polars-df 0.21.0-x64-mingw-ucrt → 0.21.1-x64-mingw-ucrt
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/Cargo.lock +1 -1
- data/LICENSE-THIRD-PARTY.txt +24 -24
- data/lib/polars/3.2/polars.so +0 -0
- data/lib/polars/3.3/polars.so +0 -0
- data/lib/polars/3.4/polars.so +0 -0
- data/lib/polars/array_expr.rb +382 -3
- data/lib/polars/array_name_space.rb +281 -0
- data/lib/polars/binary_expr.rb +67 -0
- data/lib/polars/binary_name_space.rb +43 -0
- data/lib/polars/cat_expr.rb +224 -0
- data/lib/polars/cat_name_space.rb +138 -0
- data/lib/polars/config.rb +2 -2
- data/lib/polars/convert.rb +6 -6
- data/lib/polars/data_frame.rb +684 -19
- data/lib/polars/data_type_expr.rb +52 -0
- data/lib/polars/data_types.rb +14 -2
- data/lib/polars/date_time_expr.rb +251 -0
- data/lib/polars/date_time_name_space.rb +299 -0
- data/lib/polars/expr.rb +1213 -180
- data/lib/polars/functions/datatype.rb +21 -0
- data/lib/polars/functions/lazy.rb +13 -0
- data/lib/polars/io/csv.rb +1 -1
- data/lib/polars/io/json.rb +4 -4
- data/lib/polars/io/ndjson.rb +4 -4
- data/lib/polars/io/parquet.rb +27 -5
- data/lib/polars/lazy_frame.rb +936 -20
- data/lib/polars/list_expr.rb +196 -4
- data/lib/polars/list_name_space.rb +201 -4
- data/lib/polars/meta_expr.rb +64 -0
- data/lib/polars/name_expr.rb +36 -0
- data/lib/polars/schema.rb +79 -3
- data/lib/polars/selector.rb +72 -0
- data/lib/polars/selectors.rb +3 -3
- data/lib/polars/series.rb +1051 -54
- data/lib/polars/string_expr.rb +411 -6
- data/lib/polars/string_name_space.rb +722 -49
- data/lib/polars/struct_expr.rb +103 -0
- data/lib/polars/struct_name_space.rb +19 -1
- data/lib/polars/utils/various.rb +18 -1
- data/lib/polars/utils.rb +5 -1
- data/lib/polars/version.rb +1 -1
- data/lib/polars.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 950675a4e03f1ebc9b408f107aada47d4160b616429adc13fa364ec7a1adb91b
|
4
|
+
data.tar.gz: '082cf2a2ade8ae92b843d08390b57ff855902a24cb5887de14bdad9ec5a4e4eb'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6c668e60ab1bf492349d7ad4d07eae5880f3478b9669217c5f3ca92c167ff99042d856f8ece8be9ccb9552f9b494157e737dcfc5b8cfa133afa12e6c1cff379
|
7
|
+
data.tar.gz: 047fa232b754597a773ff10cfd03131272bd775fb6d8ae1984cd6c19a003939f98b928292e825f40ccf9a995e2c744f3ef5716c7355cf718c1b971aaa5810f1a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
## 0.21.1 (2025-08-18)
|
2
|
+
|
3
|
+
- Added `read_parquet_metadata` method to `Polars`
|
4
|
+
- Added more methods to `Series` and `Expr`
|
5
|
+
- Added more methods to `DataFrame` and `LazyFrame`
|
6
|
+
- Added more methods to `ArrayExpr` and `ArrayNameSpace`
|
7
|
+
- Added more methods to `BinaryExpr` and `BinaryNameSpace`
|
8
|
+
- Added more methods to `CatExpr` and `CatNameSpace`
|
9
|
+
- Added more methods to `DateTimeExpr` ane `DateTimeNameSpace`
|
10
|
+
- Added more methods to `ListExpr` and `ListNameSpace`
|
11
|
+
- Added more methods to `MetaExpr`
|
12
|
+
- Added more methods to `NameExpr`
|
13
|
+
- Added more methods to `StringExpr` and `StringNameSpace`
|
14
|
+
- Added more methods to `StructExpr` and `StructNameSpace`
|
15
|
+
- Fixed `subset` option for `drop_nulls` method
|
16
|
+
|
1
17
|
## 0.21.0 (2025-08-03)
|
2
18
|
|
3
19
|
- Updated Polars to 0.50.0
|
data/Cargo.lock
CHANGED
data/LICENSE-THIRD-PARTY.txt
CHANGED
@@ -47281,30 +47281,6 @@ OTHER DEALINGS IN THE SOFTWARE.
|
|
47281
47281
|
|
47282
47282
|
For more information, please refer to <http://unlicense.org/>
|
47283
47283
|
|
47284
|
-
================================================================================
|
47285
|
-
winapi-x86_64-pc-windows-gnu LICENSE-MIT
|
47286
|
-
================================================================================
|
47287
|
-
|
47288
|
-
Copyright (c) 2015-2018 The winapi-rs Developers
|
47289
|
-
|
47290
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
47291
|
-
of this software and associated documentation files (the "Software"), to deal
|
47292
|
-
in the Software without restriction, including without limitation the rights
|
47293
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
47294
|
-
copies of the Software, and to permit persons to whom the Software is
|
47295
|
-
furnished to do so, subject to the following conditions:
|
47296
|
-
|
47297
|
-
The above copyright notice and this permission notice shall be included in all
|
47298
|
-
copies or substantial portions of the Software.
|
47299
|
-
|
47300
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
47301
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
47302
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
47303
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
47304
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
47305
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
47306
|
-
SOFTWARE.
|
47307
|
-
|
47308
47284
|
================================================================================
|
47309
47285
|
winapi-x86_64-pc-windows-gnu LICENSE-APACHE
|
47310
47286
|
================================================================================
|
@@ -47511,6 +47487,30 @@ winapi-x86_64-pc-windows-gnu LICENSE-APACHE
|
|
47511
47487
|
See the License for the specific language governing permissions and
|
47512
47488
|
limitations under the License.
|
47513
47489
|
|
47490
|
+
================================================================================
|
47491
|
+
winapi-x86_64-pc-windows-gnu LICENSE-MIT
|
47492
|
+
================================================================================
|
47493
|
+
|
47494
|
+
Copyright (c) 2015-2018 The winapi-rs Developers
|
47495
|
+
|
47496
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
47497
|
+
of this software and associated documentation files (the "Software"), to deal
|
47498
|
+
in the Software without restriction, including without limitation the rights
|
47499
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
47500
|
+
copies of the Software, and to permit persons to whom the Software is
|
47501
|
+
furnished to do so, subject to the following conditions:
|
47502
|
+
|
47503
|
+
The above copyright notice and this permission notice shall be included in all
|
47504
|
+
copies or substantial portions of the Software.
|
47505
|
+
|
47506
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
47507
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
47508
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
47509
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
47510
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
47511
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
47512
|
+
SOFTWARE.
|
47513
|
+
|
47514
47514
|
================================================================================
|
47515
47515
|
windows-link license-mit
|
47516
47516
|
================================================================================
|
data/lib/polars/3.2/polars.so
CHANGED
Binary file
|
data/lib/polars/3.3/polars.so
CHANGED
Binary file
|
data/lib/polars/3.4/polars.so
CHANGED
Binary file
|
data/lib/polars/array_expr.rb
CHANGED
@@ -9,6 +9,181 @@ module Polars
|
|
9
9
|
self._rbexpr = expr._rbexpr
|
10
10
|
end
|
11
11
|
|
12
|
+
# Return the number of elements in each array.
|
13
|
+
#
|
14
|
+
# @return [Expr]
|
15
|
+
#
|
16
|
+
# @example
|
17
|
+
# df = Polars::DataFrame.new(
|
18
|
+
# {"a" => [[1, 2], [4, 3]]},
|
19
|
+
# schema: {"a" => Polars::Array.new(Polars::Int64, 2)}
|
20
|
+
# )
|
21
|
+
# df.select(Polars.col("a").arr.len)
|
22
|
+
# # =>
|
23
|
+
# # shape: (2, 1)
|
24
|
+
# # ┌─────┐
|
25
|
+
# # │ a │
|
26
|
+
# # │ --- │
|
27
|
+
# # │ u32 │
|
28
|
+
# # ╞═════╡
|
29
|
+
# # │ 2 │
|
30
|
+
# # │ 2 │
|
31
|
+
# # └─────┘
|
32
|
+
def len
|
33
|
+
Utils.wrap_expr(_rbexpr.arr_len)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Slice every subarray.
|
37
|
+
#
|
38
|
+
# @param offset [Integer]
|
39
|
+
# Start index. Negative indexing is supported.
|
40
|
+
# @param length [Integer]
|
41
|
+
# Length of the slice. If set to `None` (default), the slice is taken to the
|
42
|
+
# end of the list.
|
43
|
+
# @param as_array [Boolean]
|
44
|
+
# Return result as a fixed-length `Array`, otherwise as a `List`.
|
45
|
+
# If true `length` and `offset` must be constant values.
|
46
|
+
#
|
47
|
+
# @return [Expr]
|
48
|
+
#
|
49
|
+
# @example
|
50
|
+
# df = Polars::DataFrame.new(
|
51
|
+
# {"a" => [[1, 2], [4, 3]]},
|
52
|
+
# schema: {"a" => Polars::Array.new(Polars::Int64, 2)}
|
53
|
+
# )
|
54
|
+
# df.select(Polars.col("a").arr.slice(0, 1))
|
55
|
+
# # =>
|
56
|
+
# # shape: (2, 1)
|
57
|
+
# # ┌───────────┐
|
58
|
+
# # │ a │
|
59
|
+
# # │ --- │
|
60
|
+
# # │ list[i64] │
|
61
|
+
# # ╞═══════════╡
|
62
|
+
# # │ [1] │
|
63
|
+
# # │ [4] │
|
64
|
+
# # └───────────┘
|
65
|
+
#
|
66
|
+
# @example
|
67
|
+
# df = Polars::DataFrame.new(
|
68
|
+
# {"a" => [[1, 2], [4, 3]]},
|
69
|
+
# schema: {"a" => Polars::Array.new(Polars::Int64, 2)}
|
70
|
+
# )
|
71
|
+
# df.select(Polars.col("a").arr.slice(0, 1, as_array: true))
|
72
|
+
# # =>
|
73
|
+
# # shape: (2, 1)
|
74
|
+
# # ┌───────────────┐
|
75
|
+
# # │ a │
|
76
|
+
# # │ --- │
|
77
|
+
# # │ array[i64, 1] │
|
78
|
+
# # ╞═══════════════╡
|
79
|
+
# # │ [1] │
|
80
|
+
# # │ [4] │
|
81
|
+
# # └───────────────┘
|
82
|
+
def slice(
|
83
|
+
offset,
|
84
|
+
length = nil,
|
85
|
+
as_array: false
|
86
|
+
)
|
87
|
+
offset = Utils.parse_into_expression(offset)
|
88
|
+
length = !length.nil? ? Utils.parse_into_expression(length) : nil
|
89
|
+
Utils.wrap_expr(_rbexpr.arr_slice(offset, length, as_array))
|
90
|
+
end
|
91
|
+
|
92
|
+
# Get the first `n` elements of the sub-arrays.
|
93
|
+
#
|
94
|
+
# @param n [Integer]
|
95
|
+
# Number of values to return for each sublist.
|
96
|
+
# @param as_array [Boolean]
|
97
|
+
# Return result as a fixed-length `Array`, otherwise as a `List`.
|
98
|
+
# If true `n` must be a constant value.
|
99
|
+
#
|
100
|
+
# @return [Expr]
|
101
|
+
#
|
102
|
+
# @example
|
103
|
+
# df = Polars::DataFrame.new(
|
104
|
+
# {"a" => [[1, 2], [4, 3]]},
|
105
|
+
# schema: {"a" => Polars::Array.new(Polars::Int64, 2)}
|
106
|
+
# )
|
107
|
+
# df.select(Polars.col("a").arr.head(1))
|
108
|
+
# # =>
|
109
|
+
# # shape: (2, 1)
|
110
|
+
# # ┌───────────┐
|
111
|
+
# # │ a │
|
112
|
+
# # │ --- │
|
113
|
+
# # │ list[i64] │
|
114
|
+
# # ╞═══════════╡
|
115
|
+
# # │ [1] │
|
116
|
+
# # │ [4] │
|
117
|
+
# # └───────────┘
|
118
|
+
#
|
119
|
+
# @example
|
120
|
+
# df = Polars::DataFrame.new(
|
121
|
+
# {"a" => [[1, 2], [4, 3]]},
|
122
|
+
# schema: {"a" => Polars::Array.new(Polars::Int64, 2)}
|
123
|
+
# )
|
124
|
+
# df.select(Polars.col("a").arr.head(1, as_array: true))
|
125
|
+
# # =>
|
126
|
+
# # shape: (2, 1)
|
127
|
+
# # ┌───────────────┐
|
128
|
+
# # │ a │
|
129
|
+
# # │ --- │
|
130
|
+
# # │ array[i64, 1] │
|
131
|
+
# # ╞═══════════════╡
|
132
|
+
# # │ [1] │
|
133
|
+
# # │ [4] │
|
134
|
+
# # └───────────────┘
|
135
|
+
def head(n = 5, as_array: false)
|
136
|
+
slice(0, n, as_array: as_array)
|
137
|
+
end
|
138
|
+
|
139
|
+
# Slice the last `n` values of every sublist.
|
140
|
+
#
|
141
|
+
# @param n [Integer]
|
142
|
+
# Number of values to return for each sublist.
|
143
|
+
# @param as_array [Boolean]
|
144
|
+
# Return result as a fixed-length `Array`, otherwise as a `List`.
|
145
|
+
# If true `n` must be a constant value.
|
146
|
+
#
|
147
|
+
# @return [Expr]
|
148
|
+
#
|
149
|
+
# @example
|
150
|
+
# df = Polars::DataFrame.new(
|
151
|
+
# {"a" => [[1, 2], [4, 3]]},
|
152
|
+
# schema: {"a" => Polars::Array.new(Polars::Int64, 2)}
|
153
|
+
# )
|
154
|
+
# df.select(Polars.col("a").arr.tail(1))
|
155
|
+
# # =>
|
156
|
+
# # shape: (2, 1)
|
157
|
+
# # ┌───────────┐
|
158
|
+
# # │ a │
|
159
|
+
# # │ --- │
|
160
|
+
# # │ list[i64] │
|
161
|
+
# # ╞═══════════╡
|
162
|
+
# # │ [2] │
|
163
|
+
# # │ [3] │
|
164
|
+
# # └───────────┘
|
165
|
+
#
|
166
|
+
# @example
|
167
|
+
# df = Polars::DataFrame.new(
|
168
|
+
# {"a" => [[1, 2], [4, 3]]},
|
169
|
+
# schema: {"a" => Polars::Array.new(Polars::Int64, 2)}
|
170
|
+
# )
|
171
|
+
# df.select(Polars.col("a").arr.tail(1, as_array: true))
|
172
|
+
# # =>
|
173
|
+
# # shape: (2, 1)
|
174
|
+
# # ┌───────────────┐
|
175
|
+
# # │ a │
|
176
|
+
# # │ --- │
|
177
|
+
# # │ array[i64, 1] │
|
178
|
+
# # ╞═══════════════╡
|
179
|
+
# # │ [2] │
|
180
|
+
# # │ [3] │
|
181
|
+
# # └───────────────┘
|
182
|
+
def tail(n = 5, as_array: false)
|
183
|
+
n = Utils.parse_into_expression(n)
|
184
|
+
Utils.wrap_expr(_rbexpr.arr_tail(n, as_array))
|
185
|
+
end
|
186
|
+
|
12
187
|
# Compute the min values of the sub-arrays.
|
13
188
|
#
|
14
189
|
# @return [Expr]
|
@@ -30,7 +205,7 @@ module Polars
|
|
30
205
|
# # │ 3 │
|
31
206
|
# # └─────┘
|
32
207
|
def min
|
33
|
-
Utils.wrap_expr(_rbexpr.
|
208
|
+
Utils.wrap_expr(_rbexpr.arr_min)
|
34
209
|
end
|
35
210
|
|
36
211
|
# Compute the max values of the sub-arrays.
|
@@ -54,7 +229,7 @@ module Polars
|
|
54
229
|
# # │ 4 │
|
55
230
|
# # └─────┘
|
56
231
|
def max
|
57
|
-
Utils.wrap_expr(_rbexpr.
|
232
|
+
Utils.wrap_expr(_rbexpr.arr_max)
|
58
233
|
end
|
59
234
|
|
60
235
|
# Compute the sum values of the sub-arrays.
|
@@ -78,7 +253,103 @@ module Polars
|
|
78
253
|
# # │ 7 │
|
79
254
|
# # └─────┘
|
80
255
|
def sum
|
81
|
-
Utils.wrap_expr(_rbexpr.
|
256
|
+
Utils.wrap_expr(_rbexpr.arr_sum)
|
257
|
+
end
|
258
|
+
|
259
|
+
# Compute the std of the values of the sub-arrays.
|
260
|
+
#
|
261
|
+
# @return [Expr]
|
262
|
+
#
|
263
|
+
# @example
|
264
|
+
# df = Polars::DataFrame.new(
|
265
|
+
# {"a" => [[1, 2], [4, 3]]},
|
266
|
+
# schema: {"a" => Polars::Array.new(2, Polars::Int64)}
|
267
|
+
# )
|
268
|
+
# df.select(Polars.col("a").arr.std)
|
269
|
+
# # =>
|
270
|
+
# # shape: (2, 1)
|
271
|
+
# # ┌──────────┐
|
272
|
+
# # │ a │
|
273
|
+
# # │ --- │
|
274
|
+
# # │ f64 │
|
275
|
+
# # ╞══════════╡
|
276
|
+
# # │ 0.707107 │
|
277
|
+
# # │ 0.707107 │
|
278
|
+
# # └──────────┘
|
279
|
+
def std(ddof: 1)
|
280
|
+
Utils.wrap_expr(_rbexpr.arr_std(ddof))
|
281
|
+
end
|
282
|
+
|
283
|
+
# Compute the var of the values of the sub-arrays.
|
284
|
+
#
|
285
|
+
# @return [Expr]
|
286
|
+
#
|
287
|
+
# @example
|
288
|
+
# df = Polars::DataFrame.new(
|
289
|
+
# {"a" => [[1, 2], [4, 3]]},
|
290
|
+
# schema: {"a" => Polars::Array.new(2, Polars::Int64)}
|
291
|
+
# )
|
292
|
+
# df.select(Polars.col("a").arr.var)
|
293
|
+
# # =>
|
294
|
+
# # shape: (2, 1)
|
295
|
+
# # ┌─────┐
|
296
|
+
# # │ a │
|
297
|
+
# # │ --- │
|
298
|
+
# # │ f64 │
|
299
|
+
# # ╞═════╡
|
300
|
+
# # │ 0.5 │
|
301
|
+
# # │ 0.5 │
|
302
|
+
# # └─────┘
|
303
|
+
def var(ddof: 1)
|
304
|
+
Utils.wrap_expr(_rbexpr.arr_var(ddof))
|
305
|
+
end
|
306
|
+
|
307
|
+
# Compute the mean of the values of the sub-arrays.
|
308
|
+
#
|
309
|
+
# @return [Expr]
|
310
|
+
#
|
311
|
+
# @example
|
312
|
+
# df = Polars::DataFrame.new(
|
313
|
+
# {"a" => [[1, 2, 3], [1, 1, 16]]},
|
314
|
+
# schema: {"a" => Polars::Array.new(Polars::Int64, 3)}
|
315
|
+
# )
|
316
|
+
# df.select(Polars.col("a").arr.mean)
|
317
|
+
# # =>
|
318
|
+
# # shape: (2, 1)
|
319
|
+
# # ┌─────┐
|
320
|
+
# # │ a │
|
321
|
+
# # │ --- │
|
322
|
+
# # │ f64 │
|
323
|
+
# # ╞═════╡
|
324
|
+
# # │ 2.0 │
|
325
|
+
# # │ 6.0 │
|
326
|
+
# # └─────┘
|
327
|
+
def mean
|
328
|
+
Utils.wrap_expr(_rbexpr.arr_mean)
|
329
|
+
end
|
330
|
+
|
331
|
+
# Compute the median of the values of the sub-arrays.
|
332
|
+
#
|
333
|
+
# @return [Expr]
|
334
|
+
#
|
335
|
+
# @example
|
336
|
+
# df = Polars::DataFrame.new(
|
337
|
+
# {"a" => [[1, 2], [4, 3]]},
|
338
|
+
# schema: {"a" => Polars::Array.new(2, Polars::Int64)}
|
339
|
+
# )
|
340
|
+
# df.select(Polars.col("a").arr.median)
|
341
|
+
# # =>
|
342
|
+
# # shape: (2, 1)
|
343
|
+
# # ┌─────┐
|
344
|
+
# # │ a │
|
345
|
+
# # │ --- │
|
346
|
+
# # │ f64 │
|
347
|
+
# # ╞═════╡
|
348
|
+
# # │ 1.5 │
|
349
|
+
# # │ 3.5 │
|
350
|
+
# # └─────┘
|
351
|
+
def median
|
352
|
+
Utils.wrap_expr(_rbexpr.arr_median)
|
82
353
|
end
|
83
354
|
|
84
355
|
# Get the unique/distinct values in the array.
|
@@ -109,6 +380,32 @@ module Polars
|
|
109
380
|
Utils.wrap_expr(_rbexpr.arr_unique(maintain_order))
|
110
381
|
end
|
111
382
|
|
383
|
+
# Count the number of unique values in every sub-arrays.
|
384
|
+
#
|
385
|
+
# @return [Expr]
|
386
|
+
#
|
387
|
+
# @example
|
388
|
+
# df = Polars::DataFrame.new(
|
389
|
+
# {
|
390
|
+
# "a" => [[1, 1, 2], [2, 3, 4]],
|
391
|
+
# },
|
392
|
+
# schema: {"a" => Polars::Array.new(Polars::Int64, 3)}
|
393
|
+
# )
|
394
|
+
# df.with_columns(n_unique: Polars.col("a").arr.n_unique)
|
395
|
+
# # =>
|
396
|
+
# # shape: (2, 2)
|
397
|
+
# # ┌───────────────┬──────────┐
|
398
|
+
# # │ a ┆ n_unique │
|
399
|
+
# # │ --- ┆ --- │
|
400
|
+
# # │ array[i64, 3] ┆ u32 │
|
401
|
+
# # ╞═══════════════╪══════════╡
|
402
|
+
# # │ [1, 1, 2] ┆ 2 │
|
403
|
+
# # │ [2, 3, 4] ┆ 3 │
|
404
|
+
# # └───────────────┴──────────┘
|
405
|
+
def n_unique
|
406
|
+
Utils.wrap_expr(_rbexpr.arr_n_unique)
|
407
|
+
end
|
408
|
+
|
112
409
|
# Convert an Array column into a List column with the same inner data type.
|
113
410
|
#
|
114
411
|
# @return [Expr]
|
@@ -535,5 +832,87 @@ module Polars
|
|
535
832
|
element = Utils.parse_into_expression(element, str_as_lit: true)
|
536
833
|
Utils.wrap_expr(_rbexpr.arr_count_matches(element))
|
537
834
|
end
|
835
|
+
|
836
|
+
# Convert the Series of type `Array` to a Series of type `Struct`.
|
837
|
+
#
|
838
|
+
# @param fields [Object]
|
839
|
+
# If the name and number of the desired fields is known in advance
|
840
|
+
# a list of field names can be given, which will be assigned by index.
|
841
|
+
# Otherwise, to dynamically assign field names, a custom function can be
|
842
|
+
# used; if neither are set, fields will be `field_0, field_1 .. field_n`.
|
843
|
+
#
|
844
|
+
# @return [Expr]
|
845
|
+
#
|
846
|
+
# @example Convert array to struct with default field name assignment:
|
847
|
+
# df = Polars::DataFrame.new(
|
848
|
+
# {"n" => [[0, 1, 2], [3, 4, 5]]}, schema: {"n" => Polars::Array.new(Polars::Int8, 3)}
|
849
|
+
# )
|
850
|
+
# df.with_columns(struct: Polars.col("n").arr.to_struct)
|
851
|
+
# # =>
|
852
|
+
# # shape: (2, 2)
|
853
|
+
# # ┌──────────────┬───────────┐
|
854
|
+
# # │ n ┆ struct │
|
855
|
+
# # │ --- ┆ --- │
|
856
|
+
# # │ array[i8, 3] ┆ struct[3] │
|
857
|
+
# # ╞══════════════╪═══════════╡
|
858
|
+
# # │ [0, 1, 2] ┆ {0,1,2} │
|
859
|
+
# # │ [3, 4, 5] ┆ {3,4,5} │
|
860
|
+
# # └──────────────┴───────────┘
|
861
|
+
def to_struct(fields: nil)
|
862
|
+
raise Todo if fields
|
863
|
+
if fields.is_a?(Enumerable)
|
864
|
+
field_names = fields.to_a
|
865
|
+
rbexpr = _rbexpr.arr_to_struct(nil)
|
866
|
+
Utils.wrap_expr(rbexpr).struct.rename_fields(field_names)
|
867
|
+
else
|
868
|
+
rbexpr = _rbexpr.arr_to_struct(fields)
|
869
|
+
Utils.wrap_expr(rbexpr)
|
870
|
+
end
|
871
|
+
end
|
872
|
+
|
873
|
+
# Shift array values by the given number of indices.
|
874
|
+
#
|
875
|
+
# @param n [Integer]
|
876
|
+
# Number of indices to shift forward. If a negative value is passed, values
|
877
|
+
# are shifted in the opposite direction instead.
|
878
|
+
#
|
879
|
+
# @return [Expr]
|
880
|
+
#
|
881
|
+
# @note
|
882
|
+
# This method is similar to the `LAG` operation in SQL when the value for `n`
|
883
|
+
# is positive. With a negative value for `n`, it is similar to `LEAD`.
|
884
|
+
#
|
885
|
+
# @example By default, array values are shifted forward by one index.
|
886
|
+
# df = Polars::DataFrame.new(
|
887
|
+
# {"a" => [[1, 2, 3], [4, 5, 6]]}, schema: {"a" => Polars::Array.new(Polars::Int64, 3)}
|
888
|
+
# )
|
889
|
+
# df.with_columns(shift: Polars.col("a").arr.shift)
|
890
|
+
# # =>
|
891
|
+
# # shape: (2, 2)
|
892
|
+
# # ┌───────────────┬───────────────┐
|
893
|
+
# # │ a ┆ shift │
|
894
|
+
# # │ --- ┆ --- │
|
895
|
+
# # │ array[i64, 3] ┆ array[i64, 3] │
|
896
|
+
# # ╞═══════════════╪═══════════════╡
|
897
|
+
# # │ [1, 2, 3] ┆ [null, 1, 2] │
|
898
|
+
# # │ [4, 5, 6] ┆ [null, 4, 5] │
|
899
|
+
# # └───────────────┴───────────────┘
|
900
|
+
#
|
901
|
+
# @example Pass a negative value to shift in the opposite direction instead.
|
902
|
+
# df.with_columns(shift: Polars.col("a").arr.shift(-2))
|
903
|
+
# # =>
|
904
|
+
# # shape: (2, 2)
|
905
|
+
# # ┌───────────────┬─────────────────┐
|
906
|
+
# # │ a ┆ shift │
|
907
|
+
# # │ --- ┆ --- │
|
908
|
+
# # │ array[i64, 3] ┆ array[i64, 3] │
|
909
|
+
# # ╞═══════════════╪═════════════════╡
|
910
|
+
# # │ [1, 2, 3] ┆ [3, null, null] │
|
911
|
+
# # │ [4, 5, 6] ┆ [6, null, null] │
|
912
|
+
# # └───────────────┴─────────────────┘
|
913
|
+
def shift(n = 1)
|
914
|
+
n = Utils.parse_into_expression(n)
|
915
|
+
Utils.wrap_expr(_rbexpr.arr_shift(n))
|
916
|
+
end
|
538
917
|
end
|
539
918
|
end
|