polars-df 0.25.0 → 0.26.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.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -0
  3. data/Cargo.lock +270 -97
  4. data/LICENSE.txt +1 -1
  5. data/README.md +1 -3
  6. data/ext/polars/Cargo.toml +19 -18
  7. data/ext/polars/src/catalog/unity.rs +15 -20
  8. data/ext/polars/src/conversion/any_value.rs +53 -29
  9. data/ext/polars/src/conversion/chunked_array.rs +58 -56
  10. data/ext/polars/src/conversion/datetime.rs +58 -7
  11. data/ext/polars/src/conversion/mod.rs +200 -150
  12. data/ext/polars/src/dataframe/export.rs +15 -12
  13. data/ext/polars/src/dataframe/general.rs +25 -7
  14. data/ext/polars/src/dataframe/map.rs +6 -4
  15. data/ext/polars/src/error.rs +1 -1
  16. data/ext/polars/src/expr/array.rs +0 -24
  17. data/ext/polars/src/expr/datatype.rs +13 -3
  18. data/ext/polars/src/expr/datetime.rs +4 -4
  19. data/ext/polars/src/expr/general.rs +35 -15
  20. data/ext/polars/src/expr/list.rs +0 -26
  21. data/ext/polars/src/expr/rolling.rs +24 -0
  22. data/ext/polars/src/functions/business.rs +2 -2
  23. data/ext/polars/src/functions/io.rs +4 -3
  24. data/ext/polars/src/functions/lazy.rs +65 -46
  25. data/ext/polars/src/functions/meta.rs +6 -5
  26. data/ext/polars/src/functions/mod.rs +0 -1
  27. data/ext/polars/src/functions/range.rs +13 -0
  28. data/ext/polars/src/functions/utils.rs +4 -2
  29. data/ext/polars/src/interop/arrow/mod.rs +4 -2
  30. data/ext/polars/src/interop/arrow/to_rb.rs +1 -1
  31. data/ext/polars/src/interop/numo/to_numo_series.rs +26 -25
  32. data/ext/polars/src/io/scan_options.rs +6 -3
  33. data/ext/polars/src/io/sink_options.rs +2 -0
  34. data/ext/polars/src/lazyframe/general.rs +243 -17
  35. data/ext/polars/src/lazyframe/optflags.rs +2 -1
  36. data/ext/polars/src/lib.rs +39 -35
  37. data/ext/polars/src/map/lazy.rs +5 -2
  38. data/ext/polars/src/map/series.rs +19 -18
  39. data/ext/polars/src/on_startup.rs +25 -6
  40. data/ext/polars/src/ruby/numo.rs +3 -4
  41. data/ext/polars/src/ruby/plan_callback.rs +1 -4
  42. data/ext/polars/src/ruby/rb_modules.rs +2 -4
  43. data/ext/polars/src/ruby/ruby_udf.rs +7 -9
  44. data/ext/polars/src/ruby/utils.rs +12 -1
  45. data/ext/polars/src/series/aggregation.rs +13 -1
  46. data/ext/polars/src/series/construction.rs +31 -50
  47. data/ext/polars/src/series/export.rs +33 -38
  48. data/ext/polars/src/series/general.rs +6 -6
  49. data/ext/polars/src/series/map.rs +3 -2
  50. data/ext/polars/src/series/scatter.rs +4 -4
  51. data/ext/polars/src/utils.rs +31 -7
  52. data/lib/polars/array_expr.rb +23 -7
  53. data/lib/polars/array_name_space.rb +16 -2
  54. data/lib/polars/binary_name_space.rb +32 -0
  55. data/lib/polars/collect_batches.rb +4 -0
  56. data/lib/polars/data_frame.rb +144 -11
  57. data/lib/polars/data_type_group.rb +5 -0
  58. data/lib/polars/date_time_expr.rb +91 -3
  59. data/lib/polars/date_time_name_space.rb +7 -1
  60. data/lib/polars/expr.rb +247 -44
  61. data/lib/polars/functions/business.rb +2 -2
  62. data/lib/polars/functions/datatype.rb +30 -0
  63. data/lib/polars/functions/eager.rb +80 -7
  64. data/lib/polars/functions/lazy.rb +97 -2
  65. data/lib/polars/functions/range/linear_space.rb +118 -0
  66. data/lib/polars/io/csv.rb +27 -5
  67. data/lib/polars/io/database.rb +2 -3
  68. data/lib/polars/io/ipc.rb +2 -2
  69. data/lib/polars/io/lines.rb +172 -0
  70. data/lib/polars/io/parquet.rb +1 -1
  71. data/lib/polars/io/sink_options.rb +5 -2
  72. data/lib/polars/lazy_frame.rb +517 -14
  73. data/lib/polars/list_expr.rb +21 -7
  74. data/lib/polars/list_name_space.rb +16 -2
  75. data/lib/polars/query_opt_flags.rb +23 -5
  76. data/lib/polars/selectors.rb +2 -2
  77. data/lib/polars/series.rb +176 -19
  78. data/lib/polars/sql_context.rb +2 -2
  79. data/lib/polars/string_cache.rb +19 -72
  80. data/lib/polars/string_expr.rb +1 -7
  81. data/lib/polars/string_name_space.rb +1 -7
  82. data/lib/polars/utils/construction/series.rb +24 -39
  83. data/lib/polars/utils/convert.rb +16 -6
  84. data/lib/polars/utils/parse.rb +7 -0
  85. data/lib/polars/utils/reduce_balanced.rb +43 -0
  86. data/lib/polars/utils/various.rb +5 -0
  87. data/lib/polars/version.rb +1 -1
  88. data/lib/polars.rb +2 -1
  89. metadata +4 -17
  90. data/ext/polars/src/functions/string_cache.rs +0 -24
