polars-runtime-compat 1.34.0b3__cp39-abi3-manylinux_2_24_aarch64.whl → 1.34.0b4__cp39-abi3-manylinux_2_24_aarch64.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.abi3.so +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
polars/functions/len.py
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Module containing the `len` function.
|
|
3
|
-
|
|
4
|
-
Keep this function in its own module to avoid conflicts with Python's built-in `len`.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from __future__ import annotations
|
|
8
|
-
|
|
9
|
-
import contextlib
|
|
10
|
-
from typing import TYPE_CHECKING
|
|
11
|
-
|
|
12
|
-
from polars._utils.wrap import wrap_expr
|
|
13
|
-
|
|
14
|
-
with contextlib.suppress(ImportError): # Module not available when building docs
|
|
15
|
-
import polars._plr as plr
|
|
16
|
-
|
|
17
|
-
if TYPE_CHECKING:
|
|
18
|
-
from polars import Expr
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def len() -> Expr:
|
|
22
|
-
"""
|
|
23
|
-
Return the number of rows in the context.
|
|
24
|
-
|
|
25
|
-
This is similar to `COUNT(*)` in SQL.
|
|
26
|
-
|
|
27
|
-
Returns
|
|
28
|
-
-------
|
|
29
|
-
Expr
|
|
30
|
-
Expression of data type :class:`UInt32`.
|
|
31
|
-
|
|
32
|
-
Examples
|
|
33
|
-
--------
|
|
34
|
-
>>> df = pl.DataFrame(
|
|
35
|
-
... {
|
|
36
|
-
... "a": [1, 2, None],
|
|
37
|
-
... "b": [3, None, None],
|
|
38
|
-
... "c": ["foo", "bar", "foo"],
|
|
39
|
-
... }
|
|
40
|
-
... )
|
|
41
|
-
>>> df.select(pl.len())
|
|
42
|
-
shape: (1, 1)
|
|
43
|
-
┌─────┐
|
|
44
|
-
│ len │
|
|
45
|
-
│ --- │
|
|
46
|
-
│ u32 │
|
|
47
|
-
╞═════╡
|
|
48
|
-
│ 3 │
|
|
49
|
-
└─────┘
|
|
50
|
-
|
|
51
|
-
Generate an index column by using `len` in conjunction with :func:`int_range`.
|
|
52
|
-
|
|
53
|
-
>>> df.select(
|
|
54
|
-
... pl.int_range(pl.len(), dtype=pl.UInt32).alias("index"),
|
|
55
|
-
... pl.all(),
|
|
56
|
-
... )
|
|
57
|
-
shape: (3, 4)
|
|
58
|
-
┌───────┬──────┬──────┬─────┐
|
|
59
|
-
│ index ┆ a ┆ b ┆ c │
|
|
60
|
-
│ --- ┆ --- ┆ --- ┆ --- │
|
|
61
|
-
│ u32 ┆ i64 ┆ i64 ┆ str │
|
|
62
|
-
╞═══════╪══════╪══════╪═════╡
|
|
63
|
-
│ 0 ┆ 1 ┆ 3 ┆ foo │
|
|
64
|
-
│ 1 ┆ 2 ┆ null ┆ bar │
|
|
65
|
-
│ 2 ┆ null ┆ null ┆ foo │
|
|
66
|
-
└───────┴──────┴──────┴─────┘
|
|
67
|
-
"""
|
|
68
|
-
return wrap_expr(plr.len())
|
polars/functions/lit.py
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import contextlib
|
|
4
|
-
import enum
|
|
5
|
-
from datetime import date, datetime, time, timedelta, timezone
|
|
6
|
-
from typing import TYPE_CHECKING, Any
|
|
7
|
-
from zoneinfo import ZoneInfo
|
|
8
|
-
|
|
9
|
-
import polars._reexport as pl
|
|
10
|
-
from polars._dependencies import (
|
|
11
|
-
_check_for_numpy,
|
|
12
|
-
_check_for_pytz,
|
|
13
|
-
_check_for_torch,
|
|
14
|
-
pytz,
|
|
15
|
-
torch,
|
|
16
|
-
)
|
|
17
|
-
from polars._dependencies import numpy as np
|
|
18
|
-
from polars._utils.wrap import wrap_expr
|
|
19
|
-
from polars.datatypes import Date, Datetime, Duration
|
|
20
|
-
from polars.datatypes.convert import DataTypeMappings
|
|
21
|
-
|
|
22
|
-
with contextlib.suppress(ImportError): # Module not available when building docs
|
|
23
|
-
import polars._plr as plr
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if TYPE_CHECKING:
|
|
27
|
-
from polars import Expr
|
|
28
|
-
from polars._typing import PolarsDataType, TimeUnit
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def lit(
|
|
32
|
-
value: Any, dtype: PolarsDataType | None = None, *, allow_object: bool = False
|
|
33
|
-
) -> Expr:
|
|
34
|
-
"""
|
|
35
|
-
Return an expression representing a literal value.
|
|
36
|
-
|
|
37
|
-
Parameters
|
|
38
|
-
----------
|
|
39
|
-
value
|
|
40
|
-
Value that should be used as a `literal`.
|
|
41
|
-
dtype
|
|
42
|
-
The data type of the resulting expression.
|
|
43
|
-
If set to `None` (default), the data type is inferred from the `value` input.
|
|
44
|
-
allow_object
|
|
45
|
-
If type is unknown use an 'object' type.
|
|
46
|
-
By default, we will raise a `ValueException`
|
|
47
|
-
if the type is unknown.
|
|
48
|
-
|
|
49
|
-
Notes
|
|
50
|
-
-----
|
|
51
|
-
Expected datatypes:
|
|
52
|
-
|
|
53
|
-
- `pl.lit([])` -> empty List<Null>
|
|
54
|
-
- `pl.lit([1, 2, 3])` -> List<i64>
|
|
55
|
-
- `pl.lit(pl.Series([]))`-> empty Series Null
|
|
56
|
-
- `pl.lit(pl.Series([1, 2, 3]))` -> Series Int64
|
|
57
|
-
- `pl.lit(None)` -> Null
|
|
58
|
-
|
|
59
|
-
Examples
|
|
60
|
-
--------
|
|
61
|
-
Literal scalar values:
|
|
62
|
-
|
|
63
|
-
>>> pl.lit(1) # doctest: +IGNORE_RESULT
|
|
64
|
-
>>> pl.lit(5.5) # doctest: +IGNORE_RESULT
|
|
65
|
-
>>> pl.lit(None) # doctest: +IGNORE_RESULT
|
|
66
|
-
>>> pl.lit("foo_bar") # doctest: +IGNORE_RESULT
|
|
67
|
-
>>> pl.lit(date(2021, 1, 20)) # doctest: +IGNORE_RESULT
|
|
68
|
-
>>> pl.lit(datetime(2023, 3, 31, 10, 30, 45)) # doctest: +IGNORE_RESULT
|
|
69
|
-
|
|
70
|
-
Literal list/Series data (1D):
|
|
71
|
-
|
|
72
|
-
>>> pl.lit([1, 2, 3]) # doctest: +SKIP
|
|
73
|
-
>>> pl.lit(pl.Series("x", [1, 2, 3])) # doctest: +IGNORE_RESULT
|
|
74
|
-
|
|
75
|
-
Literal list/Series data (2D):
|
|
76
|
-
|
|
77
|
-
>>> pl.lit([[1, 2], [3, 4]]) # doctest: +SKIP
|
|
78
|
-
>>> pl.lit(pl.Series("y", [[1, 2], [3, 4]])) # doctest: +IGNORE_RESULT
|
|
79
|
-
"""
|
|
80
|
-
time_unit: TimeUnit
|
|
81
|
-
|
|
82
|
-
if isinstance(value, datetime):
|
|
83
|
-
if dtype == Date:
|
|
84
|
-
return wrap_expr(plr.lit(value.date(), allow_object=False, is_scalar=True))
|
|
85
|
-
|
|
86
|
-
# parse time unit
|
|
87
|
-
if dtype is not None and (tu := getattr(dtype, "time_unit", "us")) is not None:
|
|
88
|
-
time_unit = tu # type: ignore[assignment]
|
|
89
|
-
else:
|
|
90
|
-
time_unit = "us"
|
|
91
|
-
|
|
92
|
-
# parse time zone
|
|
93
|
-
dtype_tz = getattr(dtype, "time_zone", None)
|
|
94
|
-
value_tz = value.tzinfo
|
|
95
|
-
if value_tz is None:
|
|
96
|
-
tz = dtype_tz
|
|
97
|
-
else:
|
|
98
|
-
# value has time zone, but dtype does not: keep value time zone
|
|
99
|
-
if dtype_tz is None:
|
|
100
|
-
if isinstance(value_tz, ZoneInfo) or (
|
|
101
|
-
_check_for_pytz(value_tz)
|
|
102
|
-
and isinstance(value_tz, pytz.tzinfo.BaseTzInfo)
|
|
103
|
-
and value_tz.zone is not None
|
|
104
|
-
):
|
|
105
|
-
# named timezone
|
|
106
|
-
tz = str(value_tz)
|
|
107
|
-
else:
|
|
108
|
-
# fixed offset from UTC (eg: +4:00)
|
|
109
|
-
value = value.astimezone(timezone.utc)
|
|
110
|
-
tz = "UTC"
|
|
111
|
-
|
|
112
|
-
# dtype and value both have same time zone
|
|
113
|
-
elif str(value_tz) == dtype_tz:
|
|
114
|
-
tz = str(value_tz)
|
|
115
|
-
|
|
116
|
-
# given a fixed offset from UTC that matches the dtype tz offset
|
|
117
|
-
elif hasattr(value_tz, "utcoffset") and getattr(
|
|
118
|
-
ZoneInfo(dtype_tz).utcoffset(value), "seconds", 0
|
|
119
|
-
) == getattr(value_tz.utcoffset(value), "seconds", 1):
|
|
120
|
-
tz = dtype_tz
|
|
121
|
-
else:
|
|
122
|
-
# value has time zone that differs from dtype time zone
|
|
123
|
-
msg = (
|
|
124
|
-
f"time zone of dtype ({dtype_tz!r}) differs from time zone of "
|
|
125
|
-
f"value ({value_tz!r})"
|
|
126
|
-
)
|
|
127
|
-
raise TypeError(msg)
|
|
128
|
-
|
|
129
|
-
dt_utc = value.replace(tzinfo=timezone.utc)
|
|
130
|
-
expr = wrap_expr(plr.lit(dt_utc, allow_object=False, is_scalar=True)).cast(
|
|
131
|
-
Datetime(time_unit)
|
|
132
|
-
)
|
|
133
|
-
if tz is not None:
|
|
134
|
-
expr = expr.dt.replace_time_zone(
|
|
135
|
-
tz, ambiguous="earliest" if value.fold == 0 else "latest"
|
|
136
|
-
)
|
|
137
|
-
return expr
|
|
138
|
-
|
|
139
|
-
elif isinstance(value, timedelta):
|
|
140
|
-
expr = wrap_expr(plr.lit(value, allow_object=False, is_scalar=True))
|
|
141
|
-
if dtype is not None and (tu := getattr(dtype, "time_unit", None)) is not None:
|
|
142
|
-
expr = expr.cast(Duration(tu))
|
|
143
|
-
return expr
|
|
144
|
-
|
|
145
|
-
elif isinstance(value, time):
|
|
146
|
-
return wrap_expr(plr.lit(value, allow_object=False, is_scalar=True))
|
|
147
|
-
|
|
148
|
-
elif isinstance(value, date):
|
|
149
|
-
if dtype == Datetime:
|
|
150
|
-
time_unit = getattr(dtype, "time_unit", "us") or "us"
|
|
151
|
-
dt_utc = datetime(value.year, value.month, value.day)
|
|
152
|
-
expr = wrap_expr(plr.lit(dt_utc, allow_object=False, is_scalar=True)).cast(
|
|
153
|
-
Datetime(time_unit)
|
|
154
|
-
)
|
|
155
|
-
if (time_zone := getattr(dtype, "time_zone", None)) is not None:
|
|
156
|
-
expr = expr.dt.replace_time_zone(str(time_zone))
|
|
157
|
-
return expr
|
|
158
|
-
else:
|
|
159
|
-
return wrap_expr(plr.lit(value, allow_object=False, is_scalar=True))
|
|
160
|
-
|
|
161
|
-
elif isinstance(value, pl.Series):
|
|
162
|
-
value = value._s
|
|
163
|
-
return wrap_expr(plr.lit(value, allow_object, is_scalar=False))
|
|
164
|
-
|
|
165
|
-
elif _check_for_numpy(value) and isinstance(value, np.ndarray):
|
|
166
|
-
return lit(pl.Series("literal", value, dtype=dtype))
|
|
167
|
-
|
|
168
|
-
elif _check_for_torch(value) and isinstance(value, torch.Tensor):
|
|
169
|
-
return lit(pl.Series("literal", value.numpy(force=False), dtype=dtype))
|
|
170
|
-
|
|
171
|
-
elif isinstance(value, (list, tuple)):
|
|
172
|
-
return wrap_expr(
|
|
173
|
-
plr.lit(
|
|
174
|
-
pl.Series("literal", [value], dtype=dtype)._s,
|
|
175
|
-
allow_object,
|
|
176
|
-
is_scalar=True,
|
|
177
|
-
)
|
|
178
|
-
)
|
|
179
|
-
|
|
180
|
-
elif isinstance(value, enum.Enum):
|
|
181
|
-
return lit(value.value, dtype=dtype)
|
|
182
|
-
|
|
183
|
-
if dtype:
|
|
184
|
-
return wrap_expr(plr.lit(value, allow_object, is_scalar=True)).cast(dtype)
|
|
185
|
-
|
|
186
|
-
if _check_for_numpy(value) and isinstance(value, np.generic):
|
|
187
|
-
# note: the item() is a py-native datetime/timedelta when units < 'ns'
|
|
188
|
-
if isinstance(item := value.item(), (date, datetime, timedelta)):
|
|
189
|
-
return lit(item)
|
|
190
|
-
|
|
191
|
-
# handle 'ns' units
|
|
192
|
-
if isinstance(item, int) and hasattr(value, "dtype"):
|
|
193
|
-
dtype_name = value.dtype.name
|
|
194
|
-
if dtype_name.startswith("datetime64["):
|
|
195
|
-
time_unit = dtype_name[len("datetime64[") : -1] # type: ignore[assignment]
|
|
196
|
-
return lit(item).cast(Datetime(time_unit))
|
|
197
|
-
if dtype_name.startswith("timedelta64["):
|
|
198
|
-
time_unit = dtype_name[len("timedelta64[") : -1] # type: ignore[assignment]
|
|
199
|
-
return lit(item).cast(Duration(time_unit))
|
|
200
|
-
|
|
201
|
-
# handle known mappable values
|
|
202
|
-
dtype = DataTypeMappings.NUMPY_KIND_AND_ITEMSIZE_TO_DTYPE.get(
|
|
203
|
-
(value.dtype.kind, value.dtype.itemsize)
|
|
204
|
-
)
|
|
205
|
-
if dtype is not None:
|
|
206
|
-
return lit(value, dtype=dtype)
|
|
207
|
-
else:
|
|
208
|
-
item = value
|
|
209
|
-
|
|
210
|
-
return wrap_expr(plr.lit(item, allow_object, is_scalar=True))
|
polars/functions/random.py
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import contextlib
|
|
4
|
-
|
|
5
|
-
with contextlib.suppress(ImportError): # Module not available when building docs
|
|
6
|
-
import polars._plr as plr
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def set_random_seed(seed: int) -> None:
|
|
10
|
-
r"""
|
|
11
|
-
Set the global random seed for Polars.
|
|
12
|
-
|
|
13
|
-
This random seed is used to determine things such as shuffle ordering.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
Parameters
|
|
17
|
-
----------
|
|
18
|
-
seed
|
|
19
|
-
A non-negative integer < 2\ :sup:`64` used to seed the internal global
|
|
20
|
-
random number generator.
|
|
21
|
-
"""
|
|
22
|
-
plr.set_random_seed(seed)
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
from polars.functions.range.date_range import date_range, date_ranges
|
|
2
|
-
from polars.functions.range.datetime_range import datetime_range, datetime_ranges
|
|
3
|
-
from polars.functions.range.int_range import arange, int_range, int_ranges
|
|
4
|
-
from polars.functions.range.linear_space import linear_space, linear_spaces
|
|
5
|
-
from polars.functions.range.time_range import time_range, time_ranges
|
|
6
|
-
|
|
7
|
-
__all__ = [
|
|
8
|
-
"arange",
|
|
9
|
-
"date_range",
|
|
10
|
-
"date_ranges",
|
|
11
|
-
"datetime_range",
|
|
12
|
-
"datetime_ranges",
|
|
13
|
-
"int_range",
|
|
14
|
-
"int_ranges",
|
|
15
|
-
"linear_space",
|
|
16
|
-
"linear_spaces",
|
|
17
|
-
"time_range",
|
|
18
|
-
"time_ranges",
|
|
19
|
-
]
|
polars/functions/range/_utils.py
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from datetime import timedelta
|
|
4
|
-
|
|
5
|
-
from polars._utils.convert import parse_as_duration_string
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def parse_interval_argument(interval: str | timedelta) -> str:
|
|
9
|
-
"""Parse the interval argument as a Polars duration string."""
|
|
10
|
-
if isinstance(interval, timedelta):
|
|
11
|
-
return parse_as_duration_string(interval)
|
|
12
|
-
|
|
13
|
-
if " " in interval:
|
|
14
|
-
interval = interval.replace(" ", "")
|
|
15
|
-
return interval.lower()
|
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import contextlib
|
|
4
|
-
from typing import TYPE_CHECKING, overload
|
|
5
|
-
|
|
6
|
-
from polars import functions as F
|
|
7
|
-
from polars._utils.parse import parse_into_expression
|
|
8
|
-
from polars._utils.wrap import wrap_expr
|
|
9
|
-
from polars.functions.range._utils import parse_interval_argument
|
|
10
|
-
|
|
11
|
-
with contextlib.suppress(ImportError): # Module not available when building docs
|
|
12
|
-
import polars._plr as plr
|
|
13
|
-
|
|
14
|
-
if TYPE_CHECKING:
|
|
15
|
-
from datetime import date, datetime, timedelta
|
|
16
|
-
from typing import Literal
|
|
17
|
-
|
|
18
|
-
from polars import Expr, Series
|
|
19
|
-
from polars._typing import ClosedInterval, IntoExprColumn
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
@overload
|
|
23
|
-
def date_range(
|
|
24
|
-
start: date | datetime | IntoExprColumn,
|
|
25
|
-
end: date | datetime | IntoExprColumn,
|
|
26
|
-
interval: str | timedelta = ...,
|
|
27
|
-
*,
|
|
28
|
-
closed: ClosedInterval = ...,
|
|
29
|
-
eager: Literal[False] = ...,
|
|
30
|
-
) -> Expr: ...
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
@overload
|
|
34
|
-
def date_range(
|
|
35
|
-
start: date | datetime | IntoExprColumn,
|
|
36
|
-
end: date | datetime | IntoExprColumn,
|
|
37
|
-
interval: str | timedelta = ...,
|
|
38
|
-
*,
|
|
39
|
-
closed: ClosedInterval = ...,
|
|
40
|
-
eager: Literal[True],
|
|
41
|
-
) -> Series: ...
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
@overload
|
|
45
|
-
def date_range(
|
|
46
|
-
start: date | datetime | IntoExprColumn,
|
|
47
|
-
end: date | datetime | IntoExprColumn,
|
|
48
|
-
interval: str | timedelta = ...,
|
|
49
|
-
*,
|
|
50
|
-
closed: ClosedInterval = ...,
|
|
51
|
-
eager: bool,
|
|
52
|
-
) -> Series | Expr: ...
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
def date_range(
|
|
56
|
-
start: date | datetime | IntoExprColumn,
|
|
57
|
-
end: date | datetime | IntoExprColumn,
|
|
58
|
-
interval: str | timedelta = "1d",
|
|
59
|
-
*,
|
|
60
|
-
closed: ClosedInterval = "both",
|
|
61
|
-
eager: bool = False,
|
|
62
|
-
) -> Series | Expr:
|
|
63
|
-
"""
|
|
64
|
-
Generate a date range.
|
|
65
|
-
|
|
66
|
-
Parameters
|
|
67
|
-
----------
|
|
68
|
-
start
|
|
69
|
-
Lower bound of the date range.
|
|
70
|
-
end
|
|
71
|
-
Upper bound of the date range.
|
|
72
|
-
interval
|
|
73
|
-
Interval of the range periods, specified as a Python `timedelta` object
|
|
74
|
-
or using the Polars duration string language (see "Notes" section below).
|
|
75
|
-
Must consist of full days.
|
|
76
|
-
closed : {'both', 'left', 'right', 'none'}
|
|
77
|
-
Define which sides of the range are closed (inclusive).
|
|
78
|
-
eager
|
|
79
|
-
Evaluate immediately and return a `Series`.
|
|
80
|
-
If set to `False` (default), return an expression instead.
|
|
81
|
-
|
|
82
|
-
Returns
|
|
83
|
-
-------
|
|
84
|
-
Expr or Series
|
|
85
|
-
Column of data type :class:`Date`.
|
|
86
|
-
|
|
87
|
-
See Also
|
|
88
|
-
--------
|
|
89
|
-
date_ranges
|
|
90
|
-
datetime_range
|
|
91
|
-
|
|
92
|
-
Notes
|
|
93
|
-
-----
|
|
94
|
-
`interval` is created according to the following string language:
|
|
95
|
-
|
|
96
|
-
- 1d (1 calendar day)
|
|
97
|
-
- 1w (1 calendar week)
|
|
98
|
-
- 1mo (1 calendar month)
|
|
99
|
-
- 1q (1 calendar quarter)
|
|
100
|
-
- 1y (1 calendar year)
|
|
101
|
-
|
|
102
|
-
Or combine them:
|
|
103
|
-
"1w2d" # 1 week, 2 days
|
|
104
|
-
|
|
105
|
-
By "calendar day", we mean the corresponding time on the next day (which may
|
|
106
|
-
not be 24 hours, due to daylight savings). Similarly for "calendar week",
|
|
107
|
-
"calendar month", "calendar quarter", and "calendar year".
|
|
108
|
-
|
|
109
|
-
Examples
|
|
110
|
-
--------
|
|
111
|
-
Using Polars duration string to specify the interval:
|
|
112
|
-
|
|
113
|
-
>>> from datetime import date
|
|
114
|
-
>>> pl.date_range(date(2022, 1, 1), date(2022, 3, 1), "1mo", eager=True).alias(
|
|
115
|
-
... "date"
|
|
116
|
-
... )
|
|
117
|
-
shape: (3,)
|
|
118
|
-
Series: 'date' [date]
|
|
119
|
-
[
|
|
120
|
-
2022-01-01
|
|
121
|
-
2022-02-01
|
|
122
|
-
2022-03-01
|
|
123
|
-
]
|
|
124
|
-
|
|
125
|
-
Using `timedelta` object to specify the interval:
|
|
126
|
-
|
|
127
|
-
>>> from datetime import timedelta
|
|
128
|
-
>>> pl.date_range(
|
|
129
|
-
... date(1985, 1, 1),
|
|
130
|
-
... date(1985, 1, 10),
|
|
131
|
-
... timedelta(days=2),
|
|
132
|
-
... eager=True,
|
|
133
|
-
... ).alias("date")
|
|
134
|
-
shape: (5,)
|
|
135
|
-
Series: 'date' [date]
|
|
136
|
-
[
|
|
137
|
-
1985-01-01
|
|
138
|
-
1985-01-03
|
|
139
|
-
1985-01-05
|
|
140
|
-
1985-01-07
|
|
141
|
-
1985-01-09
|
|
142
|
-
]
|
|
143
|
-
|
|
144
|
-
Omit `eager=True` if you want to use `date_range` as an expression:
|
|
145
|
-
|
|
146
|
-
>>> df = pl.DataFrame(
|
|
147
|
-
... {
|
|
148
|
-
... "date": [
|
|
149
|
-
... date(2024, 1, 1),
|
|
150
|
-
... date(2024, 1, 2),
|
|
151
|
-
... date(2024, 1, 1),
|
|
152
|
-
... date(2024, 1, 3),
|
|
153
|
-
... ],
|
|
154
|
-
... "key": ["one", "one", "two", "two"],
|
|
155
|
-
... }
|
|
156
|
-
... )
|
|
157
|
-
>>> result = (
|
|
158
|
-
... df.group_by("key")
|
|
159
|
-
... .agg(pl.date_range(pl.col("date").min(), pl.col("date").max()))
|
|
160
|
-
... .sort("key")
|
|
161
|
-
... )
|
|
162
|
-
>>> with pl.Config(fmt_str_lengths=50):
|
|
163
|
-
... print(result)
|
|
164
|
-
shape: (2, 2)
|
|
165
|
-
┌─────┬──────────────────────────────────────┐
|
|
166
|
-
│ key ┆ date │
|
|
167
|
-
│ --- ┆ --- │
|
|
168
|
-
│ str ┆ list[date] │
|
|
169
|
-
╞═════╪══════════════════════════════════════╡
|
|
170
|
-
│ one ┆ [2024-01-01, 2024-01-02] │
|
|
171
|
-
│ two ┆ [2024-01-01, 2024-01-02, 2024-01-03] │
|
|
172
|
-
└─────┴──────────────────────────────────────┘
|
|
173
|
-
"""
|
|
174
|
-
interval = parse_interval_argument(interval)
|
|
175
|
-
|
|
176
|
-
start_pyexpr = parse_into_expression(start)
|
|
177
|
-
end_pyexpr = parse_into_expression(end)
|
|
178
|
-
result = wrap_expr(plr.date_range(start_pyexpr, end_pyexpr, interval, closed))
|
|
179
|
-
|
|
180
|
-
if eager:
|
|
181
|
-
return F.select(result).to_series()
|
|
182
|
-
|
|
183
|
-
return result
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
@overload
|
|
187
|
-
def date_ranges(
|
|
188
|
-
start: date | datetime | IntoExprColumn,
|
|
189
|
-
end: date | datetime | IntoExprColumn,
|
|
190
|
-
interval: str | timedelta = ...,
|
|
191
|
-
*,
|
|
192
|
-
closed: ClosedInterval = ...,
|
|
193
|
-
eager: Literal[False] = ...,
|
|
194
|
-
) -> Expr: ...
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
@overload
|
|
198
|
-
def date_ranges(
|
|
199
|
-
start: date | datetime | IntoExprColumn,
|
|
200
|
-
end: date | datetime | IntoExprColumn,
|
|
201
|
-
interval: str | timedelta = ...,
|
|
202
|
-
*,
|
|
203
|
-
closed: ClosedInterval = ...,
|
|
204
|
-
eager: Literal[True],
|
|
205
|
-
) -> Series: ...
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
@overload
|
|
209
|
-
def date_ranges(
|
|
210
|
-
start: date | datetime | IntoExprColumn,
|
|
211
|
-
end: date | datetime | IntoExprColumn,
|
|
212
|
-
interval: str | timedelta = ...,
|
|
213
|
-
*,
|
|
214
|
-
closed: ClosedInterval = ...,
|
|
215
|
-
eager: bool,
|
|
216
|
-
) -> Series | Expr: ...
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
def date_ranges(
|
|
220
|
-
start: date | datetime | IntoExprColumn,
|
|
221
|
-
end: date | datetime | IntoExprColumn,
|
|
222
|
-
interval: str | timedelta = "1d",
|
|
223
|
-
*,
|
|
224
|
-
closed: ClosedInterval = "both",
|
|
225
|
-
eager: bool = False,
|
|
226
|
-
) -> Series | Expr:
|
|
227
|
-
"""
|
|
228
|
-
Create a column of date ranges.
|
|
229
|
-
|
|
230
|
-
Parameters
|
|
231
|
-
----------
|
|
232
|
-
start
|
|
233
|
-
Lower bound of the date range.
|
|
234
|
-
end
|
|
235
|
-
Upper bound of the date range.
|
|
236
|
-
interval
|
|
237
|
-
Interval of the range periods, specified as a Python `timedelta` object
|
|
238
|
-
or using the Polars duration string language (see "Notes" section below).
|
|
239
|
-
Must consist of full days.
|
|
240
|
-
closed : {'both', 'left', 'right', 'none'}
|
|
241
|
-
Define which sides of the range are closed (inclusive).
|
|
242
|
-
eager
|
|
243
|
-
Evaluate immediately and return a `Series`.
|
|
244
|
-
If set to `False` (default), return an expression instead.
|
|
245
|
-
|
|
246
|
-
Returns
|
|
247
|
-
-------
|
|
248
|
-
Expr or Series
|
|
249
|
-
Column of data type `List(Date)`.
|
|
250
|
-
|
|
251
|
-
See Also
|
|
252
|
-
--------
|
|
253
|
-
date_range
|
|
254
|
-
datetime_ranges
|
|
255
|
-
|
|
256
|
-
Notes
|
|
257
|
-
-----
|
|
258
|
-
`interval` is created according to the following string language:
|
|
259
|
-
|
|
260
|
-
- 1d (1 calendar day)
|
|
261
|
-
- 1w (1 calendar week)
|
|
262
|
-
- 1mo (1 calendar month)
|
|
263
|
-
- 1q (1 calendar quarter)
|
|
264
|
-
- 1y (1 calendar year)
|
|
265
|
-
|
|
266
|
-
Or combine them:
|
|
267
|
-
"1w2d" # 1 week, 2 days
|
|
268
|
-
|
|
269
|
-
By "calendar day", we mean the corresponding time on the next day (which may
|
|
270
|
-
not be 24 hours, due to daylight savings). Similarly for "calendar week",
|
|
271
|
-
"calendar month", "calendar quarter", and "calendar year".
|
|
272
|
-
|
|
273
|
-
Examples
|
|
274
|
-
--------
|
|
275
|
-
>>> from datetime import date
|
|
276
|
-
>>> df = pl.DataFrame(
|
|
277
|
-
... {
|
|
278
|
-
... "start": [date(2022, 1, 1), date(2022, 1, 2)],
|
|
279
|
-
... "end": date(2022, 1, 3),
|
|
280
|
-
... }
|
|
281
|
-
... )
|
|
282
|
-
>>> with pl.Config(fmt_str_lengths=50):
|
|
283
|
-
... df.with_columns(date_range=pl.date_ranges("start", "end"))
|
|
284
|
-
shape: (2, 3)
|
|
285
|
-
┌────────────┬────────────┬──────────────────────────────────────┐
|
|
286
|
-
│ start ┆ end ┆ date_range │
|
|
287
|
-
│ --- ┆ --- ┆ --- │
|
|
288
|
-
│ date ┆ date ┆ list[date] │
|
|
289
|
-
╞════════════╪════════════╪══════════════════════════════════════╡
|
|
290
|
-
│ 2022-01-01 ┆ 2022-01-03 ┆ [2022-01-01, 2022-01-02, 2022-01-03] │
|
|
291
|
-
│ 2022-01-02 ┆ 2022-01-03 ┆ [2022-01-02, 2022-01-03] │
|
|
292
|
-
└────────────┴────────────┴──────────────────────────────────────┘
|
|
293
|
-
"""
|
|
294
|
-
interval = parse_interval_argument(interval)
|
|
295
|
-
start_pyexpr = parse_into_expression(start)
|
|
296
|
-
end_pyexpr = parse_into_expression(end)
|
|
297
|
-
|
|
298
|
-
result = wrap_expr(plr.date_ranges(start_pyexpr, end_pyexpr, interval, closed))
|
|
299
|
-
|
|
300
|
-
if eager:
|
|
301
|
-
return F.select(result).to_series()
|
|
302
|
-
|
|
303
|
-
return result
|