polars-df 0.2.5 → 0.3.0
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 +8 -0
- data/Cargo.lock +290 -137
- data/Cargo.toml +1 -1
- data/ext/polars/Cargo.toml +5 -4
- data/ext/polars/src/apply/dataframe.rs +6 -6
- data/ext/polars/src/apply/series.rs +10 -10
- data/ext/polars/src/batched_csv.rs +6 -4
- data/ext/polars/src/conversion.rs +40 -13
- data/ext/polars/src/dataframe.rs +45 -43
- data/ext/polars/src/error.rs +8 -8
- data/ext/polars/src/file.rs +5 -4
- data/ext/polars/src/lazy/apply.rs +1 -1
- data/ext/polars/src/lazy/dataframe.rs +12 -6
- data/ext/polars/src/lazy/dsl.rs +99 -45
- data/ext/polars/src/lazy/meta.rs +10 -9
- data/ext/polars/src/lib.rs +28 -29
- data/ext/polars/src/object.rs +2 -1
- data/ext/polars/src/series.rs +23 -21
- data/lib/polars/cat_expr.rb +0 -4
- data/lib/polars/cat_name_space.rb +0 -4
- data/lib/polars/convert.rb +0 -7
- data/lib/polars/data_frame.rb +139 -204
- data/lib/polars/date_time_expr.rb +19 -151
- data/lib/polars/date_time_name_space.rb +17 -17
- data/lib/polars/expr.rb +68 -315
- data/lib/polars/group_by.rb +68 -51
- data/lib/polars/io.rb +1 -1
- data/lib/polars/lazy_frame.rb +1 -103
- data/lib/polars/lazy_functions.rb +0 -26
- data/lib/polars/lazy_group_by.rb +0 -8
- data/lib/polars/list_expr.rb +5 -27
- data/lib/polars/list_name_space.rb +5 -8
- data/lib/polars/series.rb +20 -16
- data/lib/polars/string_expr.rb +20 -76
- data/lib/polars/string_name_space.rb +5 -15
- data/lib/polars/struct_expr.rb +0 -2
- data/lib/polars/version.rb +1 -1
- metadata +3 -3
data/lib/polars/list_expr.rb
CHANGED
@@ -24,7 +24,6 @@ module Polars
|
|
24
24
|
# # │ u32 │
|
25
25
|
# # ╞═════╡
|
26
26
|
# # │ 2 │
|
27
|
-
# # ├╌╌╌╌╌┤
|
28
27
|
# # │ 1 │
|
29
28
|
# # └─────┘
|
30
29
|
def lengths
|
@@ -46,7 +45,6 @@ module Polars
|
|
46
45
|
# # │ i64 │
|
47
46
|
# # ╞════════╡
|
48
47
|
# # │ 1 │
|
49
|
-
# # ├╌╌╌╌╌╌╌╌┤
|
50
48
|
# # │ 5 │
|
51
49
|
# # └────────┘
|
52
50
|
def sum
|
@@ -68,7 +66,6 @@ module Polars
|
|
68
66
|
# # │ i64 │
|
69
67
|
# # ╞════════╡
|
70
68
|
# # │ 1 │
|
71
|
-
# # ├╌╌╌╌╌╌╌╌┤
|
72
69
|
# # │ 3 │
|
73
70
|
# # └────────┘
|
74
71
|
def max
|
@@ -90,7 +87,6 @@ module Polars
|
|
90
87
|
# # │ i64 │
|
91
88
|
# # ╞════════╡
|
92
89
|
# # │ 1 │
|
93
|
-
# # ├╌╌╌╌╌╌╌╌┤
|
94
90
|
# # │ 2 │
|
95
91
|
# # └────────┘
|
96
92
|
def min
|
@@ -112,7 +108,6 @@ module Polars
|
|
112
108
|
# # │ f64 │
|
113
109
|
# # ╞════════╡
|
114
110
|
# # │ 1.0 │
|
115
|
-
# # ├╌╌╌╌╌╌╌╌┤
|
116
111
|
# # │ 2.5 │
|
117
112
|
# # └────────┘
|
118
113
|
def mean
|
@@ -138,7 +133,6 @@ module Polars
|
|
138
133
|
# # │ list[i64] │
|
139
134
|
# # ╞═══════════╡
|
140
135
|
# # │ [1, 2, 3] │
|
141
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌┤
|
142
136
|
# # │ [1, 2, 9] │
|
143
137
|
# # └───────────┘
|
144
138
|
def sort(reverse: false)
|
@@ -164,7 +158,6 @@ module Polars
|
|
164
158
|
# # │ list[i64] │
|
165
159
|
# # ╞═══════════╡
|
166
160
|
# # │ [1, 2, 3] │
|
167
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌┤
|
168
161
|
# # │ [2, 1, 9] │
|
169
162
|
# # └───────────┘
|
170
163
|
def reverse
|
@@ -218,7 +211,6 @@ module Polars
|
|
218
211
|
# # │ list[str] │
|
219
212
|
# # ╞═════════════════╡
|
220
213
|
# # │ ["a", "b", "c"] │
|
221
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
222
214
|
# # │ ["x", "y", "z"] │
|
223
215
|
# # └─────────────────┘
|
224
216
|
def concat(other)
|
@@ -258,9 +250,7 @@ module Polars
|
|
258
250
|
# # │ i64 │
|
259
251
|
# # ╞══════╡
|
260
252
|
# # │ 3 │
|
261
|
-
# # ├╌╌╌╌╌╌┤
|
262
253
|
# # │ null │
|
263
|
-
# # ├╌╌╌╌╌╌┤
|
264
254
|
# # │ 1 │
|
265
255
|
# # └──────┘
|
266
256
|
def get(index)
|
@@ -290,9 +280,7 @@ module Polars
|
|
290
280
|
# # │ i64 │
|
291
281
|
# # ╞══════╡
|
292
282
|
# # │ 3 │
|
293
|
-
# # ├╌╌╌╌╌╌┤
|
294
283
|
# # │ null │
|
295
|
-
# # ├╌╌╌╌╌╌┤
|
296
284
|
# # │ 1 │
|
297
285
|
# # └──────┘
|
298
286
|
def first
|
@@ -314,9 +302,7 @@ module Polars
|
|
314
302
|
# # │ i64 │
|
315
303
|
# # ╞══════╡
|
316
304
|
# # │ 1 │
|
317
|
-
# # ├╌╌╌╌╌╌┤
|
318
305
|
# # │ null │
|
319
|
-
# # ├╌╌╌╌╌╌┤
|
320
306
|
# # │ 2 │
|
321
307
|
# # └──────┘
|
322
308
|
def last
|
@@ -341,9 +327,7 @@ module Polars
|
|
341
327
|
# # │ bool │
|
342
328
|
# # ╞═══════╡
|
343
329
|
# # │ true │
|
344
|
-
# # ├╌╌╌╌╌╌╌┤
|
345
330
|
# # │ false │
|
346
|
-
# # ├╌╌╌╌╌╌╌┤
|
347
331
|
# # │ true │
|
348
332
|
# # └───────┘
|
349
333
|
def contains(item)
|
@@ -370,7 +354,6 @@ module Polars
|
|
370
354
|
# # │ str │
|
371
355
|
# # ╞═══════╡
|
372
356
|
# # │ a b c │
|
373
|
-
# # ├╌╌╌╌╌╌╌┤
|
374
357
|
# # │ x y │
|
375
358
|
# # └───────┘
|
376
359
|
def join(separator)
|
@@ -396,7 +379,6 @@ module Polars
|
|
396
379
|
# # │ u32 │
|
397
380
|
# # ╞═════╡
|
398
381
|
# # │ 0 │
|
399
|
-
# # ├╌╌╌╌╌┤
|
400
382
|
# # │ 1 │
|
401
383
|
# # └─────┘
|
402
384
|
def arg_min
|
@@ -422,7 +404,6 @@ module Polars
|
|
422
404
|
# # │ u32 │
|
423
405
|
# # ╞═════╡
|
424
406
|
# # │ 1 │
|
425
|
-
# # ├╌╌╌╌╌┤
|
426
407
|
# # │ 0 │
|
427
408
|
# # └─────┘
|
428
409
|
def arg_max
|
@@ -443,7 +424,7 @@ module Polars
|
|
443
424
|
# s.arr.diff
|
444
425
|
# # =>
|
445
426
|
# # shape: (2,)
|
446
|
-
# # Series: 'a' [list]
|
427
|
+
# # Series: 'a' [list[i64]]
|
447
428
|
# # [
|
448
429
|
# # [null, 1, ... 1]
|
449
430
|
# # [null, -8, -1]
|
@@ -464,7 +445,7 @@ module Polars
|
|
464
445
|
# s.arr.shift
|
465
446
|
# # =>
|
466
447
|
# # shape: (2,)
|
467
|
-
# # Series: 'a' [list]
|
448
|
+
# # Series: 'a' [list[i64]]
|
468
449
|
# # [
|
469
450
|
# # [null, 1, ... 3]
|
470
451
|
# # [null, 10, 2]
|
@@ -488,7 +469,7 @@ module Polars
|
|
488
469
|
# s.arr.slice(1, 2)
|
489
470
|
# # =>
|
490
471
|
# # shape: (2,)
|
491
|
-
# # Series: 'a' [list]
|
472
|
+
# # Series: 'a' [list[i64]]
|
492
473
|
# # [
|
493
474
|
# # [2, 3]
|
494
475
|
# # [2, 1]
|
@@ -511,7 +492,7 @@ module Polars
|
|
511
492
|
# s.arr.head(2)
|
512
493
|
# # =>
|
513
494
|
# # shape: (2,)
|
514
|
-
# # Series: 'a' [list]
|
495
|
+
# # Series: 'a' [list[i64]]
|
515
496
|
# # [
|
516
497
|
# # [1, 2]
|
517
498
|
# # [10, 2]
|
@@ -532,7 +513,7 @@ module Polars
|
|
532
513
|
# s.arr.tail(2)
|
533
514
|
# # =>
|
534
515
|
# # shape: (2,)
|
535
|
-
# # Series: 'a' [list]
|
516
|
+
# # Series: 'a' [list[i64]]
|
536
517
|
# # [
|
537
518
|
# # [3, 4]
|
538
519
|
# # [2, 1]
|
@@ -563,7 +544,6 @@ module Polars
|
|
563
544
|
# # │ struct[3] │
|
564
545
|
# # ╞════════════╡
|
565
546
|
# # │ {1,2,3} │
|
566
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌┤
|
567
547
|
# # │ {1,2,null} │
|
568
548
|
# # └────────────┘
|
569
549
|
def to_struct(n_field_strategy: "first_non_null", name_generator: nil)
|
@@ -598,9 +578,7 @@ module Polars
|
|
598
578
|
# # │ i64 ┆ i64 ┆ list[f32] │
|
599
579
|
# # ╞═════╪═════╪════════════╡
|
600
580
|
# # │ 1 ┆ 4 ┆ [1.0, 2.0] │
|
601
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
602
581
|
# # │ 8 ┆ 5 ┆ [2.0, 1.0] │
|
603
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
604
582
|
# # │ 3 ┆ 2 ┆ [2.0, 1.0] │
|
605
583
|
# # └─────┴─────┴────────────┘
|
606
584
|
def eval(expr, parallel: false)
|
@@ -183,7 +183,7 @@ module Polars
|
|
183
183
|
# s.arr.diff
|
184
184
|
# # =>
|
185
185
|
# # shape: (2,)
|
186
|
-
# # Series: 'a' [list]
|
186
|
+
# # Series: 'a' [list[i64]]
|
187
187
|
# # [
|
188
188
|
# # [null, 1, ... 1]
|
189
189
|
# # [null, -8, -1]
|
@@ -204,7 +204,7 @@ module Polars
|
|
204
204
|
# s.arr.shift
|
205
205
|
# # =>
|
206
206
|
# # shape: (2,)
|
207
|
-
# # Series: 'a' [list]
|
207
|
+
# # Series: 'a' [list[i64]]
|
208
208
|
# # [
|
209
209
|
# # [null, 1, ... 3]
|
210
210
|
# # [null, 10, 2]
|
@@ -228,7 +228,7 @@ module Polars
|
|
228
228
|
# s.arr.slice(1, 2)
|
229
229
|
# # =>
|
230
230
|
# # shape: (2,)
|
231
|
-
# # Series: 'a' [list]
|
231
|
+
# # Series: 'a' [list[i64]]
|
232
232
|
# # [
|
233
233
|
# # [2, 3]
|
234
234
|
# # [2, 1]
|
@@ -249,7 +249,7 @@ module Polars
|
|
249
249
|
# s.arr.head(2)
|
250
250
|
# # =>
|
251
251
|
# # shape: (2,)
|
252
|
-
# # Series: 'a' [list]
|
252
|
+
# # Series: 'a' [list[i64]]
|
253
253
|
# # [
|
254
254
|
# # [1, 2]
|
255
255
|
# # [10, 2]
|
@@ -270,7 +270,7 @@ module Polars
|
|
270
270
|
# s.arr.tail(2)
|
271
271
|
# # =>
|
272
272
|
# # shape: (2,)
|
273
|
-
# # Series: 'a' [list]
|
273
|
+
# # Series: 'a' [list[i64]]
|
274
274
|
# # [
|
275
275
|
# # [3, 4]
|
276
276
|
# # [2, 1]
|
@@ -300,7 +300,6 @@ module Polars
|
|
300
300
|
# # │ struct[3] │
|
301
301
|
# # ╞════════════╡
|
302
302
|
# # │ {1,2,3} │
|
303
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌┤
|
304
303
|
# # │ {1,2,null} │
|
305
304
|
# # └────────────┘
|
306
305
|
def to_struct(n_field_strategy: "first_non_null", name_generator: nil)
|
@@ -334,9 +333,7 @@ module Polars
|
|
334
333
|
# # │ i64 ┆ i64 ┆ list[f32] │
|
335
334
|
# # ╞═════╪═════╪════════════╡
|
336
335
|
# # │ 1 ┆ 4 ┆ [1.0, 2.0] │
|
337
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
338
336
|
# # │ 8 ┆ 5 ┆ [2.0, 1.0] │
|
339
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
340
337
|
# # │ 3 ┆ 2 ┆ [2.0, 1.0] │
|
341
338
|
# # └─────┴─────┴────────────┘
|
342
339
|
def eval(expr, parallel: false)
|
data/lib/polars/series.rb
CHANGED
@@ -259,6 +259,17 @@ module Polars
|
|
259
259
|
0 - self
|
260
260
|
end
|
261
261
|
|
262
|
+
# Returns an enumerator.
|
263
|
+
#
|
264
|
+
# @return [Object]
|
265
|
+
def each
|
266
|
+
return to_enum(:each) unless block_given?
|
267
|
+
|
268
|
+
length.times do |i|
|
269
|
+
yield self[i]
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
262
273
|
# Returns elements of the Series.
|
263
274
|
#
|
264
275
|
# @return [Object]
|
@@ -432,15 +443,10 @@ module Polars
|
|
432
443
|
# # │ str ┆ f64 │
|
433
444
|
# # ╞════════════╪══════════╡
|
434
445
|
# # │ min ┆ 1.0 │
|
435
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
|
436
446
|
# # │ max ┆ 5.0 │
|
437
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
|
438
447
|
# # │ null_count ┆ 0.0 │
|
439
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
|
440
448
|
# # │ mean ┆ 3.0 │
|
441
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
|
442
449
|
# # │ std ┆ 1.581139 │
|
443
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
|
444
450
|
# # │ count ┆ 5.0 │
|
445
451
|
# # └────────────┴──────────┘
|
446
452
|
#
|
@@ -455,9 +461,7 @@ module Polars
|
|
455
461
|
# # │ str ┆ i64 │
|
456
462
|
# # ╞════════════╪═══════╡
|
457
463
|
# # │ unique ┆ 4 │
|
458
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
459
464
|
# # │ null_count ┆ 1 │
|
460
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
461
465
|
# # │ count ┆ 5 │
|
462
466
|
# # └────────────┴───────┘
|
463
467
|
def describe
|
@@ -660,13 +664,11 @@ module Polars
|
|
660
664
|
# # │ u8 ┆ u8 ┆ u8 │
|
661
665
|
# # ╞═════╪═════╪═════╡
|
662
666
|
# # │ 1 ┆ 0 ┆ 0 │
|
663
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
664
667
|
# # │ 0 ┆ 1 ┆ 0 │
|
665
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
666
668
|
# # │ 0 ┆ 0 ┆ 1 │
|
667
669
|
# # └─────┴─────┴─────┘
|
668
|
-
def to_dummies
|
669
|
-
Utils.wrap_df(_s.to_dummies)
|
670
|
+
def to_dummies(separator: "_")
|
671
|
+
Utils.wrap_df(_s.to_dummies(separator))
|
670
672
|
end
|
671
673
|
|
672
674
|
# Count the unique values in a Series.
|
@@ -687,9 +689,7 @@ module Polars
|
|
687
689
|
# # │ i64 ┆ u32 │
|
688
690
|
# # ╞═════╪════════╡
|
689
691
|
# # │ 1 ┆ 1 │
|
690
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
691
692
|
# # │ 2 ┆ 2 │
|
692
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
693
693
|
# # │ 3 ┆ 1 │
|
694
694
|
# # └─────┴────────┘
|
695
695
|
def value_counts(sort: false)
|
@@ -1285,8 +1285,12 @@ module Polars
|
|
1285
1285
|
# Expression or scalar value.
|
1286
1286
|
#
|
1287
1287
|
# @return [Integer]
|
1288
|
-
def search_sorted(element)
|
1289
|
-
|
1288
|
+
def search_sorted(element, side: "any")
|
1289
|
+
if element.is_a?(Integer) || element.is_a?(Float)
|
1290
|
+
return Polars.select(Polars.lit(self).search_sorted(element, side: side)).item
|
1291
|
+
end
|
1292
|
+
element = Series.new(element)
|
1293
|
+
Polars.select(Polars.lit(self).search_sorted(element, side: side)).to_series
|
1290
1294
|
end
|
1291
1295
|
|
1292
1296
|
# Get unique elements in series.
|
@@ -1500,7 +1504,7 @@ module Polars
|
|
1500
1504
|
# sets = Polars::Series.new("sets", [[1, 2, 3], [1, 2], [9, 10]])
|
1501
1505
|
# # =>
|
1502
1506
|
# # shape: (3,)
|
1503
|
-
# # Series: 'sets' [list]
|
1507
|
+
# # Series: 'sets' [list[i64]]
|
1504
1508
|
# # [
|
1505
1509
|
# # [1, 2, 3]
|
1506
1510
|
# # [1, 2]
|
data/lib/polars/string_expr.rb
CHANGED
@@ -22,6 +22,9 @@ module Polars
|
|
22
22
|
# @param exact [Boolean]
|
23
23
|
# - If true, require an exact format match.
|
24
24
|
# - If false, allow the format to match anywhere in the target string.
|
25
|
+
# @param utc [Boolean]
|
26
|
+
# Parse timezone aware datetimes as UTC. This may be useful if you have data
|
27
|
+
# with mixed offsets.
|
25
28
|
#
|
26
29
|
# @return [Expr]
|
27
30
|
#
|
@@ -57,14 +60,11 @@ module Polars
|
|
57
60
|
# # │ date │
|
58
61
|
# # ╞════════════╡
|
59
62
|
# # │ 2021-04-22 │
|
60
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌┤
|
61
63
|
# # │ 2022-01-04 │
|
62
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌┤
|
63
64
|
# # │ 2022-01-31 │
|
64
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌┤
|
65
65
|
# # │ 2001-07-08 │
|
66
66
|
# # └────────────┘
|
67
|
-
def strptime(datatype, fmt = nil, strict: true, exact: true, cache: true, tz_aware: false)
|
67
|
+
def strptime(datatype, fmt = nil, strict: true, exact: true, cache: true, tz_aware: false, utc: false)
|
68
68
|
if !Utils.is_polars_dtype(datatype)
|
69
69
|
raise ArgumentError, "expected: {DataType} got: #{datatype}"
|
70
70
|
end
|
@@ -74,7 +74,7 @@ module Polars
|
|
74
74
|
elsif datatype == :datetime
|
75
75
|
# TODO fix
|
76
76
|
tu = nil # datatype.tu
|
77
|
-
dtcol = Utils.wrap_expr(_rbexpr.str_parse_datetime(fmt, strict, exact, cache, tz_aware))
|
77
|
+
dtcol = Utils.wrap_expr(_rbexpr.str_parse_datetime(fmt, strict, exact, cache, tz_aware, utc))
|
78
78
|
if tu.nil?
|
79
79
|
dtcol
|
80
80
|
else
|
@@ -111,11 +111,8 @@ module Polars
|
|
111
111
|
# # │ str ┆ u32 ┆ u32 │
|
112
112
|
# # ╞══════╪════════╪════════╡
|
113
113
|
# # │ Café ┆ 5 ┆ 4 │
|
114
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
115
114
|
# # │ null ┆ null ┆ null │
|
116
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
117
115
|
# # │ 345 ┆ 3 ┆ 3 │
|
118
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
119
116
|
# # │ 東京 ┆ 6 ┆ 2 │
|
120
117
|
# # └──────┴────────┴────────┘
|
121
118
|
def lengths
|
@@ -146,11 +143,8 @@ module Polars
|
|
146
143
|
# # │ str ┆ u32 ┆ u32 │
|
147
144
|
# # ╞══════╪════════╪════════╡
|
148
145
|
# # │ Café ┆ 5 ┆ 4 │
|
149
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
150
146
|
# # │ null ┆ null ┆ null │
|
151
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
152
147
|
# # │ 345 ┆ 3 ┆ 3 │
|
153
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
154
148
|
# # │ 東京 ┆ 6 ┆ 2 │
|
155
149
|
# # └──────┴────────┴────────┘
|
156
150
|
def n_chars
|
@@ -195,7 +189,6 @@ module Polars
|
|
195
189
|
# # │ str │
|
196
190
|
# # ╞═════╡
|
197
191
|
# # │ CAT │
|
198
|
-
# # ├╌╌╌╌╌┤
|
199
192
|
# # │ DOG │
|
200
193
|
# # └─────┘
|
201
194
|
def to_uppercase
|
@@ -217,7 +210,6 @@ module Polars
|
|
217
210
|
# # │ str │
|
218
211
|
# # ╞═════╡
|
219
212
|
# # │ cat │
|
220
|
-
# # ├╌╌╌╌╌┤
|
221
213
|
# # │ dog │
|
222
214
|
# # └─────┘
|
223
215
|
def to_lowercase
|
@@ -242,9 +234,7 @@ module Polars
|
|
242
234
|
# # │ str │
|
243
235
|
# # ╞═══════╡
|
244
236
|
# # │ lead │
|
245
|
-
# # ├╌╌╌╌╌╌╌┤
|
246
237
|
# # │ trail │
|
247
|
-
# # ├╌╌╌╌╌╌╌┤
|
248
238
|
# # │ both │
|
249
239
|
# # └───────┘
|
250
240
|
def strip(matches = nil)
|
@@ -272,9 +262,7 @@ module Polars
|
|
272
262
|
# # │ str │
|
273
263
|
# # ╞════════╡
|
274
264
|
# # │ lead │
|
275
|
-
# # ├╌╌╌╌╌╌╌╌┤
|
276
265
|
# # │ trail │
|
277
|
-
# # ├╌╌╌╌╌╌╌╌┤
|
278
266
|
# # │ both │
|
279
267
|
# # └────────┘
|
280
268
|
def lstrip(matches = nil)
|
@@ -302,9 +290,7 @@ module Polars
|
|
302
290
|
# # │ str │
|
303
291
|
# # ╞═══════╡
|
304
292
|
# # │ lead │
|
305
|
-
# # ├╌╌╌╌╌╌╌┤
|
306
293
|
# # │ trail │
|
307
|
-
# # ├╌╌╌╌╌╌╌┤
|
308
294
|
# # │ both │
|
309
295
|
# # └───────┘
|
310
296
|
def rstrip(matches = nil)
|
@@ -343,21 +329,13 @@ module Polars
|
|
343
329
|
# # │ str │
|
344
330
|
# # ╞═════════╡
|
345
331
|
# # │ -0010 │
|
346
|
-
# # ├╌╌╌╌╌╌╌╌╌┤
|
347
332
|
# # │ -0001 │
|
348
|
-
# # ├╌╌╌╌╌╌╌╌╌┤
|
349
333
|
# # │ 00000 │
|
350
|
-
# # ├╌╌╌╌╌╌╌╌╌┤
|
351
334
|
# # │ 00001 │
|
352
|
-
# # ├╌╌╌╌╌╌╌╌╌┤
|
353
335
|
# # │ ... │
|
354
|
-
# # ├╌╌╌╌╌╌╌╌╌┤
|
355
336
|
# # │ 10000 │
|
356
|
-
# # ├╌╌╌╌╌╌╌╌╌┤
|
357
337
|
# # │ 100000 │
|
358
|
-
# # ├╌╌╌╌╌╌╌╌╌┤
|
359
338
|
# # │ 1000000 │
|
360
|
-
# # ├╌╌╌╌╌╌╌╌╌┤
|
361
339
|
# # │ null │
|
362
340
|
# # └─────────┘
|
363
341
|
def zfill(alignment)
|
@@ -388,11 +366,8 @@ module Polars
|
|
388
366
|
# # │ str │
|
389
367
|
# # ╞══════════════╡
|
390
368
|
# # │ cow***** │
|
391
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
392
369
|
# # │ monkey** │
|
393
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
394
370
|
# # │ null │
|
395
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
396
371
|
# # │ hippopotamus │
|
397
372
|
# # └──────────────┘
|
398
373
|
def ljust(width, fillchar = " ")
|
@@ -423,11 +398,8 @@ module Polars
|
|
423
398
|
# # │ str │
|
424
399
|
# # ╞══════════════╡
|
425
400
|
# # │ *****cow │
|
426
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
427
401
|
# # │ **monkey │
|
428
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
429
402
|
# # │ null │
|
430
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
431
403
|
# # │ hippopotamus │
|
432
404
|
# # └──────────────┘
|
433
405
|
def rjust(width, fillchar = " ")
|
@@ -460,15 +432,13 @@ module Polars
|
|
460
432
|
# # │ str ┆ bool ┆ bool │
|
461
433
|
# # ╞═════════════╪═══════╪═════════╡
|
462
434
|
# # │ Crab ┆ false ┆ false │
|
463
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
|
464
435
|
# # │ cat and dog ┆ true ┆ false │
|
465
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
|
466
436
|
# # │ rab$bit ┆ true ┆ true │
|
467
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
|
468
437
|
# # │ null ┆ null ┆ null │
|
469
438
|
# # └─────────────┴───────┴─────────┘
|
470
|
-
def contains(pattern, literal: false)
|
471
|
-
Utils.
|
439
|
+
def contains(pattern, literal: false, strict: true)
|
440
|
+
pattern = Utils.expr_to_lit_or_expr(pattern, str_to_lit: true)._rbexpr
|
441
|
+
Utils.wrap_expr(_rbexpr.str_contains(pattern, literal, strict))
|
472
442
|
end
|
473
443
|
|
474
444
|
# Check if string values end with a substring.
|
@@ -491,9 +461,7 @@ module Polars
|
|
491
461
|
# # │ str ┆ bool │
|
492
462
|
# # ╞════════╪════════════╡
|
493
463
|
# # │ apple ┆ false │
|
494
|
-
# # ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
495
464
|
# # │ mango ┆ true │
|
496
|
-
# # ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
497
465
|
# # │ null ┆ null │
|
498
466
|
# # └────────┴────────────┘
|
499
467
|
#
|
@@ -509,6 +477,7 @@ module Polars
|
|
509
477
|
# # │ mango │
|
510
478
|
# # └────────┘
|
511
479
|
def ends_with(sub)
|
480
|
+
sub = Utils.expr_to_lit_or_expr(sub, str_to_lit: true)._rbexpr
|
512
481
|
Utils.wrap_expr(_rbexpr.str_ends_with(sub))
|
513
482
|
end
|
514
483
|
|
@@ -532,9 +501,7 @@ module Polars
|
|
532
501
|
# # │ str ┆ bool │
|
533
502
|
# # ╞════════╪════════════╡
|
534
503
|
# # │ apple ┆ true │
|
535
|
-
# # ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
536
504
|
# # │ mango ┆ false │
|
537
|
-
# # ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
538
505
|
# # │ null ┆ null │
|
539
506
|
# # └────────┴────────────┘
|
540
507
|
#
|
@@ -550,6 +517,7 @@ module Polars
|
|
550
517
|
# # │ apple │
|
551
518
|
# # └────────┘
|
552
519
|
def starts_with(sub)
|
520
|
+
sub = Utils.expr_to_lit_or_expr(sub, str_to_lit: true)._rbexpr
|
553
521
|
Utils.wrap_expr(_rbexpr.str_starts_with(sub))
|
554
522
|
end
|
555
523
|
|
@@ -579,13 +547,9 @@ module Polars
|
|
579
547
|
# # │ str │
|
580
548
|
# # ╞══════════╡
|
581
549
|
# # │ 1 │
|
582
|
-
# # ├╌╌╌╌╌╌╌╌╌╌┤
|
583
550
|
# # │ null │
|
584
|
-
# # ├╌╌╌╌╌╌╌╌╌╌┤
|
585
551
|
# # │ 2 │
|
586
|
-
# # ├╌╌╌╌╌╌╌╌╌╌┤
|
587
552
|
# # │ 2.1 │
|
588
|
-
# # ├╌╌╌╌╌╌╌╌╌╌┤
|
589
553
|
# # │ true │
|
590
554
|
# # └──────────┘
|
591
555
|
def json_path_match(json_path)
|
@@ -609,18 +573,16 @@ module Polars
|
|
609
573
|
# df.select(Polars.col("encoded").str.decode("hex"))
|
610
574
|
# # =>
|
611
575
|
# # shape: (3, 1)
|
612
|
-
# #
|
613
|
-
# # │ encoded
|
614
|
-
# # │ ---
|
615
|
-
# # │
|
616
|
-
# #
|
617
|
-
# # │
|
618
|
-
# #
|
619
|
-
# # │
|
620
|
-
# #
|
621
|
-
|
622
|
-
# # └─────────┘
|
623
|
-
def decode(encoding, strict: false)
|
576
|
+
# # ┌───────────────┐
|
577
|
+
# # │ encoded │
|
578
|
+
# # │ --- │
|
579
|
+
# # │ binary │
|
580
|
+
# # ╞═══════════════╡
|
581
|
+
# # │ [binary data] │
|
582
|
+
# # │ [binary data] │
|
583
|
+
# # │ null │
|
584
|
+
# # └───────────────┘
|
585
|
+
def decode(encoding, strict: true)
|
624
586
|
if encoding == "hex"
|
625
587
|
Utils.wrap_expr(_rbexpr.str_hex_decode(strict))
|
626
588
|
elsif encoding == "base64"
|
@@ -648,9 +610,7 @@ module Polars
|
|
648
610
|
# # │ str │
|
649
611
|
# # ╞═════════╡
|
650
612
|
# # │ 666f6f │
|
651
|
-
# # ├╌╌╌╌╌╌╌╌╌┤
|
652
613
|
# # │ 626172 │
|
653
|
-
# # ├╌╌╌╌╌╌╌╌╌┤
|
654
614
|
# # │ null │
|
655
615
|
# # └─────────┘
|
656
616
|
def encode(encoding)
|
@@ -689,7 +649,6 @@ module Polars
|
|
689
649
|
# # │ str │
|
690
650
|
# # ╞═════╡
|
691
651
|
# # │ 123 │
|
692
|
-
# # ├╌╌╌╌╌┤
|
693
652
|
# # │ 678 │
|
694
653
|
# # └─────┘
|
695
654
|
def extract(pattern, group_index: 1)
|
@@ -721,7 +680,6 @@ module Polars
|
|
721
680
|
# # │ list[str] │
|
722
681
|
# # ╞════════════════╡
|
723
682
|
# # │ ["123", "45"] │
|
724
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
725
683
|
# # │ ["678", "910"] │
|
726
684
|
# # └────────────────┘
|
727
685
|
def extract_all(pattern)
|
@@ -751,7 +709,6 @@ module Polars
|
|
751
709
|
# # │ u32 │
|
752
710
|
# # ╞══════════════╡
|
753
711
|
# # │ 5 │
|
754
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
755
712
|
# # │ 6 │
|
756
713
|
# # └──────────────┘
|
757
714
|
def count_match(pattern)
|
@@ -778,9 +735,7 @@ module Polars
|
|
778
735
|
# # │ list[str] │
|
779
736
|
# # ╞═══════════════════════╡
|
780
737
|
# # │ ["foo", "bar"] │
|
781
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
782
738
|
# # │ ["foo-bar"] │
|
783
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
784
739
|
# # │ ["foo", "bar", "baz"] │
|
785
740
|
# # └───────────────────────┘
|
786
741
|
def split(by, inclusive: false)
|
@@ -821,11 +776,8 @@ module Polars
|
|
821
776
|
# # │ struct[2] │
|
822
777
|
# # ╞═════════════╡
|
823
778
|
# # │ {"a","1"} │
|
824
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
825
779
|
# # │ {null,null} │
|
826
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
827
780
|
# # │ {"c",null} │
|
828
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
829
781
|
# # │ {"d","4"} │
|
830
782
|
# # └─────────────┘
|
831
783
|
def split_exact(by, n, inclusive: false)
|
@@ -860,11 +812,8 @@ module Polars
|
|
860
812
|
# # │ struct[2] │
|
861
813
|
# # ╞═══════════════════╡
|
862
814
|
# # │ {"foo","bar"} │
|
863
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
864
815
|
# # │ {null,null} │
|
865
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
866
816
|
# # │ {"foo-bar",null} │
|
867
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
868
817
|
# # │ {"foo","bar baz"} │
|
869
818
|
# # └───────────────────┘
|
870
819
|
def splitn(by, n)
|
@@ -895,7 +844,6 @@ module Polars
|
|
895
844
|
# # │ i64 ┆ str │
|
896
845
|
# # ╞═════╪════════╡
|
897
846
|
# # │ 1 ┆ 123ABC │
|
898
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
899
847
|
# # │ 2 ┆ abc456 │
|
900
848
|
# # └─────┴────────┘
|
901
849
|
def replace(pattern, value, literal: false)
|
@@ -926,7 +874,6 @@ module Polars
|
|
926
874
|
# # │ i64 ┆ str │
|
927
875
|
# # ╞═════╪═════════╡
|
928
876
|
# # │ 1 ┆ -bc-bc │
|
929
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
|
930
877
|
# # │ 2 ┆ 123-123 │
|
931
878
|
# # └─────┴─────────┘
|
932
879
|
def replace_all(pattern, value, literal: false)
|
@@ -958,11 +905,8 @@ module Polars
|
|
958
905
|
# # │ str ┆ str │
|
959
906
|
# # ╞═════════════╪══════════╡
|
960
907
|
# # │ pear ┆ ear │
|
961
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
|
962
908
|
# # │ null ┆ null │
|
963
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
|
964
909
|
# # │ papaya ┆ aya │
|
965
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
|
966
910
|
# # │ dragonfruit ┆ uit │
|
967
911
|
# # └─────────────┴──────────┘
|
968
912
|
def slice(offset, length = nil)
|