polars-runtime-compat 1.34.0b2__cp39-abi3-macosx_11_0_arm64.whl → 1.34.0b4__cp39-abi3-macosx_11_0_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.

Files changed (203) hide show
  1. _polars_runtime_compat/_polars_runtime_compat.abi3.so +0 -0
  2. {polars_runtime_compat-1.34.0b2.dist-info → polars_runtime_compat-1.34.0b4.dist-info}/METADATA +1 -1
  3. polars_runtime_compat-1.34.0b4.dist-info/RECORD +6 -0
  4. polars/__init__.py +0 -528
  5. polars/_cpu_check.py +0 -265
  6. polars/_dependencies.py +0 -355
  7. polars/_plr.py +0 -99
  8. polars/_plr.pyi +0 -2496
  9. polars/_reexport.py +0 -23
  10. polars/_typing.py +0 -478
  11. polars/_utils/__init__.py +0 -37
  12. polars/_utils/async_.py +0 -102
  13. polars/_utils/cache.py +0 -176
  14. polars/_utils/cloud.py +0 -40
  15. polars/_utils/constants.py +0 -29
  16. polars/_utils/construction/__init__.py +0 -46
  17. polars/_utils/construction/dataframe.py +0 -1397
  18. polars/_utils/construction/other.py +0 -72
  19. polars/_utils/construction/series.py +0 -560
  20. polars/_utils/construction/utils.py +0 -118
  21. polars/_utils/convert.py +0 -224
  22. polars/_utils/deprecation.py +0 -406
  23. polars/_utils/getitem.py +0 -457
  24. polars/_utils/logging.py +0 -11
  25. polars/_utils/nest_asyncio.py +0 -264
  26. polars/_utils/parquet.py +0 -15
  27. polars/_utils/parse/__init__.py +0 -12
  28. polars/_utils/parse/expr.py +0 -242
  29. polars/_utils/polars_version.py +0 -19
  30. polars/_utils/pycapsule.py +0 -53
  31. polars/_utils/scan.py +0 -27
  32. polars/_utils/serde.py +0 -63
  33. polars/_utils/slice.py +0 -215
  34. polars/_utils/udfs.py +0 -1251
  35. polars/_utils/unstable.py +0 -63
  36. polars/_utils/various.py +0 -782
  37. polars/_utils/wrap.py +0 -25
  38. polars/api.py +0 -370
  39. polars/catalog/__init__.py +0 -0
  40. polars/catalog/unity/__init__.py +0 -19
  41. polars/catalog/unity/client.py +0 -733
  42. polars/catalog/unity/models.py +0 -152
  43. polars/config.py +0 -1571
  44. polars/convert/__init__.py +0 -25
  45. polars/convert/general.py +0 -1046
  46. polars/convert/normalize.py +0 -261
  47. polars/dataframe/__init__.py +0 -5
  48. polars/dataframe/_html.py +0 -186
  49. polars/dataframe/frame.py +0 -12582
  50. polars/dataframe/group_by.py +0 -1067
  51. polars/dataframe/plotting.py +0 -257
  52. polars/datatype_expr/__init__.py +0 -5
  53. polars/datatype_expr/array.py +0 -56
  54. polars/datatype_expr/datatype_expr.py +0 -304
  55. polars/datatype_expr/list.py +0 -18
  56. polars/datatype_expr/struct.py +0 -69
  57. polars/datatypes/__init__.py +0 -122
  58. polars/datatypes/_parse.py +0 -195
  59. polars/datatypes/_utils.py +0 -48
  60. polars/datatypes/classes.py +0 -1213
  61. polars/datatypes/constants.py +0 -11
  62. polars/datatypes/constructor.py +0 -172
  63. polars/datatypes/convert.py +0 -366
  64. polars/datatypes/group.py +0 -130
  65. polars/exceptions.py +0 -230
  66. polars/expr/__init__.py +0 -7
  67. polars/expr/array.py +0 -964
  68. polars/expr/binary.py +0 -346
  69. polars/expr/categorical.py +0 -306
  70. polars/expr/datetime.py +0 -2620
  71. polars/expr/expr.py +0 -11272
  72. polars/expr/list.py +0 -1408
  73. polars/expr/meta.py +0 -444
  74. polars/expr/name.py +0 -321
  75. polars/expr/string.py +0 -3045
  76. polars/expr/struct.py +0 -357
  77. polars/expr/whenthen.py +0 -185
  78. polars/functions/__init__.py +0 -193
  79. polars/functions/aggregation/__init__.py +0 -33
  80. polars/functions/aggregation/horizontal.py +0 -298
  81. polars/functions/aggregation/vertical.py +0 -341
  82. polars/functions/as_datatype.py +0 -848
  83. polars/functions/business.py +0 -138
  84. polars/functions/col.py +0 -384
  85. polars/functions/datatype.py +0 -121
  86. polars/functions/eager.py +0 -524
  87. polars/functions/escape_regex.py +0 -29
  88. polars/functions/lazy.py +0 -2751
  89. polars/functions/len.py +0 -68
  90. polars/functions/lit.py +0 -210
  91. polars/functions/random.py +0 -22
  92. polars/functions/range/__init__.py +0 -19
  93. polars/functions/range/_utils.py +0 -15
  94. polars/functions/range/date_range.py +0 -303
  95. polars/functions/range/datetime_range.py +0 -370
  96. polars/functions/range/int_range.py +0 -348
  97. polars/functions/range/linear_space.py +0 -311
  98. polars/functions/range/time_range.py +0 -287
  99. polars/functions/repeat.py +0 -301
  100. polars/functions/whenthen.py +0 -353
  101. polars/interchange/__init__.py +0 -10
  102. polars/interchange/buffer.py +0 -77
  103. polars/interchange/column.py +0 -190
  104. polars/interchange/dataframe.py +0 -230
  105. polars/interchange/from_dataframe.py +0 -328
  106. polars/interchange/protocol.py +0 -303
  107. polars/interchange/utils.py +0 -170
  108. polars/io/__init__.py +0 -64
  109. polars/io/_utils.py +0 -317
  110. polars/io/avro.py +0 -49
  111. polars/io/clipboard.py +0 -36
  112. polars/io/cloud/__init__.py +0 -17
  113. polars/io/cloud/_utils.py +0 -80
  114. polars/io/cloud/credential_provider/__init__.py +0 -17
  115. polars/io/cloud/credential_provider/_builder.py +0 -520
  116. polars/io/cloud/credential_provider/_providers.py +0 -618
  117. polars/io/csv/__init__.py +0 -9
  118. polars/io/csv/_utils.py +0 -38
  119. polars/io/csv/batched_reader.py +0 -142
  120. polars/io/csv/functions.py +0 -1495
  121. polars/io/database/__init__.py +0 -6
  122. polars/io/database/_arrow_registry.py +0 -70
  123. polars/io/database/_cursor_proxies.py +0 -147
  124. polars/io/database/_executor.py +0 -578
  125. polars/io/database/_inference.py +0 -314
  126. polars/io/database/_utils.py +0 -144
  127. polars/io/database/functions.py +0 -516
  128. polars/io/delta.py +0 -499
  129. polars/io/iceberg/__init__.py +0 -3
  130. polars/io/iceberg/_utils.py +0 -697
  131. polars/io/iceberg/dataset.py +0 -556
  132. polars/io/iceberg/functions.py +0 -151
  133. polars/io/ipc/__init__.py +0 -8
  134. polars/io/ipc/functions.py +0 -514
  135. polars/io/json/__init__.py +0 -3
  136. polars/io/json/read.py +0 -101
  137. polars/io/ndjson.py +0 -332
  138. polars/io/parquet/__init__.py +0 -17
  139. polars/io/parquet/field_overwrites.py +0 -140
  140. polars/io/parquet/functions.py +0 -722
  141. polars/io/partition.py +0 -491
  142. polars/io/plugins.py +0 -187
  143. polars/io/pyarrow_dataset/__init__.py +0 -5
  144. polars/io/pyarrow_dataset/anonymous_scan.py +0 -109
  145. polars/io/pyarrow_dataset/functions.py +0 -79
  146. polars/io/scan_options/__init__.py +0 -5
  147. polars/io/scan_options/_options.py +0 -59
  148. polars/io/scan_options/cast_options.py +0 -126
  149. polars/io/spreadsheet/__init__.py +0 -6
  150. polars/io/spreadsheet/_utils.py +0 -52
  151. polars/io/spreadsheet/_write_utils.py +0 -647
  152. polars/io/spreadsheet/functions.py +0 -1323
  153. polars/lazyframe/__init__.py +0 -9
  154. polars/lazyframe/engine_config.py +0 -61
  155. polars/lazyframe/frame.py +0 -8564
  156. polars/lazyframe/group_by.py +0 -669
  157. polars/lazyframe/in_process.py +0 -42
  158. polars/lazyframe/opt_flags.py +0 -333
  159. polars/meta/__init__.py +0 -14
  160. polars/meta/build.py +0 -33
  161. polars/meta/index_type.py +0 -27
  162. polars/meta/thread_pool.py +0 -50
  163. polars/meta/versions.py +0 -120
  164. polars/ml/__init__.py +0 -0
  165. polars/ml/torch.py +0 -213
  166. polars/ml/utilities.py +0 -30
  167. polars/plugins.py +0 -155
  168. polars/py.typed +0 -0
  169. polars/pyproject.toml +0 -96
  170. polars/schema.py +0 -265
  171. polars/selectors.py +0 -3117
  172. polars/series/__init__.py +0 -5
  173. polars/series/array.py +0 -776
  174. polars/series/binary.py +0 -254
  175. polars/series/categorical.py +0 -246
  176. polars/series/datetime.py +0 -2275
  177. polars/series/list.py +0 -1087
  178. polars/series/plotting.py +0 -191
  179. polars/series/series.py +0 -9197
  180. polars/series/string.py +0 -2367
  181. polars/series/struct.py +0 -154
  182. polars/series/utils.py +0 -191
  183. polars/sql/__init__.py +0 -7
  184. polars/sql/context.py +0 -677
  185. polars/sql/functions.py +0 -139
  186. polars/string_cache.py +0 -185
  187. polars/testing/__init__.py +0 -13
  188. polars/testing/asserts/__init__.py +0 -9
  189. polars/testing/asserts/frame.py +0 -231
  190. polars/testing/asserts/series.py +0 -219
  191. polars/testing/asserts/utils.py +0 -12
  192. polars/testing/parametric/__init__.py +0 -33
  193. polars/testing/parametric/profiles.py +0 -107
  194. polars/testing/parametric/strategies/__init__.py +0 -22
  195. polars/testing/parametric/strategies/_utils.py +0 -14
  196. polars/testing/parametric/strategies/core.py +0 -615
  197. polars/testing/parametric/strategies/data.py +0 -452
  198. polars/testing/parametric/strategies/dtype.py +0 -436
  199. polars/testing/parametric/strategies/legacy.py +0 -169
  200. polars/type_aliases.py +0 -24
  201. polars_runtime_compat-1.34.0b2.dist-info/RECORD +0 -203
  202. {polars_runtime_compat-1.34.0b2.dist-info → polars_runtime_compat-1.34.0b4.dist-info}/WHEEL +0 -0
  203. {polars_runtime_compat-1.34.0b2.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))
@@ -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
- ]
@@ -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