polars-runtime-compat 1.34.0b2__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.

Files changed (203) hide show
  1. _polars_runtime_compat/_polars_runtime_compat.pyd +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
@@ -1,370 +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, TimeUnit
20
-
21
-
22
- @overload
23
- def datetime_range(
24
- start: datetime | date | IntoExprColumn,
25
- end: datetime | date | IntoExprColumn,
26
- interval: str | timedelta = ...,
27
- *,
28
- closed: ClosedInterval = ...,
29
- time_unit: TimeUnit | None = ...,
30
- time_zone: str | None = ...,
31
- eager: Literal[False] = ...,
32
- ) -> Expr: ...
33
-
34
-
35
- @overload
36
- def datetime_range(
37
- start: datetime | date | IntoExprColumn,
38
- end: datetime | date | IntoExprColumn,
39
- interval: str | timedelta = ...,
40
- *,
41
- closed: ClosedInterval = ...,
42
- time_unit: TimeUnit | None = ...,
43
- time_zone: str | None = ...,
44
- eager: Literal[True],
45
- ) -> Series: ...
46
-
47
-
48
- @overload
49
- def datetime_range(
50
- start: datetime | date | IntoExprColumn,
51
- end: datetime | date | IntoExprColumn,
52
- interval: str | timedelta = ...,
53
- *,
54
- closed: ClosedInterval = ...,
55
- time_unit: TimeUnit | None = ...,
56
- time_zone: str | None = ...,
57
- eager: bool,
58
- ) -> Series | Expr: ...
59
-
60
-
61
- def datetime_range(
62
- start: datetime | date | IntoExprColumn,
63
- end: datetime | date | IntoExprColumn,
64
- interval: str | timedelta = "1d",
65
- *,
66
- closed: ClosedInterval = "both",
67
- time_unit: TimeUnit | None = None,
68
- time_zone: str | None = None,
69
- eager: bool = False,
70
- ) -> Series | Expr:
71
- """
72
- Generate a datetime range.
73
-
74
- Parameters
75
- ----------
76
- start
77
- Lower bound of the datetime range.
78
- end
79
- Upper bound of the datetime range.
80
- interval
81
- Interval of the range periods, specified as a Python `timedelta` object
82
- or using the Polars duration string language (see "Notes" section below).
83
- closed : {'both', 'left', 'right', 'none'}
84
- Define which sides of the range are closed (inclusive).
85
- time_unit : {None, 'ns', 'us', 'ms'}
86
- Time unit of the resulting `Datetime` data type.
87
- time_zone
88
- Time zone of the resulting `Datetime` data type.
89
- eager
90
- Evaluate immediately and return a `Series`.
91
- If set to `False` (default), return an expression instead.
92
-
93
- Returns
94
- -------
95
- Expr or Series
96
- Column of data type :class:`Datetime`.
97
-
98
- See Also
99
- --------
100
- datetime_ranges
101
- date_range
102
-
103
- Notes
104
- -----
105
- `interval` is created according to the following string language:
106
-
107
- - 1ns (1 nanosecond)
108
- - 1us (1 microsecond)
109
- - 1ms (1 millisecond)
110
- - 1s (1 second)
111
- - 1m (1 minute)
112
- - 1h (1 hour)
113
- - 1d (1 calendar day)
114
- - 1w (1 calendar week)
115
- - 1mo (1 calendar month)
116
- - 1q (1 calendar quarter)
117
- - 1y (1 calendar year)
118
-
119
- Or combine them:
120
- "3d12h4m25s" # 3 days, 12 hours, 4 minutes, and 25 seconds
121
-
122
- By "calendar day", we mean the corresponding time on the next day (which may
123
- not be 24 hours, due to daylight savings). Similarly for "calendar week",
124
- "calendar month", "calendar quarter", and "calendar year".
125
-
126
- Examples
127
- --------
128
- Using Polars duration string to specify the interval:
129
-
130
- >>> from datetime import datetime
131
- >>> pl.datetime_range(
132
- ... datetime(2022, 1, 1), datetime(2022, 3, 1), "1mo", eager=True
133
- ... ).alias("datetime")
134
- shape: (3,)
135
- Series: 'datetime' [datetime[μs]]
136
- [
137
- 2022-01-01 00:00:00
138
- 2022-02-01 00:00:00
139
- 2022-03-01 00:00:00
140
- ]
141
-
142
- Using `timedelta` object to specify the interval:
143
-
144
- >>> from datetime import date, timedelta
145
- >>> pl.datetime_range(
146
- ... date(1985, 1, 1),
147
- ... date(1985, 1, 10),
148
- ... timedelta(days=1, hours=12),
149
- ... time_unit="ms",
150
- ... eager=True,
151
- ... ).alias("datetime")
152
- shape: (7,)
153
- Series: 'datetime' [datetime[ms]]
154
- [
155
- 1985-01-01 00:00:00
156
- 1985-01-02 12:00:00
157
- 1985-01-04 00:00:00
158
- 1985-01-05 12:00:00
159
- 1985-01-07 00:00:00
160
- 1985-01-08 12:00:00
161
- 1985-01-10 00:00:00
162
- ]
163
-
164
- Specifying a time zone:
165
-
166
- >>> pl.datetime_range(
167
- ... datetime(2022, 1, 1),
168
- ... datetime(2022, 3, 1),
169
- ... "1mo",
170
- ... time_zone="America/New_York",
171
- ... eager=True,
172
- ... ).alias("datetime")
173
- shape: (3,)
174
- Series: 'datetime' [datetime[μs, America/New_York]]
175
- [
176
- 2022-01-01 00:00:00 EST
177
- 2022-02-01 00:00:00 EST
178
- 2022-03-01 00:00:00 EST
179
- ]
180
-
181
- Omit `eager=True` if you want to use `datetime_range` as an expression:
182
-
183
- >>> df = pl.DataFrame(
184
- ... {
185
- ... "date": [
186
- ... date(2024, 1, 1),
187
- ... date(2024, 1, 2),
188
- ... date(2024, 1, 1),
189
- ... date(2024, 1, 3),
190
- ... ],
191
- ... "key": ["one", "one", "two", "two"],
192
- ... }
193
- ... )
194
- >>> result = (
195
- ... df.group_by("key")
196
- ... .agg(pl.datetime_range(pl.col("date").min(), pl.col("date").max()))
197
- ... .sort("key")
198
- ... )
199
- >>> with pl.Config(fmt_str_lengths=70):
200
- ... print(result)
201
- shape: (2, 2)
202
- ┌─────┬─────────────────────────────────────────────────────────────────┐
203
- │ key ┆ date │
204
- │ --- ┆ --- │
205
- │ str ┆ list[datetime[μs]] │
206
- ╞═════╪═════════════════════════════════════════════════════════════════╡
207
- │ one ┆ [2024-01-01 00:00:00, 2024-01-02 00:00:00] │
208
- │ two ┆ [2024-01-01 00:00:00, 2024-01-02 00:00:00, 2024-01-03 00:00:00] │
209
- └─────┴─────────────────────────────────────────────────────────────────┘
210
- """
211
- interval = parse_interval_argument(interval)
212
- if time_unit is None and "ns" in interval:
213
- time_unit = "ns"
214
-
215
- start_pyexpr = parse_into_expression(start)
216
- end_pyexpr = parse_into_expression(end)
217
- result = wrap_expr(
218
- plr.datetime_range(
219
- start_pyexpr, end_pyexpr, interval, closed, time_unit, time_zone
220
- )
221
- )
222
-
223
- if eager:
224
- return F.select(result).to_series()
225
-
226
- return result
227
-
228
-
229
- @overload
230
- def datetime_ranges(
231
- start: datetime | date | IntoExprColumn,
232
- end: datetime | date | IntoExprColumn,
233
- interval: str | timedelta = ...,
234
- *,
235
- closed: ClosedInterval = ...,
236
- time_unit: TimeUnit | None = ...,
237
- time_zone: str | None = ...,
238
- eager: Literal[False] = ...,
239
- ) -> Expr: ...
240
-
241
-
242
- @overload
243
- def datetime_ranges(
244
- start: datetime | date | IntoExprColumn,
245
- end: datetime | date | IntoExprColumn,
246
- interval: str | timedelta = ...,
247
- *,
248
- closed: ClosedInterval = ...,
249
- time_unit: TimeUnit | None = ...,
250
- time_zone: str | None = ...,
251
- eager: Literal[True],
252
- ) -> Series: ...
253
-
254
-
255
- @overload
256
- def datetime_ranges(
257
- start: datetime | date | IntoExprColumn,
258
- end: datetime | date | IntoExprColumn,
259
- interval: str | timedelta = ...,
260
- *,
261
- closed: ClosedInterval = ...,
262
- time_unit: TimeUnit | None = ...,
263
- time_zone: str | None = ...,
264
- eager: bool,
265
- ) -> Series | Expr: ...
266
-
267
-
268
- def datetime_ranges(
269
- start: datetime | date | IntoExprColumn,
270
- end: datetime | date | IntoExprColumn,
271
- interval: str | timedelta = "1d",
272
- *,
273
- closed: ClosedInterval = "both",
274
- time_unit: TimeUnit | None = None,
275
- time_zone: str | None = None,
276
- eager: bool = False,
277
- ) -> Series | Expr:
278
- """
279
- Create a column of datetime ranges.
280
-
281
- Parameters
282
- ----------
283
- start
284
- Lower bound of the datetime range.
285
- end
286
- Upper bound of the datetime range.
287
- interval
288
- Interval of the range periods, specified as a Python `timedelta` object
289
- or using the Polars duration string language (see "Notes" section below).
290
- closed : {'both', 'left', 'right', 'none'}
291
- Define which sides of the range are closed (inclusive).
292
- time_unit : {None, 'ns', 'us', 'ms'}
293
- Time unit of the resulting `Datetime` data type.
294
- time_zone
295
- Time zone of the resulting `Datetime` data type.
296
- eager
297
- Evaluate immediately and return a `Series`.
298
- If set to `False` (default), return an expression instead.
299
-
300
- Notes
301
- -----
302
- `interval` is created according to the following string language:
303
-
304
- - 1ns (1 nanosecond)
305
- - 1us (1 microsecond)
306
- - 1ms (1 millisecond)
307
- - 1s (1 second)
308
- - 1m (1 minute)
309
- - 1h (1 hour)
310
- - 1d (1 calendar day)
311
- - 1w (1 calendar week)
312
- - 1mo (1 calendar month)
313
- - 1q (1 calendar quarter)
314
- - 1y (1 calendar year)
315
-
316
- Or combine them:
317
- "3d12h4m25s" # 3 days, 12 hours, 4 minutes, and 25 seconds
318
-
319
- By "calendar day", we mean the corresponding time on the next day (which may
320
- not be 24 hours, due to daylight savings). Similarly for "calendar week",
321
- "calendar month", "calendar quarter", and "calendar year".
322
-
323
- Returns
324
- -------
325
- Expr or Series
326
- Column of data type `List(Datetime)`.
327
-
328
- See Also
329
- --------
330
- datetime_range
331
- date_ranges
332
-
333
- Examples
334
- --------
335
- >>> from datetime import datetime
336
- >>> df = pl.DataFrame(
337
- ... {
338
- ... "start": [datetime(2022, 1, 1), datetime(2022, 1, 2)],
339
- ... "end": datetime(2022, 1, 3),
340
- ... }
341
- ... )
342
- >>> with pl.Config(fmt_str_lengths=100):
343
- ... df.select(datetime_range=pl.datetime_ranges("start", "end"))
344
- shape: (2, 1)
345
- ┌─────────────────────────────────────────────────────────────────┐
346
- │ datetime_range │
347
- │ --- │
348
- │ list[datetime[μs]] │
349
- ╞═════════════════════════════════════════════════════════════════╡
350
- │ [2022-01-01 00:00:00, 2022-01-02 00:00:00, 2022-01-03 00:00:00] │
351
- │ [2022-01-02 00:00:00, 2022-01-03 00:00:00] │
352
- └─────────────────────────────────────────────────────────────────┘
353
- """
354
- interval = parse_interval_argument(interval)
355
- if time_unit is None and "ns" in interval:
356
- time_unit = "ns"
357
-
358
- start_pyexpr = parse_into_expression(start)
359
- end_pyexpr = parse_into_expression(end)
360
-
361
- result = wrap_expr(
362
- plr.datetime_ranges(
363
- start_pyexpr, end_pyexpr, interval, closed, time_unit, time_zone
364
- )
365
- )
366
-
367
- if eager:
368
- return F.select(result).to_series()
369
-
370
- return result
@@ -1,348 +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, wrap_s
9
- from polars.datatypes import Int64
10
- from polars.datatypes._parse import parse_into_datatype_expr
11
-
12
- with contextlib.suppress(ImportError): # Module not available when building docs
13
- import polars._plr as plr
14
-
15
- if TYPE_CHECKING:
16
- from typing import Literal
17
-
18
- from polars import DataTypeExpr, Expr, Series
19
- from polars._typing import IntoExprColumn, PolarsIntegerType
20
-
21
-
22
- @overload
23
- def arange(
24
- start: int | IntoExprColumn = ...,
25
- end: int | IntoExprColumn | None = ...,
26
- step: int = ...,
27
- *,
28
- dtype: PolarsIntegerType | DataTypeExpr = ...,
29
- eager: Literal[False] = ...,
30
- ) -> Expr: ...
31
-
32
-
33
- @overload
34
- def arange(
35
- start: int | IntoExprColumn = ...,
36
- end: int | IntoExprColumn | None = ...,
37
- step: int = ...,
38
- *,
39
- dtype: PolarsIntegerType | DataTypeExpr = ...,
40
- eager: Literal[True],
41
- ) -> Series: ...
42
-
43
-
44
- @overload
45
- def arange(
46
- start: int | IntoExprColumn = ...,
47
- end: int | IntoExprColumn | None = ...,
48
- step: int = ...,
49
- *,
50
- dtype: PolarsIntegerType | DataTypeExpr = ...,
51
- eager: bool,
52
- ) -> Expr | Series: ...
53
-
54
-
55
- def arange(
56
- start: int | IntoExprColumn = 0,
57
- end: int | IntoExprColumn | None = None,
58
- step: int = 1,
59
- *,
60
- dtype: PolarsIntegerType | DataTypeExpr = Int64,
61
- eager: bool = False,
62
- ) -> Expr | Series:
63
- """
64
- Generate a range of integers.
65
-
66
- Alias for :func:`int_range`.
67
-
68
- Parameters
69
- ----------
70
- start
71
- Lower bound of the range (inclusive).
72
- end
73
- Upper bound of the range (exclusive).
74
- step
75
- Step size of the range.
76
- dtype
77
- Data type of the range. Defaults to `Int64`.
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 integer data type `dtype`.
86
-
87
- See Also
88
- --------
89
- int_range : Generate a range of integers.
90
- int_ranges : Generate a range of integers for each row of the input columns.
91
-
92
- Examples
93
- --------
94
- >>> pl.arange(0, 3, eager=True)
95
- shape: (3,)
96
- Series: 'literal' [i64]
97
- [
98
- 0
99
- 1
100
- 2
101
- ]
102
- """
103
- return int_range(start, end, step, dtype=dtype, eager=eager)
104
-
105
-
106
- @overload
107
- def int_range(
108
- start: int | IntoExprColumn = ...,
109
- end: int | IntoExprColumn | None = ...,
110
- step: int = ...,
111
- *,
112
- dtype: PolarsIntegerType | DataTypeExpr = ...,
113
- eager: Literal[False] = ...,
114
- ) -> Expr: ...
115
-
116
-
117
- @overload
118
- def int_range(
119
- start: int | IntoExprColumn = ...,
120
- end: int | IntoExprColumn | None = ...,
121
- step: int = ...,
122
- *,
123
- dtype: PolarsIntegerType | DataTypeExpr = ...,
124
- eager: Literal[True],
125
- ) -> Series: ...
126
-
127
-
128
- @overload
129
- def int_range(
130
- start: int | IntoExprColumn = ...,
131
- end: int | IntoExprColumn | None = ...,
132
- step: int = ...,
133
- *,
134
- dtype: PolarsIntegerType | DataTypeExpr = ...,
135
- eager: bool,
136
- ) -> Expr | Series: ...
137
-
138
-
139
- def int_range(
140
- start: int | IntoExprColumn = 0,
141
- end: int | IntoExprColumn | None = None,
142
- step: int = 1,
143
- *,
144
- dtype: PolarsIntegerType | DataTypeExpr = Int64,
145
- eager: bool = False,
146
- ) -> Expr | Series:
147
- """
148
- Generate a range of integers.
149
-
150
- Parameters
151
- ----------
152
- start
153
- Start of the range (inclusive). Defaults to 0.
154
- end
155
- End of the range (exclusive). If set to `None` (default),
156
- the value of `start` is used and `start` is set to `0`.
157
- step
158
- Step size of the range.
159
- dtype
160
- Data type of the range.
161
- eager
162
- Evaluate immediately and return a `Series`.
163
- If set to `False` (default), return an expression instead.
164
-
165
- Returns
166
- -------
167
- Expr or Series
168
- Column of integer data type `dtype`.
169
-
170
- See Also
171
- --------
172
- int_ranges : Generate a range of integers for each row of the input columns.
173
-
174
- Examples
175
- --------
176
- >>> pl.int_range(0, 3, eager=True)
177
- shape: (3,)
178
- Series: 'literal' [i64]
179
- [
180
- 0
181
- 1
182
- 2
183
- ]
184
-
185
- `end` can be omitted for a shorter syntax.
186
-
187
- >>> pl.int_range(3, eager=True)
188
- shape: (3,)
189
- Series: 'literal' [i64]
190
- [
191
- 0
192
- 1
193
- 2
194
- ]
195
-
196
- Generate an index column by using `int_range` in conjunction with :func:`len`.
197
-
198
- >>> df = pl.DataFrame({"a": [1, 3, 5], "b": [2, 4, 6]})
199
- >>> df.select(
200
- ... pl.int_range(pl.len(), dtype=pl.UInt32).alias("index"),
201
- ... pl.all(),
202
- ... )
203
- shape: (3, 3)
204
- ┌───────┬─────┬─────┐
205
- │ index ┆ a ┆ b │
206
- │ --- ┆ --- ┆ --- │
207
- │ u32 ┆ i64 ┆ i64 │
208
- ╞═══════╪═════╪═════╡
209
- │ 0 ┆ 1 ┆ 2 │
210
- │ 1 ┆ 3 ┆ 4 │
211
- │ 2 ┆ 5 ┆ 6 │
212
- └───────┴─────┴─────┘
213
- """
214
- if end is None:
215
- end = start
216
- start = 0
217
-
218
- dtype_expr = parse_into_datatype_expr(dtype)
219
- if isinstance(start, int) and isinstance(end, int) and eager:
220
- return wrap_s(
221
- plr.eager_int_range(start, end, step, dtype_expr._pydatatype_expr)
222
- )
223
-
224
- start_pyexpr = parse_into_expression(start)
225
- end_pyexpr = parse_into_expression(end)
226
- result = wrap_expr(
227
- plr.int_range(start_pyexpr, end_pyexpr, step, dtype_expr._pydatatype_expr)
228
- )
229
-
230
- if eager:
231
- return F.select(result).to_series()
232
-
233
- return result
234
-
235
-
236
- @overload
237
- def int_ranges(
238
- start: int | IntoExprColumn = ...,
239
- end: int | IntoExprColumn | None = ...,
240
- step: int | IntoExprColumn = ...,
241
- *,
242
- dtype: PolarsIntegerType | DataTypeExpr = ...,
243
- eager: Literal[False] = ...,
244
- ) -> Expr: ...
245
-
246
-
247
- @overload
248
- def int_ranges(
249
- start: int | IntoExprColumn = ...,
250
- end: int | IntoExprColumn | None = ...,
251
- step: int | IntoExprColumn = ...,
252
- *,
253
- dtype: PolarsIntegerType | DataTypeExpr = ...,
254
- eager: Literal[True],
255
- ) -> Series: ...
256
-
257
-
258
- @overload
259
- def int_ranges(
260
- start: int | IntoExprColumn = ...,
261
- end: int | IntoExprColumn | None = ...,
262
- step: int | IntoExprColumn = ...,
263
- *,
264
- dtype: PolarsIntegerType | DataTypeExpr = ...,
265
- eager: bool,
266
- ) -> Expr | Series: ...
267
-
268
-
269
- def int_ranges(
270
- start: int | IntoExprColumn = 0,
271
- end: int | IntoExprColumn | None = None,
272
- step: int | IntoExprColumn = 1,
273
- *,
274
- dtype: PolarsIntegerType | DataTypeExpr = Int64,
275
- eager: bool = False,
276
- ) -> Expr | Series:
277
- """
278
- Generate a range of integers for each row of the input columns.
279
-
280
- Parameters
281
- ----------
282
- start
283
- Start of the range (inclusive). Defaults to 0.
284
- end
285
- End of the range (exclusive). If set to `None` (default),
286
- the value of `start` is used and `start` is set to `0`.
287
- step
288
- Step size of the range.
289
- dtype
290
- Integer data type of the ranges. Defaults to `Int64`.
291
- eager
292
- Evaluate immediately and return a `Series`.
293
- If set to `False` (default), return an expression instead.
294
-
295
- Returns
296
- -------
297
- Expr or Series
298
- Column of data type `List(dtype)`.
299
-
300
- See Also
301
- --------
302
- int_range : Generate a single range of integers.
303
-
304
- Examples
305
- --------
306
- >>> df = pl.DataFrame({"start": [1, -1], "end": [3, 2]})
307
- >>> df.with_columns(int_range=pl.int_ranges("start", "end"))
308
- shape: (2, 3)
309
- ┌───────┬─────┬────────────┐
310
- │ start ┆ end ┆ int_range │
311
- │ --- ┆ --- ┆ --- │
312
- │ i64 ┆ i64 ┆ list[i64] │
313
- ╞═══════╪═════╪════════════╡
314
- │ 1 ┆ 3 ┆ [1, 2] │
315
- │ -1 ┆ 2 ┆ [-1, 0, 1] │
316
- └───────┴─────┴────────────┘
317
-
318
- `end` can be omitted for a shorter syntax.
319
-
320
- >>> df.select("end", int_range=pl.int_ranges("end"))
321
- shape: (2, 2)
322
- ┌─────┬───────────┐
323
- │ end ┆ int_range │
324
- │ --- ┆ --- │
325
- │ i64 ┆ list[i64] │
326
- ╞═════╪═══════════╡
327
- │ 3 ┆ [0, 1, 2] │
328
- │ 2 ┆ [0, 1] │
329
- └─────┴───────────┘
330
- """
331
- if end is None:
332
- end = start
333
- start = 0
334
-
335
- dtype_expr = parse_into_datatype_expr(dtype)
336
- start_pyexpr = parse_into_expression(start)
337
- end_pyexpr = parse_into_expression(end)
338
- step_pyexpr = parse_into_expression(step)
339
- result = wrap_expr(
340
- plr.int_ranges(
341
- start_pyexpr, end_pyexpr, step_pyexpr, dtype_expr._pydatatype_expr
342
- )
343
- )
344
-
345
- if eager:
346
- return F.select(result).to_series()
347
-
348
- return result