@@ -11,6 +11,13 @@ module Polars
11
11
 
12
12
  # Evaluate whether all boolean values in a list are true.
13
13
  #
14
+ # @param ignore_nulls [Boolean]
15
+ # * If set to `true` (default), null values are ignored. If there
16
+ # are no non-null values, the output is `true`.
17
+ # * If set to `false`, [Kleene logic](https://en.wikipedia.org/wiki/Three-valued_logic) is used to deal with nulls:
18
+ # if the column contains any null values and no `false` values,
19
+ # the output is null.
20
+ #
14
21
  # @return [Expr]
15
22
  #
16
23
  # @example
@@ -32,12 +39,19 @@ module Polars
32
39
  # # │ [] ┆ true │
33
40
  # # │ null ┆ null │
34
41
  # # └────────────────┴───────┘
35
- def all
36
- Utils.wrap_expr(_rbexpr.list_all)
42
+ def all(ignore_nulls: true)
43
+ agg(F.element.all(ignore_nulls: ignore_nulls))
37
44
  end
38
45
 
39
46
  # Evaluate whether any boolean value in a list is true.
40
47
  #
48
+ # @param ignore_nulls [Boolean]
49
+ # * If set to `true` (default), null values are ignored. If there
50
+ # are no non-null values, the output is `false`.
51
+ # * If set to `false`, [Kleene logic](https://en.wikipedia.org/wiki/Three-valued_logic) is used to deal with nulls:
52
+ # if the column contains any null values and no `true` values,
53
+ # the output is null.
54
+ #
41
55
  # @return [Expr]
42
56
  #
43
57
  # @example
@@ -59,8 +73,8 @@ module Polars
59
73
  # # │ [] ┆ false │
60
74
  # # │ null ┆ null │
61
75
  # # └────────────────┴───────┘
62
- def any
63
- Utils.wrap_expr(_rbexpr.list_any)
76
+ def any(ignore_nulls: true)
77
+ agg(F.element.any(ignore_nulls: ignore_nulls))
64
78
  end
65
79
 
66
80
  # Get the length of the arrays as `:u32`.
@@ -367,7 +381,7 @@ module Polars
367
381
  # # │ [2, 1, 9] │
368
382
  # # └───────────┘
369
383
  def reverse
370
- Utils.wrap_expr(_rbexpr.list_reverse)
384
+ eval(F.element.reverse)
371
385
  end
372
386
 
373
387
  # Get the unique/distinct values in the list.
@@ -391,7 +405,7 @@ module Polars
391
405
  # # │ [1, 2] │
