polars-runtime-compat 1.34.0b3__cp39-abi3-win_arm64.whl → 1.34.0b4__cp39-abi3-win_arm64.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 polars-runtime-compat might be problematic. Click here for more details.
- _polars_runtime_compat/_polars_runtime_compat.pyd +0 -0
- {polars_runtime_compat-1.34.0b3.dist-info → polars_runtime_compat-1.34.0b4.dist-info}/METADATA +1 -1
- polars_runtime_compat-1.34.0b4.dist-info/RECORD +6 -0
- polars/__init__.py +0 -528
- polars/_cpu_check.py +0 -265
- polars/_dependencies.py +0 -355
- polars/_plr.py +0 -99
- polars/_plr.pyi +0 -2496
- polars/_reexport.py +0 -23
- polars/_typing.py +0 -478
- polars/_utils/__init__.py +0 -37
- polars/_utils/async_.py +0 -102
- polars/_utils/cache.py +0 -176
- polars/_utils/cloud.py +0 -40
- polars/_utils/constants.py +0 -29
- polars/_utils/construction/__init__.py +0 -46
- polars/_utils/construction/dataframe.py +0 -1397
- polars/_utils/construction/other.py +0 -72
- polars/_utils/construction/series.py +0 -560
- polars/_utils/construction/utils.py +0 -118
- polars/_utils/convert.py +0 -224
- polars/_utils/deprecation.py +0 -406
- polars/_utils/getitem.py +0 -457
- polars/_utils/logging.py +0 -11
- polars/_utils/nest_asyncio.py +0 -264
- polars/_utils/parquet.py +0 -15
- polars/_utils/parse/__init__.py +0 -12
- polars/_utils/parse/expr.py +0 -242
- polars/_utils/polars_version.py +0 -19
- polars/_utils/pycapsule.py +0 -53
- polars/_utils/scan.py +0 -27
- polars/_utils/serde.py +0 -63
- polars/_utils/slice.py +0 -215
- polars/_utils/udfs.py +0 -1251
- polars/_utils/unstable.py +0 -63
- polars/_utils/various.py +0 -782
- polars/_utils/wrap.py +0 -25
- polars/api.py +0 -370
- polars/catalog/__init__.py +0 -0
- polars/catalog/unity/__init__.py +0 -19
- polars/catalog/unity/client.py +0 -733
- polars/catalog/unity/models.py +0 -152
- polars/config.py +0 -1571
- polars/convert/__init__.py +0 -25
- polars/convert/general.py +0 -1046
- polars/convert/normalize.py +0 -261
- polars/dataframe/__init__.py +0 -5
- polars/dataframe/_html.py +0 -186
- polars/dataframe/frame.py +0 -12582
- polars/dataframe/group_by.py +0 -1067
- polars/dataframe/plotting.py +0 -257
- polars/datatype_expr/__init__.py +0 -5
- polars/datatype_expr/array.py +0 -56
- polars/datatype_expr/datatype_expr.py +0 -304
- polars/datatype_expr/list.py +0 -18
- polars/datatype_expr/struct.py +0 -69
- polars/datatypes/__init__.py +0 -122
- polars/datatypes/_parse.py +0 -195
- polars/datatypes/_utils.py +0 -48
- polars/datatypes/classes.py +0 -1213
- polars/datatypes/constants.py +0 -11
- polars/datatypes/constructor.py +0 -172
- polars/datatypes/convert.py +0 -366
- polars/datatypes/group.py +0 -130
- polars/exceptions.py +0 -230
- polars/expr/__init__.py +0 -7
- polars/expr/array.py +0 -964
- polars/expr/binary.py +0 -346
- polars/expr/categorical.py +0 -306
- polars/expr/datetime.py +0 -2620
- polars/expr/expr.py +0 -11272
- polars/expr/list.py +0 -1408
- polars/expr/meta.py +0 -444
- polars/expr/name.py +0 -321
- polars/expr/string.py +0 -3045
- polars/expr/struct.py +0 -357
- polars/expr/whenthen.py +0 -185
- polars/functions/__init__.py +0 -193
- polars/functions/aggregation/__init__.py +0 -33
- polars/functions/aggregation/horizontal.py +0 -298
- polars/functions/aggregation/vertical.py +0 -341
- polars/functions/as_datatype.py +0 -848
- polars/functions/business.py +0 -138
- polars/functions/col.py +0 -384
- polars/functions/datatype.py +0 -121
- polars/functions/eager.py +0 -524
- polars/functions/escape_regex.py +0 -29
- polars/functions/lazy.py +0 -2751
- polars/functions/len.py +0 -68
- polars/functions/lit.py +0 -210
- polars/functions/random.py +0 -22
- polars/functions/range/__init__.py +0 -19
- polars/functions/range/_utils.py +0 -15
- polars/functions/range/date_range.py +0 -303
- polars/functions/range/datetime_range.py +0 -370
- polars/functions/range/int_range.py +0 -348
- polars/functions/range/linear_space.py +0 -311
- polars/functions/range/time_range.py +0 -287
- polars/functions/repeat.py +0 -301
- polars/functions/whenthen.py +0 -353
- polars/interchange/__init__.py +0 -10
- polars/interchange/buffer.py +0 -77
- polars/interchange/column.py +0 -190
- polars/interchange/dataframe.py +0 -230
- polars/interchange/from_dataframe.py +0 -328
- polars/interchange/protocol.py +0 -303
- polars/interchange/utils.py +0 -170
- polars/io/__init__.py +0 -64
- polars/io/_utils.py +0 -317
- polars/io/avro.py +0 -49
- polars/io/clipboard.py +0 -36
- polars/io/cloud/__init__.py +0 -17
- polars/io/cloud/_utils.py +0 -80
- polars/io/cloud/credential_provider/__init__.py +0 -17
- polars/io/cloud/credential_provider/_builder.py +0 -520
- polars/io/cloud/credential_provider/_providers.py +0 -618
- polars/io/csv/__init__.py +0 -9
- polars/io/csv/_utils.py +0 -38
- polars/io/csv/batched_reader.py +0 -142
- polars/io/csv/functions.py +0 -1495
- polars/io/database/__init__.py +0 -6
- polars/io/database/_arrow_registry.py +0 -70
- polars/io/database/_cursor_proxies.py +0 -147
- polars/io/database/_executor.py +0 -578
- polars/io/database/_inference.py +0 -314
- polars/io/database/_utils.py +0 -144
- polars/io/database/functions.py +0 -516
- polars/io/delta.py +0 -499
- polars/io/iceberg/__init__.py +0 -3
- polars/io/iceberg/_utils.py +0 -697
- polars/io/iceberg/dataset.py +0 -556
- polars/io/iceberg/functions.py +0 -151
- polars/io/ipc/__init__.py +0 -8
- polars/io/ipc/functions.py +0 -514
- polars/io/json/__init__.py +0 -3
- polars/io/json/read.py +0 -101
- polars/io/ndjson.py +0 -332
- polars/io/parquet/__init__.py +0 -17
- polars/io/parquet/field_overwrites.py +0 -140
- polars/io/parquet/functions.py +0 -722
- polars/io/partition.py +0 -491
- polars/io/plugins.py +0 -187
- polars/io/pyarrow_dataset/__init__.py +0 -5
- polars/io/pyarrow_dataset/anonymous_scan.py +0 -109
- polars/io/pyarrow_dataset/functions.py +0 -79
- polars/io/scan_options/__init__.py +0 -5
- polars/io/scan_options/_options.py +0 -59
- polars/io/scan_options/cast_options.py +0 -126
- polars/io/spreadsheet/__init__.py +0 -6
- polars/io/spreadsheet/_utils.py +0 -52
- polars/io/spreadsheet/_write_utils.py +0 -647
- polars/io/spreadsheet/functions.py +0 -1323
- polars/lazyframe/__init__.py +0 -9
- polars/lazyframe/engine_config.py +0 -61
- polars/lazyframe/frame.py +0 -8564
- polars/lazyframe/group_by.py +0 -669
- polars/lazyframe/in_process.py +0 -42
- polars/lazyframe/opt_flags.py +0 -333
- polars/meta/__init__.py +0 -14
- polars/meta/build.py +0 -33
- polars/meta/index_type.py +0 -27
- polars/meta/thread_pool.py +0 -50
- polars/meta/versions.py +0 -120
- polars/ml/__init__.py +0 -0
- polars/ml/torch.py +0 -213
- polars/ml/utilities.py +0 -30
- polars/plugins.py +0 -155
- polars/py.typed +0 -0
- polars/pyproject.toml +0 -103
- polars/schema.py +0 -265
- polars/selectors.py +0 -3117
- polars/series/__init__.py +0 -5
- polars/series/array.py +0 -776
- polars/series/binary.py +0 -254
- polars/series/categorical.py +0 -246
- polars/series/datetime.py +0 -2275
- polars/series/list.py +0 -1087
- polars/series/plotting.py +0 -191
- polars/series/series.py +0 -9197
- polars/series/string.py +0 -2367
- polars/series/struct.py +0 -154
- polars/series/utils.py +0 -191
- polars/sql/__init__.py +0 -7
- polars/sql/context.py +0 -677
- polars/sql/functions.py +0 -139
- polars/string_cache.py +0 -185
- polars/testing/__init__.py +0 -13
- polars/testing/asserts/__init__.py +0 -9
- polars/testing/asserts/frame.py +0 -231
- polars/testing/asserts/series.py +0 -219
- polars/testing/asserts/utils.py +0 -12
- polars/testing/parametric/__init__.py +0 -33
- polars/testing/parametric/profiles.py +0 -107
- polars/testing/parametric/strategies/__init__.py +0 -22
- polars/testing/parametric/strategies/_utils.py +0 -14
- polars/testing/parametric/strategies/core.py +0 -615
- polars/testing/parametric/strategies/data.py +0 -452
- polars/testing/parametric/strategies/dtype.py +0 -436
- polars/testing/parametric/strategies/legacy.py +0 -169
- polars/type_aliases.py +0 -24
- polars_runtime_compat-1.34.0b3.dist-info/RECORD +0 -203
- {polars_runtime_compat-1.34.0b3.dist-info → polars_runtime_compat-1.34.0b4.dist-info}/WHEEL +0 -0
- {polars_runtime_compat-1.34.0b3.dist-info → polars_runtime_compat-1.34.0b4.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,436 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from typing import TYPE_CHECKING
|
|
4
|
-
|
|
5
|
-
import hypothesis.strategies as st
|
|
6
|
-
from hypothesis.errors import InvalidArgument
|
|
7
|
-
|
|
8
|
-
from polars.datatypes import (
|
|
9
|
-
Array,
|
|
10
|
-
Binary,
|
|
11
|
-
Boolean,
|
|
12
|
-
Categorical,
|
|
13
|
-
DataType,
|
|
14
|
-
Date,
|
|
15
|
-
Datetime,
|
|
16
|
-
Decimal,
|
|
17
|
-
Duration,
|
|
18
|
-
Enum,
|
|
19
|
-
Field,
|
|
20
|
-
Float32,
|
|
21
|
-
Float64,
|
|
22
|
-
Int8,
|
|
23
|
-
Int16,
|
|
24
|
-
Int32,
|
|
25
|
-
Int64,
|
|
26
|
-
Int128,
|
|
27
|
-
List,
|
|
28
|
-
Null,
|
|
29
|
-
String,
|
|
30
|
-
Struct,
|
|
31
|
-
Time,
|
|
32
|
-
UInt8,
|
|
33
|
-
UInt16,
|
|
34
|
-
UInt32,
|
|
35
|
-
UInt64,
|
|
36
|
-
UInt128,
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
if TYPE_CHECKING:
|
|
40
|
-
from collections.abc import Collection, Sequence
|
|
41
|
-
|
|
42
|
-
from hypothesis.strategies import DrawFn, SearchStrategy
|
|
43
|
-
|
|
44
|
-
from polars._typing import PolarsDataType, TimeUnit
|
|
45
|
-
from polars.datatypes import DataTypeClass
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
# Supported data type classes which do not take any arguments
|
|
49
|
-
_SIMPLE_DTYPES: list[DataTypeClass] = [
|
|
50
|
-
Int8,
|
|
51
|
-
Int16,
|
|
52
|
-
Int32,
|
|
53
|
-
Int64,
|
|
54
|
-
Int128,
|
|
55
|
-
Float64,
|
|
56
|
-
Float32,
|
|
57
|
-
Boolean,
|
|
58
|
-
UInt8,
|
|
59
|
-
UInt16,
|
|
60
|
-
UInt32,
|
|
61
|
-
UInt64,
|
|
62
|
-
UInt128,
|
|
63
|
-
String,
|
|
64
|
-
Binary,
|
|
65
|
-
Date,
|
|
66
|
-
Time,
|
|
67
|
-
Null,
|
|
68
|
-
# TODO: Enable Object types by default when various issues are solved.
|
|
69
|
-
# Object,
|
|
70
|
-
]
|
|
71
|
-
# Supported data type classes with arguments
|
|
72
|
-
_COMPLEX_DTYPES: list[DataTypeClass] = [
|
|
73
|
-
Datetime,
|
|
74
|
-
Duration,
|
|
75
|
-
Categorical,
|
|
76
|
-
Decimal,
|
|
77
|
-
Enum,
|
|
78
|
-
]
|
|
79
|
-
# Supported data type classes that contain other data types
|
|
80
|
-
_NESTED_DTYPES: list[DataTypeClass] = [
|
|
81
|
-
# TODO: Enable nested types by default when various issues are solved.
|
|
82
|
-
# List,
|
|
83
|
-
# Array,
|
|
84
|
-
Struct,
|
|
85
|
-
]
|
|
86
|
-
# Supported data type classes that do not contain other data types
|
|
87
|
-
_FLAT_DTYPES = _SIMPLE_DTYPES + _COMPLEX_DTYPES
|
|
88
|
-
|
|
89
|
-
_DEFAULT_ARRAY_WIDTH_LIMIT = 3
|
|
90
|
-
_DEFAULT_STRUCT_FIELDS_LIMIT = 3
|
|
91
|
-
_DEFAULT_ENUM_CATEGORIES_LIMIT = 3
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
def dtypes(
|
|
95
|
-
*,
|
|
96
|
-
allowed_dtypes: Collection[PolarsDataType] | None = None,
|
|
97
|
-
excluded_dtypes: Sequence[PolarsDataType] | None = None,
|
|
98
|
-
allow_time_zones: bool = True,
|
|
99
|
-
nesting_level: int = 3,
|
|
100
|
-
) -> SearchStrategy[DataType]:
|
|
101
|
-
"""
|
|
102
|
-
Create a strategy for generating Polars :class:`DataType` objects.
|
|
103
|
-
|
|
104
|
-
.. warning::
|
|
105
|
-
This functionality is currently considered **unstable**. It may be
|
|
106
|
-
changed at any point without it being considered a breaking change.
|
|
107
|
-
|
|
108
|
-
Parameters
|
|
109
|
-
----------
|
|
110
|
-
allowed_dtypes
|
|
111
|
-
Data types the strategy will pick from. If set to `None` (default),
|
|
112
|
-
all supported data types are included.
|
|
113
|
-
excluded_dtypes
|
|
114
|
-
Data types the strategy will *not* pick from. This takes priority over
|
|
115
|
-
data types specified in `allowed_dtypes`.
|
|
116
|
-
allow_time_zones
|
|
117
|
-
Allow generating `Datetime` data types with a time zone.
|
|
118
|
-
nesting_level
|
|
119
|
-
The complexity of nested data types. If set to 0, nested data types are
|
|
120
|
-
disabled.
|
|
121
|
-
"""
|
|
122
|
-
flat_dtypes, nested_dtypes, excluded_dtypes = _parse_dtype_restrictions(
|
|
123
|
-
allowed_dtypes, excluded_dtypes
|
|
124
|
-
)
|
|
125
|
-
|
|
126
|
-
if nesting_level > 0 and nested_dtypes:
|
|
127
|
-
if not flat_dtypes:
|
|
128
|
-
return _nested_dtypes(
|
|
129
|
-
inner=st.just(Null()),
|
|
130
|
-
allowed_dtypes=nested_dtypes,
|
|
131
|
-
excluded_dtypes=excluded_dtypes,
|
|
132
|
-
allow_time_zones=allow_time_zones,
|
|
133
|
-
)
|
|
134
|
-
return st.recursive(
|
|
135
|
-
base=_flat_dtypes(
|
|
136
|
-
allowed_dtypes=flat_dtypes,
|
|
137
|
-
excluded_dtypes=excluded_dtypes,
|
|
138
|
-
allow_time_zones=allow_time_zones,
|
|
139
|
-
),
|
|
140
|
-
extend=lambda s: _nested_dtypes(
|
|
141
|
-
s,
|
|
142
|
-
allowed_dtypes=nested_dtypes,
|
|
143
|
-
excluded_dtypes=excluded_dtypes,
|
|
144
|
-
allow_time_zones=allow_time_zones,
|
|
145
|
-
),
|
|
146
|
-
max_leaves=nesting_level,
|
|
147
|
-
)
|
|
148
|
-
else:
|
|
149
|
-
return _flat_dtypes(
|
|
150
|
-
allowed_dtypes=flat_dtypes,
|
|
151
|
-
excluded_dtypes=excluded_dtypes,
|
|
152
|
-
allow_time_zones=allow_time_zones,
|
|
153
|
-
)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
def _parse_dtype_restrictions(
|
|
157
|
-
allowed_dtypes: Collection[PolarsDataType] | None = None,
|
|
158
|
-
excluded_dtypes: Sequence[PolarsDataType] | None = None,
|
|
159
|
-
) -> tuple[list[PolarsDataType], list[PolarsDataType], list[DataType]]:
|
|
160
|
-
"""
|
|
161
|
-
Parse data type restrictions.
|
|
162
|
-
|
|
163
|
-
Splits allowed data types into flat and nested data types.
|
|
164
|
-
Filters the allowed data types by excluded data type classes.
|
|
165
|
-
Excluded instantiated data types are returned to be filtered later.
|
|
166
|
-
"""
|
|
167
|
-
# Split excluded dtypes into instances and classes
|
|
168
|
-
excluded_dtypes_instance = []
|
|
169
|
-
excluded_dtypes_class = []
|
|
170
|
-
if excluded_dtypes:
|
|
171
|
-
for dt in excluded_dtypes:
|
|
172
|
-
if isinstance(dt, DataType):
|
|
173
|
-
excluded_dtypes_instance.append(dt)
|
|
174
|
-
else:
|
|
175
|
-
excluded_dtypes_class.append(dt)
|
|
176
|
-
|
|
177
|
-
# Split allowed dtypes into flat and nested, excluding certain dtype classes
|
|
178
|
-
allowed_dtypes_flat: list[PolarsDataType]
|
|
179
|
-
allowed_dtypes_nested: list[PolarsDataType]
|
|
180
|
-
if allowed_dtypes is None:
|
|
181
|
-
allowed_dtypes_flat = [
|
|
182
|
-
dt for dt in _FLAT_DTYPES if dt not in excluded_dtypes_class
|
|
183
|
-
]
|
|
184
|
-
allowed_dtypes_nested = [
|
|
185
|
-
dt for dt in _NESTED_DTYPES if dt not in excluded_dtypes_class
|
|
186
|
-
]
|
|
187
|
-
else:
|
|
188
|
-
allowed_dtypes_flat = []
|
|
189
|
-
allowed_dtypes_nested = []
|
|
190
|
-
for dt in allowed_dtypes:
|
|
191
|
-
if dt in excluded_dtypes_class:
|
|
192
|
-
continue
|
|
193
|
-
elif dt.is_nested():
|
|
194
|
-
allowed_dtypes_nested.append(dt)
|
|
195
|
-
else:
|
|
196
|
-
allowed_dtypes_flat.append(dt)
|
|
197
|
-
|
|
198
|
-
return allowed_dtypes_flat, allowed_dtypes_nested, excluded_dtypes_instance
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
@st.composite
|
|
202
|
-
def _flat_dtypes(
|
|
203
|
-
draw: DrawFn,
|
|
204
|
-
allowed_dtypes: Sequence[PolarsDataType] | None = None,
|
|
205
|
-
excluded_dtypes: Sequence[PolarsDataType] | None = None,
|
|
206
|
-
*,
|
|
207
|
-
allow_time_zones: bool = True,
|
|
208
|
-
) -> DataType:
|
|
209
|
-
"""Create a strategy for generating non-nested Polars :class:`DataType` objects."""
|
|
210
|
-
if allowed_dtypes is None:
|
|
211
|
-
allowed_dtypes = _FLAT_DTYPES
|
|
212
|
-
if excluded_dtypes is None:
|
|
213
|
-
excluded_dtypes = []
|
|
214
|
-
|
|
215
|
-
dtype = draw(st.sampled_from(allowed_dtypes))
|
|
216
|
-
return draw(
|
|
217
|
-
_instantiate_flat_dtype(dtype, allow_time_zones=allow_time_zones).filter(
|
|
218
|
-
lambda x: x not in excluded_dtypes
|
|
219
|
-
)
|
|
220
|
-
)
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
@st.composite
|
|
224
|
-
def _instantiate_flat_dtype(
|
|
225
|
-
draw: DrawFn, dtype: PolarsDataType, *, allow_time_zones: bool = True
|
|
226
|
-
) -> DataType:
|
|
227
|
-
"""Take a flat data type and instantiate it."""
|
|
228
|
-
if isinstance(dtype, DataType):
|
|
229
|
-
return dtype
|
|
230
|
-
elif dtype in _SIMPLE_DTYPES:
|
|
231
|
-
return dtype()
|
|
232
|
-
elif dtype == Datetime:
|
|
233
|
-
time_unit = draw(_time_units())
|
|
234
|
-
time_zone = draw(st.none() | _time_zones()) if allow_time_zones else None
|
|
235
|
-
return Datetime(time_unit, time_zone)
|
|
236
|
-
elif dtype == Duration:
|
|
237
|
-
time_unit = draw(_time_units())
|
|
238
|
-
return Duration(time_unit)
|
|
239
|
-
elif dtype == Categorical:
|
|
240
|
-
return Categorical()
|
|
241
|
-
elif dtype == Enum:
|
|
242
|
-
n_categories = draw(
|
|
243
|
-
st.integers(min_value=1, max_value=_DEFAULT_ENUM_CATEGORIES_LIMIT)
|
|
244
|
-
)
|
|
245
|
-
categories = [f"c{i}" for i in range(n_categories)]
|
|
246
|
-
return Enum(categories)
|
|
247
|
-
elif dtype == Decimal:
|
|
248
|
-
precision = draw(st.integers(min_value=1, max_value=38) | st.none())
|
|
249
|
-
scale = draw(st.integers(min_value=0, max_value=precision or 38))
|
|
250
|
-
return Decimal(precision, scale)
|
|
251
|
-
else:
|
|
252
|
-
msg = f"unsupported data type: {dtype}"
|
|
253
|
-
raise InvalidArgument(msg)
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
@st.composite
|
|
257
|
-
def _nested_dtypes(
|
|
258
|
-
draw: DrawFn,
|
|
259
|
-
inner: SearchStrategy[DataType],
|
|
260
|
-
allowed_dtypes: Sequence[PolarsDataType] | None = None,
|
|
261
|
-
excluded_dtypes: Sequence[PolarsDataType] | None = None,
|
|
262
|
-
*,
|
|
263
|
-
allow_time_zones: bool = True,
|
|
264
|
-
) -> DataType:
|
|
265
|
-
"""Create a strategy for generating nested Polars :class:`DataType` objects."""
|
|
266
|
-
if allowed_dtypes is None:
|
|
267
|
-
allowed_dtypes = _NESTED_DTYPES
|
|
268
|
-
if excluded_dtypes is None:
|
|
269
|
-
excluded_dtypes = []
|
|
270
|
-
|
|
271
|
-
dtype = draw(st.sampled_from(allowed_dtypes))
|
|
272
|
-
return draw(
|
|
273
|
-
_instantiate_nested_dtype(
|
|
274
|
-
dtype, inner, allow_time_zones=allow_time_zones
|
|
275
|
-
).filter(lambda x: x not in excluded_dtypes)
|
|
276
|
-
)
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
@st.composite
|
|
280
|
-
def _instantiate_nested_dtype(
|
|
281
|
-
draw: DrawFn,
|
|
282
|
-
dtype: PolarsDataType,
|
|
283
|
-
inner: SearchStrategy[DataType],
|
|
284
|
-
*,
|
|
285
|
-
allow_time_zones: bool = True,
|
|
286
|
-
) -> DataType:
|
|
287
|
-
"""Take a nested data type and instantiate it."""
|
|
288
|
-
|
|
289
|
-
def instantiate_inner(inner_dtype: PolarsDataType | None) -> DataType:
|
|
290
|
-
if inner_dtype is None:
|
|
291
|
-
return draw(inner)
|
|
292
|
-
elif inner_dtype.is_nested():
|
|
293
|
-
return draw(
|
|
294
|
-
_instantiate_nested_dtype(
|
|
295
|
-
inner_dtype, inner, allow_time_zones=allow_time_zones
|
|
296
|
-
)
|
|
297
|
-
)
|
|
298
|
-
else:
|
|
299
|
-
return draw(
|
|
300
|
-
_instantiate_flat_dtype(inner_dtype, allow_time_zones=allow_time_zones)
|
|
301
|
-
)
|
|
302
|
-
|
|
303
|
-
if dtype == List:
|
|
304
|
-
inner_dtype = instantiate_inner(getattr(dtype, "inner", None))
|
|
305
|
-
return List(inner_dtype)
|
|
306
|
-
elif dtype == Array:
|
|
307
|
-
inner_dtype = instantiate_inner(getattr(dtype, "inner", None))
|
|
308
|
-
size = getattr(
|
|
309
|
-
dtype,
|
|
310
|
-
"size",
|
|
311
|
-
draw(st.integers(min_value=1, max_value=_DEFAULT_ARRAY_WIDTH_LIMIT)),
|
|
312
|
-
)
|
|
313
|
-
return Array(inner_dtype, size)
|
|
314
|
-
elif dtype == Struct:
|
|
315
|
-
if isinstance(dtype, Struct):
|
|
316
|
-
fields = [Field(f.name, instantiate_inner(f.dtype)) for f in dtype.fields]
|
|
317
|
-
else:
|
|
318
|
-
n_fields = draw(
|
|
319
|
-
st.integers(min_value=1, max_value=_DEFAULT_STRUCT_FIELDS_LIMIT)
|
|
320
|
-
)
|
|
321
|
-
fields = [Field(f"f{i}", draw(inner)) for i in range(n_fields)]
|
|
322
|
-
return Struct(fields)
|
|
323
|
-
else:
|
|
324
|
-
msg = f"unsupported data type: {dtype}"
|
|
325
|
-
raise InvalidArgument(msg)
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
def _time_units() -> SearchStrategy[TimeUnit]:
|
|
329
|
-
"""Create a strategy for generating valid units of time."""
|
|
330
|
-
return st.sampled_from(["us", "ns", "ms"])
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
def _time_zones() -> SearchStrategy[str]:
|
|
334
|
-
"""Create a strategy for generating valid time zones."""
|
|
335
|
-
# Not available when building docs, so just import here.
|
|
336
|
-
from polars._plr import _known_timezones
|
|
337
|
-
|
|
338
|
-
chrono_known_tz = set(_known_timezones())
|
|
339
|
-
return st.timezone_keys(allow_prefix=False).filter(
|
|
340
|
-
lambda tz: tz not in {"Factory", "localtime"} and tz in chrono_known_tz
|
|
341
|
-
)
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
@st.composite
|
|
345
|
-
def _instantiate_dtype(
|
|
346
|
-
draw: DrawFn,
|
|
347
|
-
dtype: PolarsDataType,
|
|
348
|
-
*,
|
|
349
|
-
allowed_dtypes: Collection[PolarsDataType] | None = None,
|
|
350
|
-
excluded_dtypes: Sequence[PolarsDataType] | None = None,
|
|
351
|
-
nesting_level: int = 3,
|
|
352
|
-
allow_time_zones: bool = True,
|
|
353
|
-
) -> DataType:
|
|
354
|
-
"""Take a data type and instantiate it."""
|
|
355
|
-
if not dtype.is_nested():
|
|
356
|
-
if isinstance(dtype, DataType):
|
|
357
|
-
return dtype
|
|
358
|
-
|
|
359
|
-
if allowed_dtypes is None:
|
|
360
|
-
allowed_dtypes = [dtype]
|
|
361
|
-
else:
|
|
362
|
-
same_dtypes = [dt for dt in allowed_dtypes if dt == dtype]
|
|
363
|
-
allowed_dtypes = same_dtypes if same_dtypes else [dtype]
|
|
364
|
-
|
|
365
|
-
return draw(
|
|
366
|
-
_flat_dtypes(
|
|
367
|
-
allowed_dtypes=allowed_dtypes,
|
|
368
|
-
excluded_dtypes=excluded_dtypes,
|
|
369
|
-
allow_time_zones=allow_time_zones,
|
|
370
|
-
)
|
|
371
|
-
)
|
|
372
|
-
|
|
373
|
-
def draw_inner(dtype: PolarsDataType | None) -> DataType:
|
|
374
|
-
if dtype is None:
|
|
375
|
-
return draw(
|
|
376
|
-
dtypes(
|
|
377
|
-
allowed_dtypes=allowed_dtypes,
|
|
378
|
-
excluded_dtypes=excluded_dtypes,
|
|
379
|
-
nesting_level=nesting_level - 1,
|
|
380
|
-
allow_time_zones=allow_time_zones,
|
|
381
|
-
)
|
|
382
|
-
)
|
|
383
|
-
else:
|
|
384
|
-
return draw(
|
|
385
|
-
_instantiate_dtype(
|
|
386
|
-
dtype,
|
|
387
|
-
allowed_dtypes=allowed_dtypes,
|
|
388
|
-
excluded_dtypes=excluded_dtypes,
|
|
389
|
-
nesting_level=nesting_level - 1,
|
|
390
|
-
allow_time_zones=allow_time_zones,
|
|
391
|
-
)
|
|
392
|
-
)
|
|
393
|
-
|
|
394
|
-
if dtype == List:
|
|
395
|
-
inner = draw_inner(getattr(dtype, "inner", None))
|
|
396
|
-
return List(inner)
|
|
397
|
-
elif dtype == Array:
|
|
398
|
-
inner = draw_inner(getattr(dtype, "inner", None))
|
|
399
|
-
size = getattr(
|
|
400
|
-
dtype,
|
|
401
|
-
"size",
|
|
402
|
-
draw(st.integers(min_value=1, max_value=_DEFAULT_ARRAY_WIDTH_LIMIT)),
|
|
403
|
-
)
|
|
404
|
-
return Array(inner, size)
|
|
405
|
-
elif dtype == Struct:
|
|
406
|
-
if isinstance(dtype, Struct):
|
|
407
|
-
fields = [
|
|
408
|
-
Field(
|
|
409
|
-
name=f.name,
|
|
410
|
-
dtype=draw(
|
|
411
|
-
_instantiate_dtype(
|
|
412
|
-
f.dtype,
|
|
413
|
-
allowed_dtypes=allowed_dtypes,
|
|
414
|
-
excluded_dtypes=excluded_dtypes,
|
|
415
|
-
nesting_level=nesting_level - 1,
|
|
416
|
-
allow_time_zones=allow_time_zones,
|
|
417
|
-
)
|
|
418
|
-
),
|
|
419
|
-
)
|
|
420
|
-
for f in dtype.fields
|
|
421
|
-
]
|
|
422
|
-
else:
|
|
423
|
-
n_fields = draw(
|
|
424
|
-
st.integers(min_value=1, max_value=_DEFAULT_STRUCT_FIELDS_LIMIT)
|
|
425
|
-
)
|
|
426
|
-
inner_strategy = dtypes(
|
|
427
|
-
allowed_dtypes=allowed_dtypes,
|
|
428
|
-
excluded_dtypes=excluded_dtypes,
|
|
429
|
-
nesting_level=nesting_level - 1,
|
|
430
|
-
allow_time_zones=allow_time_zones,
|
|
431
|
-
)
|
|
432
|
-
fields = [Field(f"f{i}", draw(inner_strategy)) for i in range(n_fields)]
|
|
433
|
-
return Struct(fields)
|
|
434
|
-
else:
|
|
435
|
-
msg = f"unsupported data type: {dtype}"
|
|
436
|
-
raise InvalidArgument(msg)
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from collections.abc import Sequence
|
|
4
|
-
from typing import TYPE_CHECKING, Any
|
|
5
|
-
|
|
6
|
-
import hypothesis.strategies as st
|
|
7
|
-
from hypothesis.errors import InvalidArgument
|
|
8
|
-
|
|
9
|
-
from polars._utils.deprecation import deprecated
|
|
10
|
-
from polars.datatypes import is_polars_dtype
|
|
11
|
-
from polars.testing.parametric.strategies.core import _COL_LIMIT, column
|
|
12
|
-
from polars.testing.parametric.strategies.data import lists
|
|
13
|
-
from polars.testing.parametric.strategies.dtype import _instantiate_dtype, dtypes
|
|
14
|
-
|
|
15
|
-
if TYPE_CHECKING:
|
|
16
|
-
import sys
|
|
17
|
-
|
|
18
|
-
from hypothesis.strategies import SearchStrategy
|
|
19
|
-
|
|
20
|
-
from polars._typing import OneOrMoreDataTypes, PolarsDataType
|
|
21
|
-
|
|
22
|
-
if sys.version_info >= (3, 13):
|
|
23
|
-
from warnings import deprecated
|
|
24
|
-
else:
|
|
25
|
-
from typing_extensions import deprecated # noqa: TC004
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
@deprecated(
|
|
29
|
-
"`columns` is deprecated; use `column` instead, "
|
|
30
|
-
"in conjunction with a list comprehension."
|
|
31
|
-
)
|
|
32
|
-
def columns(
|
|
33
|
-
cols: int | Sequence[str] | None = None,
|
|
34
|
-
*,
|
|
35
|
-
dtype: OneOrMoreDataTypes | None = None,
|
|
36
|
-
min_cols: int = 0,
|
|
37
|
-
max_cols: int = _COL_LIMIT,
|
|
38
|
-
unique: bool = False,
|
|
39
|
-
) -> list[column]:
|
|
40
|
-
"""
|
|
41
|
-
Define multiple columns for use with the @dataframes strategy.
|
|
42
|
-
|
|
43
|
-
.. deprecated:: 0.20.26
|
|
44
|
-
Use :class:`column` instead, in conjunction with a list comprehension.
|
|
45
|
-
|
|
46
|
-
.. warning::
|
|
47
|
-
This functionality is currently considered **unstable**. It may be
|
|
48
|
-
changed at any point without it being considered a breaking change.
|
|
49
|
-
|
|
50
|
-
Generate a fixed sequence of `column` objects suitable for passing to the
|
|
51
|
-
@dataframes strategy, or using standalone (note that this function is not itself
|
|
52
|
-
a strategy).
|
|
53
|
-
|
|
54
|
-
Notes
|
|
55
|
-
-----
|
|
56
|
-
Additional control is available by creating a sequence of columns explicitly,
|
|
57
|
-
using the `column` class (an especially useful option is to override the default
|
|
58
|
-
data-generating strategy for a given col/dtype).
|
|
59
|
-
|
|
60
|
-
Parameters
|
|
61
|
-
----------
|
|
62
|
-
cols : {int, [str]}, optional
|
|
63
|
-
integer number of cols to create, or explicit list of column names. if
|
|
64
|
-
omitted a random number of columns (between mincol and max_cols) are
|
|
65
|
-
created.
|
|
66
|
-
dtype : PolarsDataType, optional
|
|
67
|
-
a single dtype for all cols, or list of dtypes (the same length as `cols`).
|
|
68
|
-
if omitted, each generated column is assigned a random dtype.
|
|
69
|
-
min_cols : int, optional
|
|
70
|
-
if not passing an exact size, can set a minimum here (defaults to 0).
|
|
71
|
-
max_cols : int, optional
|
|
72
|
-
if not passing an exact size, can set a maximum value here (defaults to
|
|
73
|
-
MAX_COLS).
|
|
74
|
-
unique : bool, optional
|
|
75
|
-
indicate if the values generated for these columns should be unique
|
|
76
|
-
(per-column).
|
|
77
|
-
|
|
78
|
-
Examples
|
|
79
|
-
--------
|
|
80
|
-
>>> from polars.testing.parametric import columns, dataframes
|
|
81
|
-
>>> from hypothesis import given
|
|
82
|
-
>>> @given(dataframes(columns(["x", "y", "z"], unique=True))) # doctest: +SKIP
|
|
83
|
-
... def test_unique_xyz(df: pl.DataFrame) -> None:
|
|
84
|
-
... assert_something(df)
|
|
85
|
-
"""
|
|
86
|
-
# create/assign named columns
|
|
87
|
-
if cols is None:
|
|
88
|
-
cols = st.integers(min_value=min_cols, max_value=max_cols).example()
|
|
89
|
-
if isinstance(cols, int):
|
|
90
|
-
names: Sequence[str] = [f"col{n}" for n in range(cols)]
|
|
91
|
-
else:
|
|
92
|
-
names = cols
|
|
93
|
-
n_cols = len(names)
|
|
94
|
-
|
|
95
|
-
if dtype is None:
|
|
96
|
-
dtypes: Sequence[PolarsDataType | None] = [None] * n_cols
|
|
97
|
-
elif is_polars_dtype(dtype):
|
|
98
|
-
dtypes = [dtype] * n_cols
|
|
99
|
-
elif isinstance(dtype, Sequence):
|
|
100
|
-
if (n_dtypes := len(dtype)) != n_cols:
|
|
101
|
-
msg = f"given {n_dtypes} dtypes for {n_cols} names"
|
|
102
|
-
raise InvalidArgument(msg)
|
|
103
|
-
dtypes = dtype
|
|
104
|
-
else:
|
|
105
|
-
msg = f"{dtype!r} is not a valid polars datatype"
|
|
106
|
-
raise InvalidArgument(msg)
|
|
107
|
-
|
|
108
|
-
# init list of named/typed columns
|
|
109
|
-
return [column(name=nm, dtype=tp, unique=unique) for nm, tp in zip(names, dtypes)]
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
@deprecated("`create_list_strategy` is deprecated; use `lists` instead.")
|
|
113
|
-
def create_list_strategy(
|
|
114
|
-
inner_dtype: PolarsDataType | None = None,
|
|
115
|
-
*,
|
|
116
|
-
select_from: Sequence[Any] | None = None,
|
|
117
|
-
size: int | None = None,
|
|
118
|
-
min_size: int = 0,
|
|
119
|
-
max_size: int | None = None,
|
|
120
|
-
unique: bool = False,
|
|
121
|
-
) -> SearchStrategy[list[Any]]:
|
|
122
|
-
"""
|
|
123
|
-
Create a strategy for generating Polars :class:`List` data.
|
|
124
|
-
|
|
125
|
-
.. deprecated:: 0.20.26
|
|
126
|
-
Use :func:`lists` instead.
|
|
127
|
-
|
|
128
|
-
Parameters
|
|
129
|
-
----------
|
|
130
|
-
inner_dtype : PolarsDataType
|
|
131
|
-
type of the inner list elements (can also be another List).
|
|
132
|
-
select_from : list, optional
|
|
133
|
-
randomly select the innermost values from this list (otherwise
|
|
134
|
-
the default strategy associated with the innermost dtype is used).
|
|
135
|
-
size : int, optional
|
|
136
|
-
if set, generated lists will be of exactly this size (and
|
|
137
|
-
ignore the min_size/max_size params).
|
|
138
|
-
min_size : int, optional
|
|
139
|
-
set the minimum size of the generated lists (default: 0 if unset).
|
|
140
|
-
max_size : int, optional
|
|
141
|
-
set the maximum size of the generated lists (default: 3 if
|
|
142
|
-
min_size is unset or zero, otherwise 2x min_size).
|
|
143
|
-
unique : bool, optional
|
|
144
|
-
ensure that the generated lists contain unique values.
|
|
145
|
-
|
|
146
|
-
Examples
|
|
147
|
-
--------
|
|
148
|
-
Create a strategy that generates a list of i32 values:
|
|
149
|
-
|
|
150
|
-
>>> from polars.testing.parametric import create_list_strategy
|
|
151
|
-
>>> lst = create_list_strategy(inner_dtype=pl.Int32) # doctest: +SKIP
|
|
152
|
-
>>> lst.example() # doctest: +SKIP
|
|
153
|
-
[-11330, 24030, 116]
|
|
154
|
-
"""
|
|
155
|
-
if size is not None:
|
|
156
|
-
min_size = max_size = size
|
|
157
|
-
|
|
158
|
-
if inner_dtype is None:
|
|
159
|
-
inner_dtype = dtypes().example()
|
|
160
|
-
else:
|
|
161
|
-
inner_dtype = _instantiate_dtype(inner_dtype).example()
|
|
162
|
-
|
|
163
|
-
return lists(
|
|
164
|
-
inner_dtype,
|
|
165
|
-
select_from=select_from,
|
|
166
|
-
min_size=min_size,
|
|
167
|
-
max_size=max_size,
|
|
168
|
-
unique=unique,
|
|
169
|
-
)
|
polars/type_aliases.py
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Deprecated module - do not use.
|
|
3
|
-
|
|
4
|
-
Used to contain private type aliases. These are now in the `polars._typing` module.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from typing import Any
|
|
8
|
-
|
|
9
|
-
import polars._typing as plt
|
|
10
|
-
from polars._utils.deprecation import issue_deprecation_warning
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def __getattr__(name: str) -> Any:
|
|
14
|
-
if name in dir(plt):
|
|
15
|
-
issue_deprecation_warning(
|
|
16
|
-
"the `polars.type_aliases` module was deprecated in version 1.0.0."
|
|
17
|
-
" The type aliases have moved to the `polars._typing` module to explicitly mark them as private."
|
|
18
|
-
" Please define your own type aliases, or temporarily import from the `polars._typing` module."
|
|
19
|
-
" A public `polars.typing` module will be added in the future.",
|
|
20
|
-
)
|
|
21
|
-
return getattr(plt, name)
|
|
22
|
-
|
|
23
|
-
msg = f"module {__name__!r} has no attribute {name!r}"
|
|
24
|
-
raise AttributeError(msg)
|