lets-plot 4.6.0rc1__cp38-cp38-macosx_10_15_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of lets-plot might be problematic. Click here for more details.
- lets_plot/__init__.py +283 -0
- lets_plot/_global_settings.py +191 -0
- lets_plot/_kbridge.py +134 -0
- lets_plot/_type_utils.py +110 -0
- lets_plot/_version.py +6 -0
- lets_plot/bistro/__init__.py +16 -0
- lets_plot/bistro/_plot2d_common.py +100 -0
- lets_plot/bistro/corr.py +447 -0
- lets_plot/bistro/im.py +196 -0
- lets_plot/bistro/joint.py +192 -0
- lets_plot/bistro/qq.py +207 -0
- lets_plot/bistro/residual.py +341 -0
- lets_plot/bistro/waterfall.py +252 -0
- lets_plot/export/__init__.py +6 -0
- lets_plot/export/ggsave_.py +133 -0
- lets_plot/frontend_context/__init__.py +8 -0
- lets_plot/frontend_context/_configuration.py +144 -0
- lets_plot/frontend_context/_frontend_ctx.py +16 -0
- lets_plot/frontend_context/_html_contexts.py +117 -0
- lets_plot/frontend_context/_intellij_python_json_ctx.py +38 -0
- lets_plot/frontend_context/_json_contexts.py +39 -0
- lets_plot/frontend_context/_jupyter_notebook_ctx.py +119 -0
- lets_plot/frontend_context/_mime_types.py +7 -0
- lets_plot/frontend_context/_static_html_page_ctx.py +27 -0
- lets_plot/frontend_context/_static_svg_ctx.py +26 -0
- lets_plot/frontend_context/_webbr_html_page_ctx.py +29 -0
- lets_plot/frontend_context/sandbox.py +5 -0
- lets_plot/geo_data/__init__.py +18 -0
- lets_plot/geo_data/core.py +331 -0
- lets_plot/geo_data/geocoder.py +977 -0
- lets_plot/geo_data/geocodes.py +512 -0
- lets_plot/geo_data/gis/__init__.py +0 -0
- lets_plot/geo_data/gis/fluent_dict.py +201 -0
- lets_plot/geo_data/gis/geocoding_service.py +42 -0
- lets_plot/geo_data/gis/geometry.py +91 -0
- lets_plot/geo_data/gis/json_request.py +232 -0
- lets_plot/geo_data/gis/json_response.py +308 -0
- lets_plot/geo_data/gis/request.py +492 -0
- lets_plot/geo_data/gis/response.py +247 -0
- lets_plot/geo_data/livemap_helper.py +65 -0
- lets_plot/geo_data/to_geo_data_frame.py +141 -0
- lets_plot/geo_data/type_assertion.py +34 -0
- lets_plot/geo_data_internals/__init__.py +4 -0
- lets_plot/geo_data_internals/constants.py +13 -0
- lets_plot/geo_data_internals/utils.py +33 -0
- lets_plot/mapping.py +115 -0
- lets_plot/package_data/lets-plot.min.js +2 -0
- lets_plot/plot/__init__.py +64 -0
- lets_plot/plot/_global_theme.py +14 -0
- lets_plot/plot/annotation.py +233 -0
- lets_plot/plot/coord.py +242 -0
- lets_plot/plot/core.py +943 -0
- lets_plot/plot/expand_limits_.py +78 -0
- lets_plot/plot/facet.py +206 -0
- lets_plot/plot/font_features.py +71 -0
- lets_plot/plot/geom.py +8160 -0
- lets_plot/plot/geom_extras.py +53 -0
- lets_plot/plot/geom_function_.py +216 -0
- lets_plot/plot/geom_imshow_.py +401 -0
- lets_plot/plot/geom_livemap_.py +330 -0
- lets_plot/plot/ggbunch_.py +96 -0
- lets_plot/plot/gggrid_.py +126 -0
- lets_plot/plot/ggtb_.py +56 -0
- lets_plot/plot/guide.py +229 -0
- lets_plot/plot/label.py +187 -0
- lets_plot/plot/marginal_layer.py +181 -0
- lets_plot/plot/plot.py +244 -0
- lets_plot/plot/pos.py +346 -0
- lets_plot/plot/sampling.py +338 -0
- lets_plot/plot/sandbox_.py +26 -0
- lets_plot/plot/scale.py +3577 -0
- lets_plot/plot/scale_colormap_mpl.py +297 -0
- lets_plot/plot/scale_convenience.py +155 -0
- lets_plot/plot/scale_identity_.py +658 -0
- lets_plot/plot/scale_position.py +1336 -0
- lets_plot/plot/series_meta.py +129 -0
- lets_plot/plot/stat.py +581 -0
- lets_plot/plot/subplots.py +322 -0
- lets_plot/plot/subplots_util.py +24 -0
- lets_plot/plot/theme_.py +766 -0
- lets_plot/plot/theme_set.py +393 -0
- lets_plot/plot/tooltip.py +486 -0
- lets_plot/plot/util.py +226 -0
- lets_plot/settings_utils.py +244 -0
- lets_plot/tilesets.py +364 -0
- lets_plot-4.6.0rc1.dist-info/LICENSE +21 -0
- lets_plot-4.6.0rc1.dist-info/METADATA +186 -0
- lets_plot-4.6.0rc1.dist-info/RECORD +91 -0
- lets_plot-4.6.0rc1.dist-info/WHEEL +5 -0
- lets_plot-4.6.0rc1.dist-info/top_level.txt +2 -0
- lets_plot_kotlin_bridge.cpython-38-darwin.so +0 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Copyright (c) 2024. JetBrains s.r.o.
|
|
2
|
+
# Use of this source code is governed by the MIT license that can be found in the LICENSE file.
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from typing import Union, Dict, Iterable
|
|
5
|
+
|
|
6
|
+
from lets_plot._type_utils import is_polars_dataframe
|
|
7
|
+
from lets_plot.plot.util import is_pandas_data_frame
|
|
8
|
+
|
|
9
|
+
TYPE_INTEGER = 'int'
|
|
10
|
+
TYPE_FLOATING = 'float'
|
|
11
|
+
TYPE_STRING = 'str'
|
|
12
|
+
TYPE_BOOLEAN = 'bool'
|
|
13
|
+
TYPE_DATE_TIME = 'datetime'
|
|
14
|
+
TYPE_UNKNOWN = 'unknown'
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def infer_type(data: Union[Dict, 'pandas.DataFrame', 'polars.DataFrame']) -> Dict[str, str]:
|
|
18
|
+
type_info = {}
|
|
19
|
+
|
|
20
|
+
if is_pandas_data_frame(data):
|
|
21
|
+
import pandas as pd
|
|
22
|
+
import numpy as np # np is a dependency of pandas, we can import it without checking
|
|
23
|
+
|
|
24
|
+
for var_name, var_content in data.items():
|
|
25
|
+
if data.empty:
|
|
26
|
+
type_info[var_name] = TYPE_UNKNOWN
|
|
27
|
+
continue
|
|
28
|
+
|
|
29
|
+
inferred_type = pd.api.types.infer_dtype(var_content.values, skipna=True)
|
|
30
|
+
if inferred_type == "categorical":
|
|
31
|
+
dtype = var_content.cat.categories.dtype
|
|
32
|
+
|
|
33
|
+
if np.issubdtype(dtype, np.integer):
|
|
34
|
+
type_info[var_name] = TYPE_INTEGER
|
|
35
|
+
elif np.issubdtype(dtype, np.floating):
|
|
36
|
+
type_info[var_name] = TYPE_FLOATING
|
|
37
|
+
elif np.issubdtype(dtype, np.object_):
|
|
38
|
+
# Check if all elements are strings
|
|
39
|
+
if all(isinstance(x, str) for x in var_content.cat.categories):
|
|
40
|
+
type_info[var_name] = TYPE_STRING
|
|
41
|
+
else:
|
|
42
|
+
type_info[var_name] = TYPE_UNKNOWN
|
|
43
|
+
else:
|
|
44
|
+
type_info[var_name] = TYPE_UNKNOWN
|
|
45
|
+
else:
|
|
46
|
+
# see https://pandas.pydata.org/docs/reference/api/pandas.api.types.infer_dtype.html
|
|
47
|
+
if inferred_type == 'string':
|
|
48
|
+
type_info[var_name] = TYPE_STRING
|
|
49
|
+
elif inferred_type == 'floating':
|
|
50
|
+
type_info[var_name] = TYPE_FLOATING
|
|
51
|
+
elif inferred_type == 'integer':
|
|
52
|
+
type_info[var_name] = TYPE_INTEGER
|
|
53
|
+
elif inferred_type == 'boolean':
|
|
54
|
+
type_info[var_name] = TYPE_BOOLEAN
|
|
55
|
+
elif inferred_type == 'datetime64' or inferred_type == 'datetime':
|
|
56
|
+
type_info[var_name] = TYPE_DATE_TIME
|
|
57
|
+
elif inferred_type == "date":
|
|
58
|
+
type_info[var_name] = TYPE_DATE_TIME
|
|
59
|
+
elif inferred_type == 'empty': # for columns with all None values
|
|
60
|
+
type_info[var_name] = TYPE_UNKNOWN
|
|
61
|
+
else:
|
|
62
|
+
type_info[var_name] = 'unknown(pandas:' + inferred_type + ')'
|
|
63
|
+
elif is_polars_dataframe(data):
|
|
64
|
+
import polars as pl
|
|
65
|
+
from polars.datatypes.group import INTEGER_DTYPES, FLOAT_DTYPES
|
|
66
|
+
for var_name, var_type in data.schema.items():
|
|
67
|
+
|
|
68
|
+
# https://docs.pola.rs/api/python/stable/reference/datatypes.html
|
|
69
|
+
if var_type in FLOAT_DTYPES:
|
|
70
|
+
type_info[var_name] = TYPE_FLOATING
|
|
71
|
+
elif var_type in INTEGER_DTYPES:
|
|
72
|
+
type_info[var_name] = TYPE_INTEGER
|
|
73
|
+
elif var_type == pl.datatypes.String:
|
|
74
|
+
type_info[var_name] = TYPE_STRING
|
|
75
|
+
elif var_type == pl.datatypes.Boolean:
|
|
76
|
+
type_info[var_name] = TYPE_BOOLEAN
|
|
77
|
+
elif var_type == pl.datatypes.Date or var_type == pl.datatypes.Datetime:
|
|
78
|
+
type_info[var_name] = TYPE_DATE_TIME
|
|
79
|
+
else:
|
|
80
|
+
type_info[var_name] = 'unknown(polars:' + str(var_type) + ')'
|
|
81
|
+
elif isinstance(data, dict):
|
|
82
|
+
for var_name, var_content in data.items():
|
|
83
|
+
if isinstance(var_content, Iterable):
|
|
84
|
+
if not any(True for _ in var_content): # empty
|
|
85
|
+
type_info[var_name] = TYPE_UNKNOWN
|
|
86
|
+
continue
|
|
87
|
+
|
|
88
|
+
type_set = set(type(val) for val in var_content)
|
|
89
|
+
if type(None) in type_set:
|
|
90
|
+
type_set.remove(type(None))
|
|
91
|
+
|
|
92
|
+
if len(type_set) == 0:
|
|
93
|
+
continue
|
|
94
|
+
|
|
95
|
+
if len(type_set) > 1:
|
|
96
|
+
if all(issubclass(type_obj, int) or issubclass(type_obj, float) for type_obj in type_set):
|
|
97
|
+
type_info[var_name] = TYPE_FLOATING
|
|
98
|
+
else:
|
|
99
|
+
type_info[var_name] = 'unknown(mixed types)'
|
|
100
|
+
continue
|
|
101
|
+
|
|
102
|
+
try:
|
|
103
|
+
import numpy
|
|
104
|
+
except ImportError:
|
|
105
|
+
numpy = None
|
|
106
|
+
|
|
107
|
+
type_obj = list(type_set)[0]
|
|
108
|
+
if type_obj == bool:
|
|
109
|
+
type_info[var_name] = TYPE_BOOLEAN
|
|
110
|
+
elif issubclass(type_obj, int):
|
|
111
|
+
type_info[var_name] = TYPE_INTEGER
|
|
112
|
+
elif issubclass(type_obj, float):
|
|
113
|
+
type_info[var_name] = TYPE_FLOATING
|
|
114
|
+
elif issubclass(type_obj, str):
|
|
115
|
+
type_info[var_name] = TYPE_STRING
|
|
116
|
+
elif issubclass(type_obj, datetime):
|
|
117
|
+
type_info[var_name] = TYPE_DATE_TIME
|
|
118
|
+
elif numpy and issubclass(type_obj, numpy.datetime64):
|
|
119
|
+
type_info[var_name] = TYPE_DATE_TIME
|
|
120
|
+
elif numpy and issubclass(type_obj, numpy.timedelta64):
|
|
121
|
+
type_info[var_name] = TYPE_DATE_TIME
|
|
122
|
+
elif numpy and issubclass(type_obj, numpy.integer):
|
|
123
|
+
type_info[var_name] = TYPE_INTEGER
|
|
124
|
+
elif numpy and issubclass(type_obj, numpy.floating):
|
|
125
|
+
type_info[var_name] = TYPE_FLOATING
|
|
126
|
+
else:
|
|
127
|
+
type_info[var_name] = 'unknown(python:' + str(type_obj) + ')'
|
|
128
|
+
|
|
129
|
+
return type_info
|