392
406
  # # └───────────┘
393
407
  def unique(maintain_order: false)
394
- Utils.wrap_expr(_rbexpr.list_unique(maintain_order))
408
+ eval(F.element.unique(maintain_order: maintain_order))
395
409
  end
396
410
 
397
411
  # Count the number of unique values in every sub-lists.
@@ -416,7 +430,7 @@ module Polars
416
430
  # # │ [2, 3, 4] ┆ 3 │
417
431
  # # └───────────┴──────────┘
418
432
  def n_unique
419
- Utils.wrap_expr(_rbexpr.list_n_unique)
433
+ agg(F.element.n_unique)
420
434
  end
421
435
 
422
436
  # Concat the arrays in a Series dtype List in linear time.
@@ -12,6 +12,13 @@ module Polars
12
12
 
13
13
  # Evaluate whether all boolean values in a list are true.
14
14
  #
15
+ # @param ignore_nulls [Boolean]
16
+ # * If set to `true` (default), null values are ignored. If there
17
+ # are no non-null values, the output is `true`.
18
+ # * If set to `false`, [Kleene logic](https://en.wikipedia.org/wiki/Three-valued_logic) is used to deal with nulls:
19
+ # if the column contains any null values and no `false` values,
20
+ # the output is null.
21
+ #
15
22
  # @return [Series]
16
23
  #
17
24
  # @example
@@ -31,12 +38,19 @@ module Polars
31
38
  # # true
32
39
  # # null
33
40
  # # ]
34
- def all
41
+ def all(ignore_nulls: true)
35
42
  super
36
43
  end
37
44
 
38
45
  # Evaluate whether any boolean value in a list is true.
39
46
  #
47
+ # @param ignore_nulls [Boolean]
48
+ # * If set to `true` (default), null values are ignored. If there
49
+ # are no non-null values, the output is `false`.
50
+ # * If set to `false`, [Kleene logic](https://en.wikipedia.org/wiki/Three-valued_logic) is used to deal with nulls:
51
+ # if the column contains any null values and no `true` values,
52
+ # the output is null.
53
+ #
40
54
  # @return [Series]
41
55
  #
42
56
  # @example
@@ -56,7 +70,7 @@ module Polars
56
70
  # # false
57
71
  # # null
58
72
  # # ]
59
- def any
73
+ def any(ignore_nulls: true)
60
74
  super
61
75
  end
62
76
 
@@ -18,7 +18,8 @@ module Polars
18
18
  cluster_with_columns: nil,
19
19
  collapse_joins: nil,
20
20
  check_order_observe: nil,
21
- fast_projection: nil
21
+ fast_projection: nil,
22
+ sort_collapse: nil
22
23
  )
23
24
  self._rboptflags = RbOptFlags.default
24
25
  update(
@@ -31,7 +32,8 @@ module Polars
31
32
  cluster_with_columns: cluster_with_columns,
32
33
  collapse_joins: collapse_joins,
33
34
  check_order_observe: check_order_observe,
34
- fast_projection: fast_projection
35
+ fast_projection: fast_projection,
36
+ sort_collapse: sort_collapse
35
37
  )
36
38
  end
37
39
 
@@ -46,7 +48,8 @@ module Polars
46
48
  cluster_with_columns: nil,
47
49
  collapse_joins: nil,
48
50
  check_order_observe: nil,
49
- fast_projection: nil
51
+ fast_projection: nil,
52
+ sort_collapse: nil
50
53
  )
51
54
  optflags = QueryOptFlags.new
52
55
  optflags.no_optimizations
@@ -60,7 +63,8 @@ module Polars
60
63
  cluster_with_columns: cluster_with_columns,
61
64
  collapse_joins: collapse_joins,
62
65
  check_order_observe: check_order_observe,
63
- fast_projection: fast_projection
66
+ fast_projection: fast_projection,
67
+ sort_collapse: sort_collapse
64
68
  )
65
69
  end
66
70
 
@@ -74,7 +78,8 @@ module Polars
74
78
  cluster_with_columns: nil,
75
79
  collapse_joins: nil,
76
80
  check_order_observe: nil,
