polars-runtime-compat 1.34.0b2__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/.gitkeep +0 -0
  2. _polars_runtime_compat/_polars_runtime_compat.abi3.so +0 -0
  3. polars/__init__.py +528 -0
  4. polars/_cpu_check.py +265 -0
  5. polars/_dependencies.py +355 -0
  6. polars/_plr.py +99 -0
  7. polars/_plr.pyi +2496 -0
  8. polars/_reexport.py +23 -0
  9. polars/_typing.py +478 -0
  10. polars/_utils/__init__.py +37 -0
  11. polars/_utils/async_.py +102 -0
  12. polars/_utils/cache.py +176 -0
  13. polars/_utils/cloud.py +40 -0
  14. polars/_utils/constants.py +29 -0
  15. polars/_utils/construction/__init__.py +46 -0
  16. polars/_utils/construction/dataframe.py +1397 -0
  17. polars/_utils/construction/other.py +72 -0
  18. polars/_utils/construction/series.py +560 -0
  19. polars/_utils/construction/utils.py +118 -0
  20. polars/_utils/convert.py +224 -0
  21. polars/_utils/deprecation.py +406 -0
  22. polars/_utils/getitem.py +457 -0
  23. polars/_utils/logging.py +11 -0
  24. polars/_utils/nest_asyncio.py +264 -0
  25. polars/_utils/parquet.py +15 -0
  26. polars/_utils/parse/__init__.py +12 -0
  27. polars/_utils/parse/expr.py +242 -0
  28. polars/_utils/polars_version.py +19 -0
  29. polars/_utils/pycapsule.py +53 -0
  30. polars/_utils/scan.py +27 -0
  31. polars/_utils/serde.py +63 -0
  32. polars/_utils/slice.py +215 -0
  33. polars/_utils/udfs.py +1251 -0
  34. polars/_utils/unstable.py +63 -0
  35. polars/_utils/various.py +782 -0
  36. polars/_utils/wrap.py +25 -0
  37. polars/api.py +370 -0
  38. polars/catalog/__init__.py +0 -0
  39. polars/catalog/unity/__init__.py +19 -0
  40. polars/catalog/unity/client.py +733 -0
  41. polars/catalog/unity/models.py +152 -0
  42. polars/config.py +1571 -0
  43. polars/convert/__init__.py +25 -0
  44. polars/convert/general.py +1046 -0
  45. polars/convert/normalize.py +261 -0
  46. polars/dataframe/__init__.py +5 -0
  47. polars/dataframe/_html.py +186 -0
  48. polars/dataframe/frame.py +12582 -0
  49. polars/dataframe/group_by.py +1067 -0
  50. polars/dataframe/plotting.py +257 -0
  51. polars/datatype_expr/__init__.py +5 -0
  52. polars/datatype_expr/array.py +56 -0
  53. polars/datatype_expr/datatype_expr.py +304 -0
  54. polars/datatype_expr/list.py +18 -0
  55. polars/datatype_expr/struct.py +69 -0
  56. polars/datatypes/__init__.py +122 -0
  57. polars/datatypes/_parse.py +195 -0
  58. polars/datatypes/_utils.py +48 -0
  59. polars/datatypes/classes.py +1213 -0
  60. polars/datatypes/constants.py +11 -0
  61. polars/datatypes/constructor.py +172 -0
  62. polars/datatypes/convert.py +366 -0
  63. polars/datatypes/group.py +130 -0
  64. polars/exceptions.py +230 -0
  65. polars/expr/__init__.py +7 -0
  66. polars/expr/array.py +964 -0
  67. polars/expr/binary.py +346 -0
  68. polars/expr/categorical.py +306 -0
  69. polars/expr/datetime.py +2620 -0
  70. polars/expr/expr.py +11272 -0
  71. polars/expr/list.py +1408 -0
  72. polars/expr/meta.py +444 -0
  73. polars/expr/name.py +321 -0
  74. polars/expr/string.py +3045 -0
  75. polars/expr/struct.py +357 -0
  76. polars/expr/whenthen.py +185 -0
  77. polars/functions/__init__.py +193 -0
  78. polars/functions/aggregation/__init__.py +33 -0
  79. polars/functions/aggregation/horizontal.py +298 -0
  80. polars/functions/aggregation/vertical.py +341 -0
  81. polars/functions/as_datatype.py +848 -0
  82. polars/functions/business.py +138 -0
  83. polars/functions/col.py +384 -0
  84. polars/functions/datatype.py +121 -0
  85. polars/functions/eager.py +524 -0
  86. polars/functions/escape_regex.py +29 -0
  87. polars/functions/lazy.py +2751 -0
  88. polars/functions/len.py +68 -0
  89. polars/functions/lit.py +210 -0
  90. polars/functions/random.py +22 -0
  91. polars/functions/range/__init__.py +19 -0
  92. polars/functions/range/_utils.py +15 -0
  93. polars/functions/range/date_range.py +303 -0
  94. polars/functions/range/datetime_range.py +370 -0
  95. polars/functions/range/int_range.py +348 -0
  96. polars/functions/range/linear_space.py +311 -0
  97. polars/functions/range/time_range.py +287 -0
  98. polars/functions/repeat.py +301 -0
  99. polars/functions/whenthen.py +353 -0
  100. polars/interchange/__init__.py +10 -0
  101. polars/interchange/buffer.py +77 -0
  102. polars/interchange/column.py +190 -0
  103. polars/interchange/dataframe.py +230 -0
  104. polars/interchange/from_dataframe.py +328 -0
  105. polars/interchange/protocol.py +303 -0
  106. polars/interchange/utils.py +170 -0
  107. polars/io/__init__.py +64 -0
  108. polars/io/_utils.py +317 -0
  109. polars/io/avro.py +49 -0
  110. polars/io/clipboard.py +36 -0
  111. polars/io/cloud/__init__.py +17 -0
  112. polars/io/cloud/_utils.py +80 -0
  113. polars/io/cloud/credential_provider/__init__.py +17 -0
  114. polars/io/cloud/credential_provider/_builder.py +520 -0
  115. polars/io/cloud/credential_provider/_providers.py +618 -0
  116. polars/io/csv/__init__.py +9 -0
  117. polars/io/csv/_utils.py +38 -0
  118. polars/io/csv/batched_reader.py +142 -0
  119. polars/io/csv/functions.py +1495 -0
  120. polars/io/database/__init__.py +6 -0
  121. polars/io/database/_arrow_registry.py +70 -0
  122. polars/io/database/_cursor_proxies.py +147 -0
  123. polars/io/database/_executor.py +578 -0
  124. polars/io/database/_inference.py +314 -0
  125. polars/io/database/_utils.py +144 -0
  126. polars/io/database/functions.py +516 -0
  127. polars/io/delta.py +499 -0
  128. polars/io/iceberg/__init__.py +3 -0
  129. polars/io/iceberg/_utils.py +697 -0
  130. polars/io/iceberg/dataset.py +556 -0
  131. polars/io/iceberg/functions.py +151 -0
  132. polars/io/ipc/__init__.py +8 -0
  133. polars/io/ipc/functions.py +514 -0
  134. polars/io/json/__init__.py +3 -0
  135. polars/io/json/read.py +101 -0
  136. polars/io/ndjson.py +332 -0
  137. polars/io/parquet/__init__.py +17 -0
  138. polars/io/parquet/field_overwrites.py +140 -0
  139. polars/io/parquet/functions.py +722 -0
  140. polars/io/partition.py +491 -0
  141. polars/io/plugins.py +187 -0
  142. polars/io/pyarrow_dataset/__init__.py +5 -0
  143. polars/io/pyarrow_dataset/anonymous_scan.py +109 -0
  144. polars/io/pyarrow_dataset/functions.py +79 -0
  145. polars/io/scan_options/__init__.py +5 -0
  146. polars/io/scan_options/_options.py +59 -0
  147. polars/io/scan_options/cast_options.py +126 -0
  148. polars/io/spreadsheet/__init__.py +6 -0
  149. polars/io/spreadsheet/_utils.py +52 -0
  150. polars/io/spreadsheet/_write_utils.py +647 -0
  151. polars/io/spreadsheet/functions.py +1323 -0
  152. polars/lazyframe/__init__.py +9 -0
  153. polars/lazyframe/engine_config.py +61 -0
  154. polars/lazyframe/frame.py +8564 -0
  155. polars/lazyframe/group_by.py +669 -0
  156. polars/lazyframe/in_process.py +42 -0
  157. polars/lazyframe/opt_flags.py +333 -0
  158. polars/meta/__init__.py +14 -0
  159. polars/meta/build.py +33 -0
  160. polars/meta/index_type.py +27 -0
  161. polars/meta/thread_pool.py +50 -0
  162. polars/meta/versions.py +120 -0
  163. polars/ml/__init__.py +0 -0
  164. polars/ml/torch.py +213 -0
  165. polars/ml/utilities.py +30 -0
  166. polars/plugins.py +155 -0
  167. polars/py.typed +0 -0
  168. polars/pyproject.toml +96 -0
  169. polars/schema.py +265 -0
  170. polars/selectors.py +3117 -0
  171. polars/series/__init__.py +5 -0
  172. polars/series/array.py +776 -0
  173. polars/series/binary.py +254 -0
  174. polars/series/categorical.py +246 -0
  175. polars/series/datetime.py +2275 -0
  176. polars/series/list.py +1087 -0
  177. polars/series/plotting.py +191 -0
  178. polars/series/series.py +9197 -0
  179. polars/series/string.py +2367 -0
  180. polars/series/struct.py +154 -0
  181. polars/series/utils.py +191 -0
  182. polars/sql/__init__.py +7 -0
  183. polars/sql/context.py +677 -0
  184. polars/sql/functions.py +139 -0
  185. polars/string_cache.py +185 -0
  186. polars/testing/__init__.py +13 -0
  187. polars/testing/asserts/__init__.py +9 -0
  188. polars/testing/asserts/frame.py +231 -0
  189. polars/testing/asserts/series.py +219 -0
  190. polars/testing/asserts/utils.py +12 -0
  191. polars/testing/parametric/__init__.py +33 -0
  192. polars/testing/parametric/profiles.py +107 -0
  193. polars/testing/parametric/strategies/__init__.py +22 -0
  194. polars/testing/parametric/strategies/_utils.py +14 -0
  195. polars/testing/parametric/strategies/core.py +615 -0
  196. polars/testing/parametric/strategies/data.py +452 -0
  197. polars/testing/parametric/strategies/dtype.py +436 -0
  198. polars/testing/parametric/strategies/legacy.py +169 -0
  199. polars/type_aliases.py +24 -0
  200. polars_runtime_compat-1.34.0b2.dist-info/METADATA +190 -0
  201. polars_runtime_compat-1.34.0b2.dist-info/RECORD +203 -0
  202. polars_runtime_compat-1.34.0b2.dist-info/WHEEL +4 -0
  203. polars_runtime_compat-1.34.0b2.dist-info/licenses/LICENSE +20 -0
