polars-runtime-compat 1.34.0b2__cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.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/list.py ADDED
@@ -0,0 +1,1087 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Sequence
4
+ from typing import TYPE_CHECKING, Any, Callable
5
+
6
+ from polars import functions as F
7
+ from polars._utils.wrap import wrap_s
8
+ from polars.series.utils import expr_dispatch
9
+
10
+ if TYPE_CHECKING:
11
+ from collections.abc import Collection
12
+
13
+ from polars import Expr, Series
14
+ from polars._plr import PySeries
15
+ from polars._typing import (
16
+ IntoExpr,
17
+ IntoExprColumn,
18
+ ListToStructWidthStrategy,
19
+ NullBehavior,
20
+ )
21
+
22
+
23
+ @expr_dispatch
24
+ class ListNameSpace:
25
+ """Namespace for list related methods."""
26
+
27
+ _accessor = "list"
28
+
29
+ def __init__(self, series: Series) -> None:
30
+ self._s: PySeries = series._s
31
+
32
+ def all(self) -> Series:
33
+ """
34
+ Evaluate whether all boolean values in a list are true.
35
+
36
+ Returns
37
+ -------
38
+ Series
39
+ Series of data type :class:`Boolean`.
40
+
41
+ Notes
42
+ -----
43
+ If there are no non-null elements in a row, the output is `True`.
44
+
45
+ Examples
46
+ --------
47
+ >>> s = pl.Series(
48
+ ... [[True, True], [False, True], [False, False], [None], [], None],
49
+ ... dtype=pl.List(pl.Boolean),
50
+ ... )
51
+ >>> s.list.all()
52
+ shape: (6,)
53
+ Series: '' [bool]
54
+ [
55
+ true
56
+ false
57
+ false
58
+ true
59
+ true
60
+ null
61
+ ]
62
+ """
63
+
64
+ def any(self) -> Series:
65
+ """
66
+ Evaluate whether any boolean value in a list is true.
67
+
68
+ Returns
69
+ -------
70
+ Series
71
+ Series of data type :class:`Boolean`.
72
+
73
+ Notes
74
+ -----
75
+ If there are no non-null elements in a row, the output is `False`.
76
+
77
+ Examples
78
+ --------
79
+ >>> s = pl.Series(
80
+ ... [[True, True], [False, True], [False, False], [None], [], None],
81
+ ... dtype=pl.List(pl.Boolean),
82
+ ... )
83
+ >>> s.list.any()
84
+ shape: (6,)
85
+ Series: '' [bool]
86
+ [
87
+ true
88
+ true
89
+ false
90
+ false
91
+ false
92
+ null
93
+ ]
94
+ """
95
+
96
+ def len(self) -> Series:
97
+ """
98
+ Return the number of elements in each list.
99
+
100
+ Null values count towards the total.
101
+
102
+ Returns
103
+ -------
104
+ Series
105
+ Series of data type :class:`UInt32`.
106
+
107
+ Examples
108
+ --------
109
+ >>> s = pl.Series([[1, 2, None], [5]])
110
+ >>> s.list.len()
111
+ shape: (2,)
112
+ Series: '' [u32]
113
+ [
114
+ 3
115
+ 1
116
+ ]
117
+ """
118
+
119
+ def drop_nulls(self) -> Series:
120
+ """
121
+ Drop all null values in the list.
122
+
123
+ The original order of the remaining elements is preserved.
124
+
125
+ Examples
126
+ --------
127
+ >>> s = pl.Series("values", [[None, 1, None, 2], [None], [3, 4]])
128
+ >>> s.list.drop_nulls()
129
+ shape: (3,)
130
+ Series: 'values' [list[i64]]
131
+ [
132
+ [1, 2]
133
+ []
134
+ [3, 4]
135
+ ]
136
+ """
137
+
138
+ def sample(
139
+ self,
140
+ n: int | IntoExprColumn | None = None,
141
+ *,
142
+ fraction: float | IntoExprColumn | None = None,
143
+ with_replacement: bool = False,
144
+ shuffle: bool = False,
145
+ seed: int | None = None,
146
+ ) -> Series:
147
+ """
148
+ Sample from this list.
149
+
150
+ Parameters
151
+ ----------
152
+ n
153
+ Number of items to return. Cannot be used with `fraction`. Defaults to 1 if
154
+ `fraction` is None.
155
+ fraction
156
+ Fraction of items to return. Cannot be used with `n`.
157
+ with_replacement
158
+ Allow values to be sampled more than once.
159
+ shuffle
160
+ Shuffle the order of sampled data points.
161
+ seed
162
+ Seed for the random number generator. If set to None (default), a
163
+ random seed is generated for each sample operation.
164
+
165
+ Examples
166
+ --------
167
+ >>> s = pl.Series("values", [[1, 2, 3], [4, 5]])
168
+ >>> s.list.sample(n=pl.Series("n", [2, 1]), seed=1)
169
+ shape: (2,)
170
+ Series: 'values' [list[i64]]
171
+ [
172
+ [2, 3]
173
+ [5]
174
+ ]
175
+ """
176
+
177
+ def sum(self) -> Series:
178
+ """
179
+ Sum all the arrays in the list.
180
+
181
+ Notes
182
+ -----
183
+ If there are no non-null elements in a row, the output is `0`.
184
+
185
+ Examples
186
+ --------
187
+ >>> s = pl.Series("values", [[1], [2, 3]])
188
+ >>> s.list.sum()
189
+ shape: (2,)
190
+ Series: 'values' [i64]
191
+ [
192
+ 1
193
+ 5
194
+ ]
195
+ """
196
+
197
+ def max(self) -> Series:
198
+ """
199
+ Compute the max value of the arrays in the list.
200
+
201
+ Examples
202
+ --------
203
+ >>> s = pl.Series("values", [[4, 1], [2, 3]])
204
+ >>> s.list.max()
205
+ shape: (2,)
206
+ Series: 'values' [i64]
207
+ [
208
+ 4
209
+ 3
210
+ ]
211
+ """
212
+
213
+ def min(self) -> Series:
214
+ """
215
+ Compute the min value of the arrays in the list.
216
+
217
+ Examples
218
+ --------
219
+ >>> s = pl.Series("values", [[4, 1], [2, 3]])
220
+ >>> s.list.min()
221
+ shape: (2,)
222
+ Series: 'values' [i64]
223
+ [
224
+ 1
225
+ 2
226
+ ]
227
+ """
228
+
229
+ def mean(self) -> Series:
230
+ """
231
+ Compute the mean value of the arrays in the list.
232
+
233
+ Examples
234
+ --------
235
+ >>> s = pl.Series("values", [[3, 1], [3, 3]])
236
+ >>> s.list.mean()
237
+ shape: (2,)
238
+ Series: 'values' [f64]
239
+ [
240
+ 2.0
241
+ 3.0
242
+ ]
243
+ """
244
+
245
+ def median(self) -> Series:
246
+ """
247
+ Compute the median value of the arrays in the list.
248
+
249
+ Examples
250
+ --------
251
+ >>> s = pl.Series("values", [[-1, 0, 1], [1, 10]])
252
+ >>> s.list.median()
253
+ shape: (2,)
254
+ Series: 'values' [f64]
255
+ [
256
+ 0.0
257
+ 5.5
258
+ ]
259
+ """
260
+
261
+ def std(self, ddof: int = 1) -> Series:
262
+ """
263
+ Compute the std value of the arrays in the list.
264
+
265
+ Examples
266
+ --------
267
+ >>> s = pl.Series("values", [[-1, 0, 1], [1, 10]])
268
+ >>> s.list.std()
269
+ shape: (2,)
270
+ Series: 'values' [f64]
271
+ [
272
+ 1.0
273
+ 6.363961
274
+ ]
275
+ """
276
+
277
+ def var(self, ddof: int = 1) -> Series:
278
+ """
279
+ Compute the var value of the arrays in the list.
280
+
281
+ Examples
282
+ --------
283
+ >>> s = pl.Series("values", [[-1, 0, 1], [1, 10]])
284
+ >>> s.list.var()
285
+ shape: (2,)
286
+ Series: 'values' [f64]
287
+ [
288
+ 1.0
289
+ 40.5
290
+ ]
291
+ """
292
+
293
+ def sort(
294
+ self,
295
+ *,
296
+ descending: bool = False,
297
+ nulls_last: bool = False,
298
+ multithreaded: bool = True,
299
+ ) -> Series:
300
+ """
301
+ Sort the arrays in this column.
302
+
303
+ Parameters
304
+ ----------
305
+ descending
306
+ Sort in descending order.
307
+ nulls_last
308
+ Place null values last.
309
+ multithreaded
310
+ Sort using multiple threads.
311
+
312
+ Examples
313
+ --------
314
+ >>> s = pl.Series("a", [[3, 2, 1], [9, 1, 2]])
315
+ >>> s.list.sort()
316
+ shape: (2,)
317
+ Series: 'a' [list[i64]]
318
+ [
319
+ [1, 2, 3]
320
+ [1, 2, 9]
321
+ ]
322
+ >>> s.list.sort(descending=True)
323
+ shape: (2,)
324
+ Series: 'a' [list[i64]]
325
+ [
326
+ [3, 2, 1]
327
+ [9, 2, 1]
328
+ ]
329
+ """
330
+
331
+ def reverse(self) -> Series:
332
+ """
333
+ Reverse the arrays in the list.
334
+
335
+ Examples
336
+ --------
337
+ >>> s = pl.Series("a", [[3, 2, 1], [9, 1, 2]])
338
+ >>> s.list.reverse()
339
+ shape: (2,)
340
+ Series: 'a' [list[i64]]
341
+ [
342
+ [1, 2, 3]
343
+ [2, 1, 9]
344
+ ]
345
+ """
346
+
347
+ def unique(self, *, maintain_order: bool = False) -> Series:
348
+ """
349
+ Get the unique/distinct values in the list.
350
+
351
+ Parameters
352
+ ----------
353
+ maintain_order
354
+ Maintain order of data. This requires more work.
355
+
356
+ Examples
357
+ --------
358
+ >>> s = pl.Series("a", [[1, 1, 2], [2, 3, 3]])
359
+ >>> s.list.unique()
360
+ shape: (2,)
361
+ Series: 'a' [list[i64]]
362
+ [
363
+ [1, 2]
364
+ [2, 3]
365
+ ]
366
+ """
367
+
368
+ def n_unique(self) -> Series:
369
+ """
370
+ Count the number of unique values in every sub-lists.
371
+
372
+ Examples
373
+ --------
374
+ >>> s = pl.Series("a", [[1, 1, 2], [2, 3, 4]])
375
+ >>> s.list.n_unique()
376
+ shape: (2,)
377
+ Series: 'a' [u32]
378
+ [
379
+ 2
380
+ 3
381
+ ]
382
+ """
383
+
384
+ def concat(self, other: list[Series] | Series | list[Any]) -> Series:
385
+ """
386
+ Concat the arrays in a Series dtype List in linear time.
387
+
388
+ Parameters
389
+ ----------
390
+ other
391
+ Columns to concat into a List Series
392
+
393
+ Examples
394
+ --------
395
+ >>> s1 = pl.Series("a", [["a", "b"], ["c"]])
396
+ >>> s2 = pl.Series("b", [["c"], ["d", None]])
397
+ >>> s1.list.concat(s2)
398
+ shape: (2,)
399
+ Series: 'a' [list[str]]
400
+ [
401
+ ["a", "b", "c"]
402
+ ["c", "d", null]
403
+ ]
404
+ """
405
+
406
+ def get(
407
+ self,
408
+ index: int | Series | list[int],
409
+ *,
410
+ null_on_oob: bool = False,
411
+ ) -> Series:
412
+ """
413
+ Get the value by index in the sublists.
414
+
415
+ So index `0` would return the first item of every sublist
416
+ and index `-1` would return the last item of every sublist
417
+ if an index is out of bounds, it will return a `None`.
418
+
419
+ Parameters
420
+ ----------
421
+ index
422
+ Index to return per sublist
423
+ null_on_oob
424
+ Behavior if an index is out of bounds:
425
+
426
+ * True -> set as null
427
+ * False -> raise an error
428
+
429
+ Examples
430
+ --------
431
+ >>> s = pl.Series("a", [[3, 2, 1], [], [1, 2]])
432
+ >>> s.list.get(0, null_on_oob=True)
433
+ shape: (3,)
434
+ Series: 'a' [i64]
435
+ [
436
+ 3
437
+ null
438
+ 1
439
+ ]
440
+ """
441
+
442
+ def gather(
443
+ self,
444
+ indices: Series | list[int] | list[list[int]],
445
+ *,
446
+ null_on_oob: bool = False,
447
+ ) -> Series:
448
+ """
449
+ Take sublists by multiple indices.
450
+
451
+ The indices may be defined in a single column, or by sublists in another
452
+ column of dtype `List`.
453
+
454
+ Parameters
455
+ ----------
456
+ indices
457
+ Indices to return per sublist
458
+ null_on_oob
459
+ Behavior if an index is out of bounds:
460
+ True -> set as null
461
+ False -> raise an error
462
+ Note that defaulting to raising an error is much cheaper
463
+
464
+ Examples
465
+ --------
466
+ >>> s = pl.Series("a", [[3, 2, 1], [], [1, 2]])
467
+ >>> s.list.gather([0, 2], null_on_oob=True)
468
+ shape: (3,)
469
+ Series: 'a' [list[i64]]
470
+ [
471
+ [3, 1]
472
+ [null, null]
473
+ [1, null]
474
+ ]
475
+ """
476
+
477
+ def gather_every(
478
+ self, n: int | IntoExprColumn, offset: int | IntoExprColumn = 0
479
+ ) -> Series:
480
+ """
481
+ Take every n-th value start from offset in sublists.
482
+
483
+ Parameters
484
+ ----------
485
+ n
486
+ Gather every n-th element.
487
+ offset
488
+ Starting index.
489
+
490
+ Examples
491
+ --------
492
+ >>> s = pl.Series("a", [[1, 2, 3], [], [6, 7, 8, 9]])
493
+ >>> s.list.gather_every(2, offset=1)
494
+ shape: (3,)
495
+ Series: 'a' [list[i64]]
496
+ [
497
+ [2]
498
+ []
499
+ [7, 9]
500
+ ]
501
+ """
502
+
503
+ def __getitem__(self, item: int) -> Series:
504
+ return self.get(item)
505
+
506
+ def join(self, separator: IntoExprColumn, *, ignore_nulls: bool = True) -> Series:
507
+ """
508
+ Join all string items in a sublist and place a separator between them.
509
+
510
+ This errors if inner type of list `!= String`.
511
+
512
+ Parameters
513
+ ----------
514
+ separator
515
+ string to separate the items with
516
+ ignore_nulls
517
+ Ignore null values (default).
518
+
519
+ If set to ``False``, null values will be propagated.
520
+ If the sub-list contains any null values, the output is ``None``.
521
+
522
+ Returns
523
+ -------
524
+ Series
525
+ Series of data type :class:`String`.
526
+
527
+ Examples
528
+ --------
529
+ >>> s = pl.Series([["foo", "bar"], ["hello", "world"]])
530
+ >>> s.list.join(separator="-")
531
+ shape: (2,)
532
+ Series: '' [str]
533
+ [
534
+ "foo-bar"
535
+ "hello-world"
536
+ ]
537
+ """
538
+
539
+ def first(self) -> Series:
540
+ """
541
+ Get the first value of the sublists.
542
+
543
+ Examples
544
+ --------
545
+ >>> s = pl.Series("a", [[3, 2, 1], [], [1, 2]])
546
+ >>> s.list.first()
547
+ shape: (3,)
548
+ Series: 'a' [i64]
549
+ [
550
+ 3
551
+ null
552
+ 1
553
+ ]
554
+ """
555
+
556
+ def last(self) -> Series:
557
+ """
558
+ Get the last value of the sublists.
559
+
560
+ Examples
561
+ --------
562
+ >>> s = pl.Series("a", [[3, 2, 1], [], [1, 2]])
563
+ >>> s.list.last()
564
+ shape: (3,)
565
+ Series: 'a' [i64]
566
+ [
567
+ 1
568
+ null
569
+ 2
570
+ ]
571
+ """
572
+
573
+ def contains(self, item: IntoExpr, *, nulls_equal: bool = True) -> Series:
574
+ """
575
+ Check if sublists contain the given item.
576
+
577
+ Parameters
578
+ ----------
579
+ item
580
+ Item that will be checked for membership
581
+ nulls_equal : bool, default True
582
+ If True, treat null as a distinct value. Null values will not propagate.
583
+
584
+ Returns
585
+ -------
586
+ Series
587
+ Series of data type :class:`Boolean`.
588
+
589
+ Examples
590
+ --------
591
+ >>> s = pl.Series("a", [[3, 2, 1], [], [1, 2]])
592
+ >>> s.list.contains(1)
593
+ shape: (3,)
594
+ Series: 'a' [bool]
595
+ [
596
+ true
597
+ false
598
+ true
599
+ ]
600
+ """
601
+
602
+ def arg_min(self) -> Series:
603
+ """
604
+ Retrieve the index of the minimal value in every sublist.
605
+
606
+ Returns
607
+ -------
608
+ Series
609
+ Series of data type :class:`UInt32` or :class:`UInt64`
610
+ (depending on compilation).
611
+
612
+ Examples
613
+ --------
614
+ >>> s = pl.Series("a", [[1, 2], [2, 1]])
615
+ >>> s.list.arg_min()
616
+ shape: (2,)
617
+ Series: 'a' [u32]
618
+ [
619
+ 0
620
+ 1
621
+ ]
622
+ """
623
+
624
+ def arg_max(self) -> Series:
625
+ """
626
+ Retrieve the index of the maximum value in every sublist.
627
+
628
+ Returns
629
+ -------
630
+ Series
631
+ Series of data type :class:`UInt32` or :class:`UInt64`
632
+ (depending on compilation).
633
+
634
+ Examples
635
+ --------
636
+ >>> s = pl.Series("a", [[1, 2], [2, 1]])
637
+ >>> s.list.arg_max()
638
+ shape: (2,)
639
+ Series: 'a' [u32]
640
+ [
641
+ 1
642
+ 0
643
+ ]
644
+ """
645
+
646
+ def diff(self, n: int = 1, null_behavior: NullBehavior = "ignore") -> Series:
647
+ """
648
+ Calculate the first discrete difference between shifted items of every sublist.
649
+
650
+ Parameters
651
+ ----------
652
+ n
653
+ Number of slots to shift.
654
+ null_behavior : {'ignore', 'drop'}
655
+ How to handle null values.
656
+
657
+ Examples
658
+ --------
659
+ >>> s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]])
660
+ >>> s.list.diff()
661
+ shape: (2,)
662
+ Series: 'a' [list[i64]]
663
+ [
664
+ [null, 1, … 1]
665
+ [null, -8, -1]
666
+ ]
667
+
668
+ >>> s.list.diff(n=2)
669
+ shape: (2,)
670
+ Series: 'a' [list[i64]]
671
+ [
672
+ [null, null, … 2]
673
+ [null, null, -9]
674
+ ]
675
+
676
+ >>> s.list.diff(n=2, null_behavior="drop")
677
+ shape: (2,)
678
+ Series: 'a' [list[i64]]
679
+ [
680
+ [2, 2]
681
+ [-9]
682
+ ]
683
+ """
684
+
685
+ def shift(self, n: int | IntoExprColumn = 1) -> Series:
686
+ """
687
+ Shift list values by the given number of indices.
688
+
689
+ Parameters
690
+ ----------
691
+ n
692
+ Number of indices to shift forward. If a negative value is passed, values
693
+ are shifted in the opposite direction instead.
694
+
695
+ Notes
696
+ -----
697
+ This method is similar to the `LAG` operation in SQL when the value for `n`
698
+ is positive. With a negative value for `n`, it is similar to `LEAD`.
699
+
700
+ Examples
701
+ --------
702
+ By default, list values are shifted forward by one index.
703
+
704
+ >>> s = pl.Series([[1, 2, 3], [4, 5]])
705
+ >>> s.list.shift()
706
+ shape: (2,)
707
+ Series: '' [list[i64]]
708
+ [
709
+ [null, 1, 2]
710
+ [null, 4]
711
+ ]
712
+
713
+ Pass a negative value to shift in the opposite direction instead.
714
+
715
+ >>> s.list.shift(-2)
716
+ shape: (2,)
717
+ Series: '' [list[i64]]
718
+ [
719
+ [3, null, null]
720
+ [null, null]
721
+ ]
722
+ """
723
+
724
+ def slice(self, offset: int | Expr, length: int | Expr | None = None) -> Series:
725
+ """
726
+ Slice every sublist.
727
+
728
+ Parameters
729
+ ----------
730
+ offset
731
+ Start index. Negative indexing is supported.
732
+ length
733
+ Length of the slice. If set to `None` (default), the slice is taken to the
734
+ end of the list.
735
+
736
+ Examples
737
+ --------
738
+ >>> s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]])
739
+ >>> s.list.slice(1, 2)
740
+ shape: (2,)
741
+ Series: 'a' [list[i64]]
742
+ [
743
+ [2, 3]
744
+ [2, 1]
745
+ ]
746
+ """
747
+
748
+ def head(self, n: int | Expr = 5) -> Series:
749
+ """
750
+ Slice the first `n` values of every sublist.
751
+
752
+ Parameters
753
+ ----------
754
+ n
755
+ Number of values to return for each sublist.
756
+
757
+ Examples
758
+ --------
759
+ >>> s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]])
760
+ >>> s.list.head(2)
761
+ shape: (2,)
762
+ Series: 'a' [list[i64]]
763
+ [
764
+ [1, 2]
765
+ [10, 2]
766
+ ]
767
+ """
768
+
769
+ def tail(self, n: int | Expr = 5) -> Series:
770
+ """
771
+ Slice the last `n` values of every sublist.
772
+
773
+ Parameters
774
+ ----------
775
+ n
776
+ Number of values to return for each sublist.
777
+
778
+ Examples
779
+ --------
780
+ >>> s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]])
781
+ >>> s.list.tail(2)
782
+ shape: (2,)
783
+ Series: 'a' [list[i64]]
784
+ [
785
+ [3, 4]
786
+ [2, 1]
787
+ ]
788
+ """
789
+
790
+ def explode(self) -> Series:
791
+ """
792
+ Returns a column with a separate row for every list element.
793
+
794
+ Returns
795
+ -------
796
+ Series
797
+ Series with the data type of the list elements.
798
+
799
+ See Also
800
+ --------
801
+ Series.reshape : Reshape this Series to a flat Series or a Series of Lists.
802
+
803
+ Examples
804
+ --------
805
+ >>> s = pl.Series("a", [[1, 2, 3], [4, 5, 6]])
806
+ >>> s.list.explode()
807
+ shape: (6,)
808
+ Series: 'a' [i64]
809
+ [
810
+ 1
811
+ 2
812
+ 3
813
+ 4
814
+ 5
815
+ 6
816
+ ]
817
+ """
818
+
819
+ def count_matches(self, element: IntoExpr) -> Series:
820
+ """
821
+ Count how often the value produced by `element` occurs.
822
+
823
+ Parameters
824
+ ----------
825
+ element
826
+ An expression that produces a single value
827
+
828
+ Examples
829
+ --------
830
+ >>> s = pl.Series("a", [[0], [1], [1, 2, 3, 2], [1, 2, 1], [4, 4]])
831
+ >>> s.list.count_matches(1)
832
+ shape: (5,)
833
+ Series: 'a' [u32]
834
+ [
835
+ 0
836
+ 1
837
+ 1
838
+ 2
839
+ 0
840
+ ]
841
+ """
842
+
843
+ def to_array(self, width: int) -> Series:
844
+ """
845
+ Convert a List column into an Array column with the same inner data type.
846
+
847
+ Parameters
848
+ ----------
849
+ width
850
+ Width of the resulting Array column.
851
+
852
+ Returns
853
+ -------
854
+ Series
855
+ Series of data type :class:`Array`.
856
+
857
+ Examples
858
+ --------
859
+ >>> s = pl.Series([[1, 2], [3, 4]], dtype=pl.List(pl.Int8))
860
+ >>> s.list.to_array(2)
861
+ shape: (2,)
862
+ Series: '' [array[i8, 2]]
863
+ [
864
+ [1, 2]
865
+ [3, 4]
866
+ ]
867
+ """
868
+
869
+ def to_struct(
870
+ self,
871
+ n_field_strategy: ListToStructWidthStrategy = "first_non_null",
872
+ fields: Callable[[int], str] | Sequence[str] | None = None,
873
+ ) -> Series:
874
+ """
875
+ Convert the series of type `List` to a series of type `Struct`.
876
+
877
+ Parameters
878
+ ----------
879
+ n_field_strategy : {'first_non_null', 'max_width'}
880
+ Strategy to determine the number of fields of the struct.
881
+
882
+ * "first_non_null": set number of fields equal to the length of the
883
+ first non zero-length sublist.
884
+ * "max_width": set number of fields as max length of all sublists.
885
+ fields
886
+ If the name and number of the desired fields is known in advance
887
+ a list of field names can be given, which will be assigned by index.
888
+ Otherwise, to dynamically assign field names, a custom function can be
889
+ used; if neither are set, fields will be `field_0, field_1 .. field_n`.
890
+
891
+ Examples
892
+ --------
893
+ Convert list to struct with default field name assignment:
894
+
895
+ >>> s1 = pl.Series("n", [[0, 1, 2], [0, 1]])
896
+ >>> s2 = s1.list.to_struct()
897
+ >>> s2
898
+ shape: (2,)
899
+ Series: 'n' [struct[3]]
900
+ [
901
+ {0,1,2}
902
+ {0,1,null}
903
+ ]
904
+ >>> s2.struct.fields
905
+ ['field_0', 'field_1', 'field_2']
906
+
907
+ Convert list to struct with field name assignment by function/index:
908
+
909
+ >>> s3 = s1.list.to_struct(fields=lambda idx: f"n{idx:02}")
910
+ >>> s3.struct.fields
911
+ ['n00', 'n01', 'n02']
912
+
913
+ Convert list to struct with field name assignment by index from a list of names:
914
+
915
+ >>> s1.list.to_struct(fields=["one", "two", "three"]).struct.unnest()
916
+ shape: (2, 3)
917
+ ┌─────┬─────┬───────┐
918
+ │ one ┆ two ┆ three │
919
+ │ --- ┆ --- ┆ --- │
920
+ │ i64 ┆ i64 ┆ i64 │
921
+ ╞═════╪═════╪═══════╡
922
+ │ 0 ┆ 1 ┆ 2 │
923
+ │ 0 ┆ 1 ┆ null │
924
+ └─────┴─────┴───────┘
925
+ """
926
+ if isinstance(fields, Sequence):
927
+ s = wrap_s(self._s)
928
+ return (
929
+ s.to_frame()
930
+ .select_seq(F.col(s.name).list.to_struct(fields=fields))
931
+ .to_series()
932
+ )
933
+
934
+ return wrap_s(self._s.list_to_struct(n_field_strategy, fields))
935
+
936
+ def eval(self, expr: Expr, *, parallel: bool = False) -> Series:
937
+ """
938
+ Run any polars expression against the lists' elements.
939
+
940
+ Parameters
941
+ ----------
942
+ expr
943
+ Expression to run. Note that you can select an element with `pl.first()`, or
944
+ `pl.col()`
945
+ parallel
946
+ Run all expression parallel. Don't activate this blindly.
947
+ Parallelism is worth it if there is enough work to do per thread.
948
+
949
+ This likely should not be use in the group by context, because we already
950
+ parallel execution per group
951
+
952
+ Examples
953
+ --------
954
+ >>> s = pl.Series("a", [[1, 4], [8, 5], [3, 2]])
955
+ >>> s.list.eval(pl.element().rank())
956
+ shape: (3,)
957
+ Series: 'a' [list[f64]]
958
+ [
959
+ [1.0, 2.0]
960
+ [2.0, 1.0]
961
+ [2.0, 1.0]
962
+ ]
963
+ """
964
+
965
+ def filter(self, predicate: Expr) -> Series:
966
+ """
967
+ Filter elements in each list by a boolean expression, returning a new Series of lists.
968
+
969
+ Parameters
970
+ ----------
971
+ predicate
972
+ A boolean expression evaluated on each list element.
973
+ Use `pl.element()` to refer to the current element.
974
+
975
+ Examples
976
+ --------
977
+ >>> import polars as pl
978
+ >>> s = pl.Series("a", [[1, 4], [8, 5], [3, 2]])
979
+ >>> s.list.filter(pl.element() % 2 == 0)
980
+ shape: (3,)
981
+ Series: 'a' [list[i64]]
982
+ [
983
+ [4]
984
+ [8]
985
+ [2]
986
+ ]
987
+ """ # noqa: W505
988
+
989
+ def set_union(self, other: Series | Collection[Any]) -> Series:
990
+ """
991
+ Compute the SET UNION between the elements in this list and the elements of `other`.
992
+
993
+ Parameters
994
+ ----------
995
+ other
996
+ Right hand side of the set operation.
997
+
998
+ Examples
999
+ --------
1000
+ >>> a = pl.Series([[1, 2, 3], [], [None, 3], [5, 6, 7]])
1001
+ >>> b = pl.Series([[2, 3, 4], [3], [3, 4, None], [6, 8]])
1002
+ >>> a.list.set_union(b) # doctest: +IGNORE_RESULT
1003
+ shape: (4,)
1004
+ Series: '' [list[i64]]
1005
+ [
1006
+ [1, 2, 3, 4]
1007
+ [3]
1008
+ [null, 3, 4]
1009
+ [5, 6, 7, 8]
1010
+ ]
1011
+ """ # noqa: W505
1012
+
1013
+ def set_difference(self, other: Series | Collection[Any]) -> Series:
1014
+ """
1015
+ Compute the SET DIFFERENCE between the elements in this list and the elements of `other`.
1016
+
1017
+ Parameters
1018
+ ----------
1019
+ other
1020
+ Right hand side of the set operation.
1021
+
1022
+ See Also
1023
+ --------
1024
+ polars.Series.list.diff: Calculates the n-th discrete difference of every sublist.
1025
+
1026
+ Examples
1027
+ --------
1028
+ >>> a = pl.Series([[1, 2, 3], [], [None, 3], [5, 6, 7]])
1029
+ >>> b = pl.Series([[2, 3, 4], [3], [3, 4, None], [6, 8]])
1030
+ >>> a.list.set_difference(b)
1031
+ shape: (4,)
1032
+ Series: '' [list[i64]]
1033
+ [
1034
+ [1]
1035
+ []
1036
+ []
1037
+ [5, 7]
1038
+ ]
1039
+ """ # noqa: W505
1040
+
1041
+ def set_intersection(self, other: Series | Collection[Any]) -> Series:
1042
+ """
1043
+ Compute the SET INTERSECTION between the elements in this list and the elements of `other`.
1044
+
1045
+ Parameters
1046
+ ----------
1047
+ other
1048
+ Right hand side of the set operation.
1049
+
1050
+ Examples
1051
+ --------
1052
+ >>> a = pl.Series([[1, 2, 3], [], [None, 3], [5, 6, 7]])
1053
+ >>> b = pl.Series([[2, 3, 4], [3], [3, 4, None], [6, 8]])
1054
+ >>> a.list.set_intersection(b)
1055
+ shape: (4,)
1056
+ Series: '' [list[i64]]
1057
+ [
1058
+ [2, 3]
1059
+ []
1060
+ [null, 3]
1061
+ [6]
1062
+ ]
1063
+ """ # noqa: W505
1064
+
1065
+ def set_symmetric_difference(self, other: Series | Collection[Any]) -> Series:
1066
+ """
1067
+ Compute the SET SYMMETRIC DIFFERENCE between the elements in this list and the elements of `other`.
1068
+
1069
+ Parameters
1070
+ ----------
1071
+ other
1072
+ Right hand side of the set operation.
1073
+
1074
+ Examples
1075
+ --------
1076
+ >>> a = pl.Series([[1, 2, 3], [], [None, 3], [5, 6, 7]])
1077
+ >>> b = pl.Series([[2, 3, 4], [3], [3, 4, None], [6, 8]])
1078
+ >>> a.list.set_symmetric_difference(b)
1079
+ shape: (4,)
1080
+ Series: '' [list[i64]]
1081
+ [
1082
+ [1, 4]
1083
+ [3]
1084
+ [4]
1085
+ [5, 7, 8]
1086
+ ]
1087
+ """ # noqa: W505