77
- fast_projection: nil
81
+ fast_projection: nil,
82
+ sort_collapse: nil
78
83
  )
79
84
  if !predicate_pushdown.nil?
80
85
  self.predicate_pushdown = predicate_pushdown
@@ -112,6 +117,9 @@ module Polars
112
117
  if !fast_projection.nil?
113
118
  self.fast_projection = fast_projection
114
119
  end
120
+ if !sort_collapse.nil?
121
+ self.sort_collapse = sort_collapse
122
+ end
115
123
 
116
124
  self
117
125
  end
@@ -211,6 +219,15 @@ module Polars
211
219
  _rboptflags.fast_projection = value
212
220
  end
213
221
 
222
+ # Collapse sequential sort nodes into a single sort node.
223
+ def sort_collapse
224
+ _rboptflags.sort_collapse
225
+ end
226
+
227
+ def sort_collapse=(value)
228
+ _rboptflags.sort_collapse = value
229
+ end
230
+
214
231
  def to_s
215
232
  <<~STR
216
233
  QueryOptFlags {
@@ -242,5 +259,6 @@ module Polars
242
259
  end
243
260
  end
244
261
 
262
+ # @private
245
263
  DEFAULT_QUERY_OPT_FLAGS = QueryOptFlags.new
246
264
  end
@@ -264,7 +264,7 @@ module Polars
264
264
  re_alpha = ascii_only ? "a-zA-Z" : "\\p{Alphabetic}"
265
265
  re_digit = ascii_only ? "0-9" : "\\d"
266
266
  re_space = ignore_spaces ? " " : ""
267
- return Selector._from_rbselector(
267
+ Selector._from_rbselector(
268
268
  RbSelector.matches("^[#{re_alpha}#{re_digit}#{re_space}]+$")
269
269
  )
270
270
  end
@@ -806,7 +806,7 @@ module Polars
806
806
  # @example Select all struct columns:
807
807
  # df = Polars::DataFrame.new(
808
808
  # {
809
- # "foo" => [{"a": "xx", "b": "z"}, {"a": "x", "b": "y"}],
809
+ # "foo" => [{"a" => "xx", "b" => "z"}, {"a" => "x", "b" => "y"}],
810
810
  # "bar" => [123, 456],
811
811
  # "baz" => [2.0, 5.5]
812
812
  # }
data/lib/polars/series.rb CHANGED
@@ -973,6 +973,29 @@ module Polars
973
973
  _s.min
974
974
  end
975
975
 
976
+ # Get the minimum value in this Series, ordered by an expression.
977
+ #
978
+ # If the by expression has multiple values equal to the minimum it is not
979
+ # defined which value will be chosen.
980
+ #
981
+ # @note
982
+ # This functionality is considered **unstable**. It may be changed
983
+ # at any point without it being considered a breaking change.
984
+ #
985
+ # @param by [Object]
986
+ # Column used to determine the smallest element.
987
+ # Accepts expression input. Strings are parsed as column names.
988
+ #
989
+ # @return [Expr]
990
+ #
991
+ # @example
992
+ # s = Polars::Series.new("a", [-2.0, Float::NAN, 1.0])
993
+ # s.min_by(Polars.col("a").abs)
994
+ # # => 1.0
995
+ def min_by(by)
996
+ to_frame.select_seq(F.col(name).min_by(by)).item
997
+ end
998
+
976
999
  # Get the maximum value in this Series.
977
1000
  #
978
1001
  # @return [Object]
@@ -985,6 +1008,29 @@ module Polars
985
1008
  _s.max
986
1009
  end
987
1010
 
1011
+ # Get the maximum value in this Series, ordered by an expression.
1012
+ #
1013
+ # If the by expression has multiple values equal to the maximum it is not
1014
+ # defined which value will be chosen.
1015
+ #
1016
+ # @note
1017
+ # This functionality is considered **unstable**. It may be changed
1018
+ # at any point without it being considered a breaking change.
1019
+ #
1020
+ # @param by [Object]
1021
+ # Column used to determine the largest element.
1022
+ # Accepts expression input. Strings are parsed as column names.
1023
+ #
1024
+ # @return [Object]
1025
+ #
1026
+ # @example
1027
+ # s = Polars::Series.new("a", [-2.0, Float::NAN, 1.0])
1028
+ # s.max_by(Polars.col("a").abs)
1029
+ # # => -2.0
1030
+ def max_by(by)
1031
+ to_frame.select_seq(F.col(name).max_by(by)).item
1032
+ end
1033
+
988
1034
  # Get maximum value, but propagate/poison encountered NaN values.
989
1035
  #
990
1036
  # @return [Object]
@@ -1138,7 +1184,7 @@ module Polars
1138
1184
  # s.cut([-1, 1], labels: ["a", "b", "c"])
1139
1185
  # # =>
1140
1186
  # # shape: (5,)
1141
- # # Series: 'foo' [cat]
1187
+ # # Series: 'foo' [enum]
1142
1188
  # # [
1143
1189
  # # "a"
1144
1190
  # # "a"
@@ -1155,7 +1201,7 @@ module Polars
1155
1201
  # # ┌─────┬─────────────┬────────────┐
1156
1202
  # # │ foo ┆ break_point ┆ category │
1157
1203
  # # │ --- ┆ --- ┆ --- │
1158
- # # │ i64 ┆ f64 ┆ cat
1204
+ # # │ i64 ┆ f64 ┆ enum
1159
1205
  # # ╞═════╪═════════════╪════════════╡
1160
1206
  # # │ -2 ┆ -1.0 ┆ (-inf, -1] │
1161
1207
  # # │ -1 ┆ -1.0 ┆ (-inf, -1] │
@@ -1469,13 +1515,7 @@ module Polars
1469
1515
  # b = Polars::Series.new([0.65, 0.10, 0.25])
1470
1516
  # b.entropy(normalize: true)
1471
1517
  # # => 0.8568409950394724
1472
- def entropy(base: Math::E, normalize: nil)
1473
- # TODO update
1474
- if normalize.nil?
1475
- warn "The default `normalize` for `entropy` method will change from `false` to `true` in a future version"
1476
- normalize = false
1477
- end
1478
-
1518
+ def entropy(base: Math::E, normalize: true)
1479
1519
  Polars.select(Polars.lit(self).entropy(base: base, normalize: normalize)).to_series[0]
1480
1520
  end
1481
1521
 
@@ -2345,6 +2385,11 @@ module Polars
2345
2385
  #
2346
2386
  # @param indices [Array]
2347
2387
  # Index location used for selection.
2388
+ # @param null_on_oob [Boolean]
2389
+ # Behavior if an index is out of bounds:
2390
+ #
2391
+ # - true -> set the result to null
2392
+ # - false -> raise an error
2348
2393
  #
2349
2394
  # @return [Series]
2350
2395
  #
@@ -2358,7 +2403,7 @@ module Polars
2358
2403
  # # 2
2359
2404
  # # 4
2360
2405
  # # ]
2361
- def gather(indices)
2406
+ def gather(indices, null_on_oob: false)
2362
2407
  super
2363
2408
  end
2364
2409
 
@@ -2395,14 +2440,23 @@ module Polars
2395
2440
 
2396
2441
  # Check if the Series is empty.
2397
2442
  #
2443
+ # @param ignore_nulls [Boolean]
2444
+ # If true a series containing only nulls will also be considered empty.
2445
+ # The default is false.
2446
+ #
2398
2447
  # @return [Boolean]
2399
2448
  #
2400
2449
  # @example
2401
2450
  # s = Polars::Series.new("a", [])
2402
2451
  # s.is_empty
2403
2452
  # # => true
2404
- def is_empty
2405
- len == 0
2453
+ def is_empty(ignore_nulls: false)
2454
+ if ignore_nulls
2455
+ msg = "the `ignore_nulls` parameter of `Series.is_empty()` is considered unstable."
2456
+ Utils.issue_unstable_warning(msg)
2457
+ end
2458
+
2459
+ _s.is_empty(ignore_nulls: ignore_nulls)
2406
2460
  end
2407
2461
  alias_method :empty?, :is_empty
2408
2462
 
@@ -3345,6 +3399,51 @@ module Polars
3345
3399
  super
3346
3400
  end
3347
3401
 
3402
+ # Truncate numeric data toward zero to `decimals` number of decimal places.
3403
+ #
3404
+ # @param decimals [Integer]
3405
+ # Number of decimal places to truncate to.
3406
+ #
3407
+ # @return [Series]
3408
+ #
3409
+ # @note
3410
+ # Truncation discards the fractional part beyond the given number of decimals.
3411
+ # For example, when rounding to 0 decimals 0.25, -0.25, 0.99, and -0.99 will
3412
+ # all round to 0. When rounding to 1 decimal 1.9999 rounds to 1.9 and -1.9999
3413
+ # rounds to -1.9. There is no tiebreak behaviour at midpoint values as there
3414
+ # is with :meth:`round` so 0.5 and -0.5 will also round to 0 when decimals=1.
3415
+ #
3416
+ # @note
3417
+ # This method performs numeric truncation. For truncating temporal
3418
+ # data (dates/datetimes), use :func:`Series.dt.truncate` instead.
3419
+ #
3420
+ # @example
3421
+ # s = Polars::Series.new("a", [1.12345, 2.56789, 3.991234])
3422
+ # s.truncate(2)
3423
+ # # =>
3424
+ # # shape: (3,)
3425
+ # # Series: 'a' [f64]
3426
+ # # [
3427
+ # # 1.12
3428
+ # # 2.56
3429
+ # # 3.99
3430
+ # # ]
3431
+ #
3432
+ # @example
3433
+ # s = Polars::Series.new("a", [-1.78, 2.56, -3.99])
3434
+ # s.truncate(0)
3435
+ # # =>
3436
+ # # shape: (3,)
3437
+ # # Series: 'a' [f64]
3438
+ # # [
3439
+ # # -1.0
3440
+ # # 2.0
3441
+ # # -3.0
3442
+ # # ]
3443
+ def truncate(decimals = 0)
3444
+ super
3445
+ end
3446
+
3348
3447
  # Round underlying floating point data by `decimals` digits.
3349
3448
  #
3350
3449
  # The default rounding mode is "half to even" (also known as "bankers' rounding").
@@ -4281,7 +4380,7 @@ module Polars
4281
4380
  def rolling_sum_by(
4282
4381
  by,
4283
4382
  window_size,
4284
- min_samples: 1,
4383
+ min_samples: 0,
4285
4384
  closed: "right"
4286
4385
  )
4287
4386
  super
@@ -4592,6 +4691,48 @@ module Polars
4592
4691
  super
4593
4692
  end
4594
4693
 
4694
+ # Compute a custom rolling window function.
4695
+ #
4696
+ # @note
4697
+ # This functionality is considered **unstable**. It may be changed
4698
+ # at any point without it being considered a breaking change.
4699
+ #
4700
+ # @param window_size [Integer]
4701
+ # The length of the window in number of elements.
4702
+ # @param weights [Object]
4703
+ # An optional slice with the same length as the window that will be multiplied
4704
+ # elementwise with the values in the window.
4705
+ # @param min_samples [Integer]
4706
+ # The number of values in the window that should be non-null before computing
4707
+ # a result. If set to `nil` (default), it will be set equal to `window_size`.
4708
+ # @param center [Boolean]
4709
+ # Set the labels at the center of the window.
4710
+ #
4711
+ # @return [Series]
4712
+ #
4713
+ # @example
4714
+ # s = Polars::Series.new([11.0, 2.0, 9.0, Float::NAN, 8.0])
4715
+ # s.rolling_map(3) { |v| v.drop_nans.sum }
4716
+ # # =>
4717
+ # # shape: (5,)
4718
+ # # Series: '' [f64]
4719
+ # # [
4720
+ # # null
4721
+ # # null
4722
+ # # 22.0
4723
+ # # 11.0
4724
+ # # 17.0
4725
+ # # ]
4726
+ def rolling_map(
4727
+ window_size,
4728
+ weights: nil,
4729
+ min_samples: nil,
4730
+ center: false,
4731
+ &function
4732
+ )
4733
+ super
4734
+ end
4735
+
4595
4736
  # Compute a rolling median based on another series.
4596
4737
  #
4597
4738
  # @note
@@ -5097,8 +5238,8 @@ module Polars
5097
5238
  # # shape: (2,)
5098
5239
  # # Series: 'a' [i64]
5099
5240
  # # [
5100
- # # 5
5101
5241
  # # 2
5242
+ # # 5
5102
5243
  # # ]
5103
5244
  def sample(
5104
5245
  n: nil,
@@ -5211,13 +5352,18 @@ module Polars
5211
5352
  super
5212
5353
  end
5213
5354
 
5214
- # Reinterpret the underlying bits as a signed/unsigned integer.
5355
+ # Reinterpret the underlying bits as a signed/unsigned integer or float.
5356
+ #
5357
+ # This operation is only allowed for numeric types of the same size.
5358
+ # For lower bits numbers, you can safely use the cast operation.
5215
5359
  #
5216
- # This operation is only allowed for 64bit integers. For lower bits integers,
5217
- # you can safely use that cast operation.
5360
+ # Either `signed` or `dtype` can be specified.
5218
5361
  #
5219
5362
  # @param signed [Boolean]
5220
- # If true, reinterpret as `Polars::Int64`. Otherwise, reinterpret as `Polars::UInt64`.
5363
+ # If true, reinterpret as signed integer. Otherwise, reinterpret
5364
+ # as unsigned integer.
5365
+ # @param dtype [Object]
5366
+ # DataType to reinterpret to.
5221
5367
  #
5222
5368
  # @return [Series]
5223
5369
  #
@@ -5232,7 +5378,18 @@ module Polars
5232
5378
  # # 18446744073709551614
5233
5379
  # # 3
5234
5380
  # # ]
5235
- def reinterpret(signed: true)
5381
+ #
5382
+ # @example
5383
+ # s.reinterpret(dtype: Polars::Int64)
5384
+ # # =>
5385
+ # # shape: (3,)
5386
+ # # Series: 'a' [i64]
5387
+ # # [
5388
+ # # -1152921504606846976
5389
+ # # -2
5390
+ # # 3
5391
+ # # ]
5392
+ def reinterpret(signed: nil, dtype: nil)
5236
5393
  super
5237
5394
  end
5238
5395
 
@@ -73,11 +73,11 @@ module Polars
73
73
  # ctx.execute(
74
74
  # "
75
75
  # SELECT
76
- # MAX(release_year / 10) * 10 AS decade,
76
+ # MAX(release_year // 10) * 10 AS decade,
77
77
  # SUM(gross) AS total_gross,
78
78
  # COUNT(title) AS n_films,
79
79
  # FROM films
80
- # GROUP BY (release_year / 10) -- decade
80
+ # GROUP BY (release_year // 10) -- decade
81
81
  # ORDER BY total_gross DESC
82
82
  # ",
83
83
  # eager: true
@@ -1,30 +1,11 @@
1
1
  module Polars
2
- # Class for enabling and disabling the global string cache.
2
+ # Does nothing.
3
3
  #
4
- # @example Construct two Series using the same global string cache.
5
- # s1 = nil
6
- # s2 = nil
7
- # Polars::StringCache.new do
8
- # s1 = Polars::Series.new("color", ["red", "green", "red"], dtype: Polars::Categorical)
9
- # s2 = Polars::Series.new("color", ["blue", "red", "green"], dtype: Polars::Categorical)
10
- # end
11
- #
12
- # @example As both Series are constructed under the same global string cache, they can be concatenated.
13
- # Polars.concat([s1, s2])
14
- # # =>
15
- # # shape: (6,)
16
- # # Series: 'color' [cat]
17
- # # [
18
- # # "red"
19
- # # "green"
20
- # # "red"
21
- # # "blue"
22
- # # "red"
23
- # # "green"
24
- # # ]
4
+ # @deprecated
5
+ # The string cache was used to maintain the mapping for the Categorical
6
+ # dtype, this is now done through `Polars::Categories`.
25
7
  class StringCache
26
8
  def initialize(&block)
27
- RbStringCacheHolder.hold(&block)
28
9
  end
29
10
  end
30
11
 
@@ -33,69 +14,35 @@ module Polars
33
14
  end
34
15
 
35
16
  module Functions
36
- # Enable the global string cache.
17
+ # Does nothing.
37
18
  #
38
- # `Categorical` columns created under the same global string cache have
39
- # the same underlying physical value when string values are equal. This allows the
40
- # columns to be concatenated or used in a join operation, for example.
19
+ # @deprecated
20
+ # The string cache was used to maintain the mapping for the Categorical
21
+ # dtype, this is now done through `Polars::Categories`.
41
22
  #
42
23
  # @return [nil]
43
- #
44
- # @example Construct two Series using the same global string cache.
45
- # Polars.enable_string_cache
46
- # s1 = Polars::Series.new("color", ["red", "green", "red"], dtype: Polars::Categorical)
47
- # s2 = Polars::Series.new("color", ["blue", "red", "green"], dtype: Polars::Categorical)
48
- # Polars.disable_string_cache
49
- #
50
- # @example As both Series are constructed under the same global string cache, they can be concatenated.
51
- # Polars.concat([s1, s2])
52
- # # =>
53
- # # shape: (6,)
54
- # # Series: 'color' [cat]
55
- # # [
56
- # # "red"
57
- # # "green"
58
- # # "red"
59
- # # "blue"
60
- # # "red"
61
- # # "green"
62
- # # ]
63
24
  def enable_string_cache
64
- Plr.enable_string_cache
65
25
  end
66
26
 
67
- # Disable and clear the global string cache.
27
+ # Does nothing.
68
28
  #
69
- # @return [nil]
29
+ # @deprecated
30
+ # The string cache was used to maintain the mapping for the Categorical
31
+ # dtype, this is now done through `Polars::Categories`.
70
32
  #
71
- # @example Construct two Series using the same global string cache.
72
- # Polars.enable_string_cache
73
- # s1 = Polars::Series.new("color", ["red", "green", "red"], dtype: Polars::Categorical)
74
- # s2 = Polars::Series.new("color", ["blue", "red", "green"], dtype: Polars::Categorical)
75
- # Polars.disable_string_cache
76
- #
77
- # @example As both Series are constructed under the same global string cache, they can be concatenated.
78
- # Polars.concat([s1, s2])
79
- # # =>
80
- # # shape: (6,)
81
- # # Series: 'color' [cat]
82
- # # [
83
- # # "red"
84
- # # "green"
85
- # # "red"
86
- # # "blue"
87
- # # "red"
88
- # # "green"
89
- # # ]
33
+ # @return [nil]
90
34
  def disable_string_cache
91
- Plr.disable_string_cache
92
35
  end
93
36
 
94
- # Check whether the global string cache is enabled.
37
+ # Always returns true.
38
+ #
39
+ # @deprecated
40
+ # The string cache was used to maintain the mapping for the Categorical
41
+ # dtype, this is now done through `Polars::Categories`.
95
42
  #
96
43
  # @return [Boolean]
97
44
  def using_string_cache
98
- Plr.using_string_cache
45
+ true
99
46
  end
100
47
  end
101
48
  end
@@ -378,13 +378,7 @@ module Polars
378
378
  # # ╞══════╡
379
379
  # # │ null │
380
380
  # # └──────┘
381
- def join(delimiter = nil, ignore_nulls: true)
382
- # TODO update
383
- if delimiter.nil?
384
- warn "The default `delimiter` for `join` method will change from `-` to empty string in a future version"
385
- delimiter = "-"
386
- end
387
-
381
+ def join(delimiter = "", ignore_nulls: true)
388
382
  Utils.wrap_expr(_rbexpr.str_join(delimiter, ignore_nulls))
389
383
  end
390
384
 
@@ -1494,13 +1494,7 @@ module Polars
1494
1494
  # # [
1495
1495
  # # null
1496
1496
  # # ]
1497
- def join(delimiter = nil, ignore_nulls: true)
1498
- # TODO update
1499
- if delimiter.nil?
1500
- warn "The default `delimiter` for `join` method will change from `-` to empty string in a future version"
1501
- delimiter = "-"
1502
- end
1503
-
1497
+ def join(delimiter = "", ignore_nulls: true)
1504
1498
  super
1505
1499
  end
1506
1500