polars/series/array.py ADDED
@@ -0,0 +1,776 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, Callable
4
+
5
+ from polars import functions as F
6
+ from polars._utils.wrap import wrap_s
7
+ from polars.series.utils import expr_dispatch
8
+
9
+ if TYPE_CHECKING:
10
+ from collections.abc import Sequence
11
+
12
+ from polars import Series
13
+ from polars._plr import PySeries
14
+ from polars._typing import IntoExpr, IntoExprColumn
15
+ from polars.expr.expr import Expr
16
+
17
+
18
+ @expr_dispatch
19
+ class ArrayNameSpace:
20
+ """Namespace for array related methods."""
21
+
22
+ _accessor = "arr"
23
+
24
+ def __init__(self, series: Series) -> None:
25
+ self._s: PySeries = series._s
26
+
27
+ def min(self) -> Series:
28
+ """
29
+ Compute the min values of the sub-arrays.
30
+
31
+ Examples
32
+ --------
33
+ >>> s = pl.Series("a", [[1, 2], [4, 3]], dtype=pl.Array(pl.Int64, 2))
34
+ >>> s.arr.min()
35
+ shape: (2,)
36
+ Series: 'a' [i64]
37
+ [
38
+ 1
39
+ 3
40
+ ]
41
+ """
42
+
43
+ def max(self) -> Series:
44
+ """
45
+ Compute the max values of the sub-arrays.
46
+
47
+ Examples
48
+ --------
49
+ >>> s = pl.Series("a", [[1, 2], [4, 3]], dtype=pl.Array(pl.Int64, 2))
50
+ >>> s.arr.max()
51
+ shape: (2,)
52
+ Series: 'a' [i64]
53
+ [
54
+ 2
55
+ 4
56
+ ]
57
+ """
58
+
59
+ def sum(self) -> Series:
60
+ """
61
+ Compute the sum values of the sub-arrays.
62
+
63
+ Notes
64
+ -----
65
+ If there are no non-null elements in a row, the output is `0`.
66
+
67
+ Examples
68
+ --------
69
+ >>> s = pl.Series([[1, 2], [4, 3]], dtype=pl.Array(pl.Int64, 2))
70
+ >>> s.arr.sum()
71
+ shape: (2,)
72
+ Series: '' [i64]
73
+ [
74
+ 3
75
+ 7
76
+ ]
77
+ """
78
+
79
+ def std(self, ddof: int = 1) -> Series:
80
+ """
81
+ Compute the std of the values of the sub-arrays.
82
+
83
+ Examples
84
+ --------
85
+ >>> s = pl.Series("a", [[1, 2], [4, 3]], dtype=pl.Array(pl.Int64, 2))
86
+ >>> s.arr.std()
87
+ shape: (2,)
88
+ Series: 'a' [f64]
89
+ [
90
+ 0.707107
91
+ 0.707107
92
+ ]
93
+ """
94
+
95
+ def var(self, ddof: int = 1) -> Series:
96
+ """
97
+ Compute the var of the values of the sub-arrays.
98
+
99
+ Examples
100
+ --------
101
+ >>> s = pl.Series("a", [[1, 2], [4, 3]], dtype=pl.Array(pl.Int64, 2))
102
+ >>> s.arr.var()
103
+ shape: (2,)
104
+ Series: 'a' [f64]
105
+ [
106
+ 0.5
107
+ 0.5
108
+ ]
109
+ """
110
+
111
+ def median(self) -> Series:
112
+ """
113
+ Compute the median of the values of the sub-arrays.
114
+
115
+ Examples
116
+ --------
117
+ >>> s = pl.Series("a", [[1, 2], [4, 3]], dtype=pl.Array(pl.Int64, 2))
118
+ >>> s.arr.median()
119
+ shape: (2,)
120
+ Series: 'a' [f64]
121
+ [
122
+ 1.5
123
+ 3.5
124
+ ]
125
+ """
126
+
127
+ def unique(self, *, maintain_order: bool = False) -> Series:
128
+ """
129
+ Get the unique/distinct values in the array.
130
+
131
+ Parameters
132
+ ----------
133
+ maintain_order
134
+ Maintain order of data. This requires more work.
135
+
136
+ Returns
137
+ -------
138
+ Series
139
+ Series of data type :class:`List`.
140
+
141
+ Examples
142
+ --------
143
+ >>> s = pl.Series([[1, 1, 2], [3, 4, 5]], dtype=pl.Array(pl.Int64, 3))
144
+ >>> s.arr.unique()
145
+ shape: (2,)
146
+ Series: '' [list[i64]]
147
+ [
148
+ [1, 2]
149
+ [3, 4, 5]
150
+ ]
151
+ """
152
+
153
+ def n_unique(self) -> Series:
154
+ """
155
+ Count the number of unique values in every sub-arrays.
156
+
157
+ Examples
158
+ --------
159
+ >>> s = pl.Series("a", [[1, 2], [4, 4]], dtype=pl.Array(pl.Int64, 2))
160
+ >>> s.arr.n_unique()
161
+ shape: (2,)
162
+ Series: 'a' [u32]
163
+ [
164
+ 2
165
+ 1
166
+ ]
167
+ """
168
+
169
+ def to_list(self) -> Series:
170
+ """
171
+ Convert an Array column into a List column with the same inner data type.
172
+
173
+ Returns
174
+ -------
175
+ Series
176
+ Series of data type :class:`List`.
177
+
178
+ Examples
179
+ --------
180
+ >>> s = pl.Series([[1, 2], [3, 4]], dtype=pl.Array(pl.Int8, 2))
181
+ >>> s.arr.to_list()
182
+ shape: (2,)
183
+ Series: '' [list[i8]]
184
+ [
185
+ [1, 2]
186
+ [3, 4]
187
+ ]
188
+ """
189
+
190
+ def any(self) -> Series:
191
+ """
192
+ Evaluate whether any boolean value is true for every subarray.
193
+
194
+ Returns
195
+ -------
196
+ Series
197
+ Series of data type :class:`Boolean`.
198
+
199
+ Notes
200
+ -----
201
+ If there are no non-null elements in a row, the output is `False`.
202
+
203
+ Examples
204
+ --------
205
+ >>> s = pl.Series(
206
+ ... [[True, True], [False, True], [False, False], [None, None], None],
207
+ ... dtype=pl.Array(pl.Boolean, 2),
208
+ ... )
209
+ >>> s.arr.any()
210
+ shape: (5,)
211
+ Series: '' [bool]
212
+ [
213
+ true
214
+ true
215
+ false
216
+ false
217
+ null
218
+ ]
219
+ """
220
+
221
+ def len(self) -> Series:
222
+ """
223
+ Return the number of elements in each array.
224
+
225
+ Returns
226
+ -------
227
+ Series
228
+ Series of data type :class:`UInt32`.
229
+
230
+ Examples
231
+ --------
232
+ >>> s = pl.Series("a", [[1, 2], [4, 3]], dtype=pl.Array(pl.Int64, 2))
233
+ >>> s.arr.len()
234
+ shape: (2,)
235
+ Series: 'a' [u32]
236
+ [
237
+ 2
238
+ 2
239
+ ]
240
+ """
241
+
242
+ def slice(
243
+ self,
244
+ offset: int | Expr,
245
+ length: int | Expr | None = None,
246
+ *,
247
+ as_array: bool = False,
248
+ ) -> Series:
249
+ """
250
+ Slice the sub-arrays.
251
+
252
+ Parameters
253
+ ----------
254
+ offset
255
+ The starting index of the slice.
256
+ length
257
+ The length of the slice.
258
+
259
+ Returns
260
+ -------
261
+ Series
262
+ Series of data type :class:`Array`.
263
+
264
+ Examples
265
+ --------
266
+ >>> s = pl.Series(
267
+ ... [[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12]],
268
+ ... dtype=pl.Array(pl.Int64, 6),
269
+ ... )
270
+ >>> s.arr.slice(1)
271
+ shape: (2,)
272
+ Series: '' [list[i64]]
273
+ [
274
+ [2, 3, … 6]
275
+ [8, 9, … 12]
276
+ ]
277
+ >>> s.arr.slice(1, 3, as_array=True)
278
+ shape: (2,)
279
+ Series: '' [array[i64, 3]]
280
+ [
281
+ [2, 3, 4]
282
+ [8, 9, 10]
283
+ ]
284
+ >>> s.arr.slice(-2)
285
+ shape: (2,)
286
+ Series: '' [list[i64]]
287
+ [
288
+ [5, 6]
289
+ [11, 12]
290
+ ]
291
+ """
292
+
293
+ def head(self, n: int | Expr = 5, *, as_array: bool = False) -> Series:
294
+ """
295
+ Get the first `n` elements of the sub-arrays.
296
+
297
+ Parameters
298
+ ----------
299
+ n
300
+ Number of values to return for each sublist.
301
+ as_array
302
+ Return result as a fixed-length `Array`, otherwise as a `List`.
303
+ If true `n` must be a constant value.
304
+
305
+ Examples
306
+ --------
307
+ >>> s = pl.Series(
308
+ ... [[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12]],
309
+ ... dtype=pl.Array(pl.Int64, 6),
310
+ ... )
311
+ >>> s.arr.head()
312
+ shape: (2,)
313
+ Series: '' [list[i64]]
314
+ [
315
+ [1, 2, … 5]
316
+ [7, 8, … 11]
317
+ ]
318
+ >>> s.arr.head(3, as_array=True)
319
+ shape: (2,)
320
+ Series: '' [array[i64, 3]]
321
+ [
322
+ [1, 2, 3]
323
+ [7, 8, 9]
324
+ ]
325
+ """
326
+
327
+ def tail(self, n: int | Expr = 5, *, as_array: bool = False) -> Series:
328
+ """
329
+ Slice the last `n` values of every sublist.
330
+
331
+ Parameters
332
+ ----------
333
+ n
334
+ Number of values to return for each sublist.
335
+ as_array
336
+ Return result as a fixed-length `Array`, otherwise as a `List`.
337
+ If true `n` must be a constant value.
338
+
339
+ Examples
340
+ --------
341
+ >>> s = pl.Series(
342
+ ... [[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12]],
343
+ ... dtype=pl.Array(pl.Int64, 6),
344
+ ... )
345
+ >>> s.arr.tail()
346
+ shape: (2,)
347
+ Series: '' [list[i64]]
348
+ [
349
+ [2, 3, … 6]
350
+ [8, 9, … 12]
351
+ ]
352
+ >>> s.arr.tail(3, as_array=True)
353
+ shape: (2,)
354
+ Series: '' [array[i64, 3]]
355
+ [
356
+ [4, 5, 6]
357
+ [10, 11, 12]
358
+ ]
359
+ """
360
+
361
+ def all(self) -> Series:
362
+ """
363
+ Evaluate whether all boolean values are true for every subarray.
364
+
365
+ Returns
366
+ -------
367
+ Series
368
+ Series of data type :class:`Boolean`.
369
+
370
+ Notes
371
+ -----
372
+ If there are no non-null elements in a row, the output is `True`.
373
+
374
+ Examples
375
+ --------
376
+ >>> s = pl.Series(
377
+ ... [[True, True], [False, True], [False, False], [None, None], None],
378
+ ... dtype=pl.Array(pl.Boolean, 2),
379
+ ... )
380
+ >>> s.arr.all()
381
+ shape: (5,)
382
+ Series: '' [bool]
383
+ [
384
+ true
385
+ false
386
+ false
387
+ true
388
+ null
389
+ ]
390
+ """
391
+
392
+ def sort(
393
+ self,
394
+ *,
395
+ descending: bool = False,
396
+ nulls_last: bool = False,
397
+ multithreaded: bool = True,
398
+ ) -> Series:
399
+ """
400
+ Sort the arrays in this column.
401
+
402
+ Parameters
403
+ ----------
404
+ descending
405
+ Sort in descending order.
406
+ nulls_last
407
+ Place null values last.
408
+ multithreaded
409
+ Sort using multiple threads.
410
+
411
+ Examples
412
+ --------
413
+ >>> s = pl.Series("a", [[3, 2, 1], [9, 1, 2]], dtype=pl.Array(pl.Int64, 3))
414
+ >>> s.arr.sort()
415
+ shape: (2,)
416
+ Series: 'a' [array[i64, 3]]
417
+ [
418
+ [1, 2, 3]
419
+ [1, 2, 9]
420
+ ]
421
+ >>> s.arr.sort(descending=True)
422
+ shape: (2,)
423
+ Series: 'a' [array[i64, 3]]
424
+ [
425
+ [3, 2, 1]
426
+ [9, 2, 1]
427
+ ]
428
+
429
+ """
430
+
431
+ def reverse(self) -> Series:
432
+ """
433
+ Reverse the arrays in this column.
434
+
435
+ Examples
436
+ --------
437
+ >>> s = pl.Series("a", [[3, 2, 1], [9, 1, 2]], dtype=pl.Array(pl.Int64, 3))
438
+ >>> s.arr.reverse()
439
+ shape: (2,)
440
+ Series: 'a' [array[i64, 3]]
441
+ [
442
+ [1, 2, 3]
443
+ [2, 1, 9]
444
+ ]
445
+
446
+ """
447
+
448
+ def arg_min(self) -> Series:
449
+ """
450
+ Retrieve the index of the minimal value in every sub-array.
451
+
452
+ Returns
453
+ -------
454
+ Series
455
+ Series of data type :class:`UInt32` or :class:`UInt64`
456
+ (depending on compilation).
457
+
458
+ Examples
459
+ --------
460
+ >>> s = pl.Series("a", [[3, 2, 1], [9, 1, 2]], dtype=pl.Array(pl.Int64, 3))
461
+ >>> s.arr.arg_min()
462
+ shape: (2,)
463
+ Series: 'a' [u32]
464
+ [
465
+ 2
466
+ 1
467
+ ]
468
+
469
+ """
470
+
471
+ def arg_max(self) -> Series:
472
+ """
473
+ Retrieve the index of the maximum value in every sub-array.
474
+
475
+ Returns
476
+ -------
477
+ Series
478
+ Series of data type :class:`UInt32` or :class:`UInt64`
479
+ (depending on compilation).
480
+
481
+ Examples
482
+ --------
483
+ >>> s = pl.Series("a", [[0, 9, 3], [9, 1, 2]], dtype=pl.Array(pl.Int64, 3))
484
+ >>> s.arr.arg_max()
485
+ shape: (2,)
486
+ Series: 'a' [u32]
487
+ [
488
+ 1
489
+ 0
490
+ ]
491
+
492
+ """
493
+
494
+ def get(self, index: int | IntoExprColumn, *, null_on_oob: bool = False) -> Series:
495
+ """
496
+ Get the value by index in the sub-arrays.
497
+
498
+ So index `0` would return the first item of every sublist
499
+ and index `-1` would return the last item of every sublist
500
+ if an index is out of bounds, it will return a `None`.
501
+
502
+ Parameters
503
+ ----------
504
+ index
505
+ Index to return per sublist
506
+ null_on_oob
507
+ Behavior if an index is out of bounds:
508
+ True -> set as null
509
+ False -> raise an error
510
+
511
+ Returns
512
+ -------
513
+ Series
514
+ Series of innter data type.
515
+
516
+ Examples
517
+ --------
518
+ >>> s = pl.Series(
519
+ ... "a", [[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=pl.Array(pl.Int32, 3)
520
+ ... )
521
+ >>> s.arr.get(pl.Series([1, -2, 0]), null_on_oob=True)
522
+ shape: (3,)
523
+ Series: 'a' [i32]
524
+ [
525
+ 2
526
+ 5
527
+ 7
528
+ ]
529
+
530
+ """
531
+
532
+ def first(self) -> Series:
533
+ """
534
+ Get the first value of the sub-arrays.
535
+
536
+ Examples
537
+ --------
538
+ >>> s = pl.Series(
539
+ ... "a", [[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=pl.Array(pl.Int32, 3)
540
+ ... )
541
+ >>> s.arr.first()
542
+ shape: (3,)
543
+ Series: 'a' [i32]
544
+ [
545
+ 1
546
+ 4
547
+ 7
548
+ ]
549
+
550
+ """
551
+
552
+ def last(self) -> Series:
553
+ """
554
+ Get the last value of the sub-arrays.
555
+
556
+ Examples
557
+ --------
558
+ >>> s = pl.Series(
559
+ ... "a", [[1, 2, 3], [4, 5, 6], [7, 9, 8]], dtype=pl.Array(pl.Int32, 3)
560
+ ... )
561
+ >>> s.arr.last()
562
+ shape: (3,)
563
+ Series: 'a' [i32]
564
+ [
565
+ 3
566
+ 6
567
+ 8
568
+ ]
569
+
570
+ """
571
+
572
+ def join(self, separator: IntoExprColumn, *, ignore_nulls: bool = True) -> Series:
573
+ """
574
+ Join all string items in a sub-array and place a separator between them.
575
+
576
+ This errors if inner type of array `!= String`.
577
+
578
+ Parameters
579
+ ----------
580
+ separator
581
+ string to separate the items with
582
+ ignore_nulls
583
+ Ignore null values (default).
584
+
585
+ If set to ``False``, null values will be propagated.
586
+ If the sub-list contains any null values, the output is ``None``.
587
+
588
+ Returns
589
+ -------
590
+ Series
591
+ Series of data type :class:`String`.
592
+
593
+ Examples
594
+ --------
595
+ >>> s = pl.Series([["x", "y"], ["a", "b"]], dtype=pl.Array(pl.String, 2))
596
+ >>> s.arr.join(separator="-")
597
+ shape: (2,)
598
+ Series: '' [str]
599
+ [
600
+ "x-y"
601
+ "a-b"
602
+ ]
603
+
604
+ """
605
+
606
+ def explode(self) -> Series:
607
+ """
608
+ Returns a column with a separate row for every array element.
609
+
610
+ Returns
611
+ -------
612
+ Series
613
+ Series with the data type of the array elements.
614
+
615
+ Examples
616
+ --------
617
+ >>> s = pl.Series("a", [[1, 2, 3], [4, 5, 6]], dtype=pl.Array(pl.Int64, 3))
618
+ >>> s.arr.explode()
619
+ shape: (6,)
620
+ Series: 'a' [i64]
621
+ [
622
+ 1
623
+ 2
624
+ 3
625
+ 4
626
+ 5
627
+ 6
628
+ ]
629
+ """
630
+
631
+ def contains(self, item: IntoExpr, *, nulls_equal: bool = True) -> Series:
632
+ """
633
+ Check if sub-arrays contain the given item.
634
+
635
+ Parameters
636
+ ----------
637
+ item
638
+ Item that will be checked for membership
639
+ nulls_equal : bool, default True
640
+ If True, treat null as a distinct value. Null values will not propagate.
641
+
642
+ Returns
643
+ -------
644
+ Series
645
+ Series of data type :class:`Boolean`.
646
+
647
+ Examples
648
+ --------
649
+ >>> s = pl.Series(
650
+ ... "a", [[3, 2, 1], [1, 2, 3], [4, 5, 6]], dtype=pl.Array(pl.Int32, 3)
651
+ ... )
652
+ >>> s.arr.contains(1)
653
+ shape: (3,)
654
+ Series: 'a' [bool]
655
+ [
656
+ true
657
+ true
658
+ false
659
+ ]
660
+
661
+ """
662
+
663
+ def count_matches(self, element: IntoExpr) -> Series:
664
+ """
665
+ Count how often the value produced by `element` occurs.
666
+
667
+ Parameters
668
+ ----------
669
+ element
670
+ An expression that produces a single value
671
+
672
+ Examples
673
+ --------
674
+ >>> s = pl.Series("a", [[1, 2, 3], [2, 2, 2]], dtype=pl.Array(pl.Int64, 3))
675
+ >>> s.arr.count_matches(2)
676
+ shape: (2,)
677
+ Series: 'a' [u32]
678
+ [
679
+ 1
680
+ 3
681
+ ]
682
+
683
+ """
684
+
685
+ def to_struct(
686
+ self,
687
+ fields: Callable[[int], str] | Sequence[str] | None = None,
688
+ ) -> Series:
689
+ """
690
+ Convert the series of type `Array` to a series of type `Struct`.
691
+
692
+ Parameters
693
+ ----------
694
+ fields
695
+ If the name and number of the desired fields is known in advance
696
+ a list of field names can be given, which will be assigned by index.
697
+ Otherwise, to dynamically assign field names, a custom function can be
698
+ used; if neither are set, fields will be `field_0, field_1 .. field_n`.
699
+
700
+ Examples
701
+ --------
702
+ Convert array to struct with default field name assignment:
703
+
704
+ >>> s1 = pl.Series("n", [[0, 1, 2], [3, 4, 5]], dtype=pl.Array(pl.Int8, 3))
705
+ >>> s2 = s1.arr.to_struct()
706
+ >>> s2
707
+ shape: (2,)
708
+ Series: 'n' [struct[3]]
709
+ [
710
+ {0,1,2}
711
+ {3,4,5}
712
+ ]
713
+ >>> s2.struct.fields
714
+ ['field_0', 'field_1', 'field_2']
715
+
716
+ Convert array to struct with field name assignment by function/index:
717
+
718
+ >>> s3 = s1.arr.to_struct(fields=lambda idx: f"n{idx:02}")
719
+ >>> s3.struct.fields
720
+ ['n00', 'n01', 'n02']
721
+
722
+ Convert array to struct with field name assignment by
723
+ index from a list of names:
724
+
725
+ >>> s1.arr.to_struct(fields=["one", "two", "three"]).struct.unnest()
726
+ shape: (2, 3)
727
+ ┌─────┬─────┬───────┐
728
+ │ one ┆ two ┆ three │
729
+ │ --- ┆ --- ┆ --- │
730
+ │ i8 ┆ i8 ┆ i8 │
731
+ ╞═════╪═════╪═══════╡
732
+ │ 0 ┆ 1 ┆ 2 │
733
+ │ 3 ┆ 4 ┆ 5 │
734
+ └─────┴─────┴───────┘
735
+ """
736
+ s = wrap_s(self._s)
737
+ return s.to_frame().select(F.col(s.name).arr.to_struct(fields)).to_series()
738
+
739
+ def shift(self, n: int | IntoExprColumn = 1) -> Series:
740
+ """
741
+ Shift array values by the given number of indices.
742
+
743
+ Parameters
744
+ ----------
745
+ n
746
+ Number of indices to shift forward. If a negative value is passed, values
747
+ are shifted in the opposite direction instead.
748
+
749
+ Notes
750
+ -----
751
+ This method is similar to the `LAG` operation in SQL when the value for `n`
752
+ is positive. With a negative value for `n`, it is similar to `LEAD`.
753
+
754
+ Examples
755
+ --------
756
+ By default, array values are shifted forward by one index.
757
+
758
+ >>> s = pl.Series([[1, 2, 3], [4, 5, 6]], dtype=pl.Array(pl.Int64, 3))
759
+ >>> s.arr.shift()
760
+ shape: (2,)
761
+ Series: '' [array[i64, 3]]
762
+ [
763
+ [null, 1, 2]
764
+ [null, 4, 5]
765
+ ]
766
+
767
+ Pass a negative value to shift in the opposite direction instead.
768
+
769
+ >>> s.arr.shift(-2)
770
+ shape: (2,)
771
+ Series: '' [array[i64, 3]]
772
+ [
773
+ [3, null, null]
774
+ [6, null, null]
775
+ ]
776
+ """