polars-df 0.20.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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +27 -0
  3. data/Cargo.lock +192 -186
  4. data/LICENSE-THIRD-PARTY.txt +2153 -2532
  5. data/LICENSE.txt +1 -1
  6. data/lib/polars/3.2/polars.so +0 -0
  7. data/lib/polars/3.3/polars.so +0 -0
  8. data/lib/polars/3.4/polars.so +0 -0
  9. data/lib/polars/array_expr.rb +382 -3
  10. data/lib/polars/array_name_space.rb +281 -0
  11. data/lib/polars/binary_expr.rb +67 -0
  12. data/lib/polars/binary_name_space.rb +43 -0
  13. data/lib/polars/cat_expr.rb +224 -0
  14. data/lib/polars/cat_name_space.rb +130 -32
  15. data/lib/polars/catalog/unity/catalog_info.rb +20 -0
  16. data/lib/polars/catalog/unity/column_info.rb +31 -0
  17. data/lib/polars/catalog/unity/namespace_info.rb +21 -0
  18. data/lib/polars/catalog/unity/table_info.rb +50 -0
  19. data/lib/polars/catalog.rb +448 -0
  20. data/lib/polars/config.rb +2 -2
  21. data/lib/polars/convert.rb +12 -2
  22. data/lib/polars/data_frame.rb +834 -48
  23. data/lib/polars/data_type_expr.rb +52 -0
  24. data/lib/polars/data_types.rb +61 -5
  25. data/lib/polars/date_time_expr.rb +251 -0
  26. data/lib/polars/date_time_name_space.rb +299 -0
  27. data/lib/polars/exceptions.rb +7 -2
  28. data/lib/polars/expr.rb +1247 -211
  29. data/lib/polars/functions/col.rb +6 -5
  30. data/lib/polars/functions/datatype.rb +21 -0
  31. data/lib/polars/functions/lazy.rb +127 -15
  32. data/lib/polars/functions/repeat.rb +4 -0
  33. data/lib/polars/io/csv.rb +19 -1
  34. data/lib/polars/io/json.rb +16 -0
  35. data/lib/polars/io/ndjson.rb +13 -0
  36. data/lib/polars/io/parquet.rb +70 -66
  37. data/lib/polars/io/scan_options.rb +47 -0
  38. data/lib/polars/lazy_frame.rb +1099 -95
  39. data/lib/polars/list_expr.rb +400 -11
  40. data/lib/polars/list_name_space.rb +321 -5
  41. data/lib/polars/meta_expr.rb +71 -22
  42. data/lib/polars/name_expr.rb +36 -0
  43. data/lib/polars/scan_cast_options.rb +64 -0
  44. data/lib/polars/schema.rb +84 -3
  45. data/lib/polars/selector.rb +210 -0
  46. data/lib/polars/selectors.rb +932 -203
  47. data/lib/polars/series.rb +1083 -63
  48. data/lib/polars/string_expr.rb +435 -9
  49. data/lib/polars/string_name_space.rb +729 -45
  50. data/lib/polars/struct_expr.rb +103 -0
  51. data/lib/polars/struct_name_space.rb +19 -1
  52. data/lib/polars/utils/parse.rb +40 -0
  53. data/lib/polars/utils/various.rb +18 -1
  54. data/lib/polars/utils.rb +9 -1
  55. data/lib/polars/version.rb +1 -1
  56. data/lib/polars.rb +10 -0
  57. metadata +12 -2
@@ -57,6 +57,36 @@ module Polars
57
57
  Utils.wrap_expr(_rbexpr.struct_field_by_name(name))
58
58
  end
59
59
 
60
+ # Expand the struct into its individual fields.
61
+ #
62
+ # Alias for `Expr.struct.field("*")`.
63
+ #
64
+ # @return [Expr]
65
+ #
66
+ # @example
67
+ # df = Polars::DataFrame.new(
68
+ # {
69
+ # "aaa" => [1, 2],
70
+ # "bbb" => ["ab", "cd"],
71
+ # "ccc" => [true, nil],
72
+ # "ddd" => [[1, 2], [3]]
73
+ # }
74
+ # ).select(Polars.struct("aaa", "bbb", "ccc", "ddd").alias("struct_col"))
75
+ # df.select(Polars.col("struct_col").struct.unnest)
76
+ # # =>
77
+ # # shape: (2, 4)
78
+ # # ┌─────┬─────┬──────┬───────────┐
79
+ # # │ aaa ┆ bbb ┆ ccc ┆ ddd │
80
+ # # │ --- ┆ --- ┆ --- ┆ --- │
81
+ # # │ i64 ┆ str ┆ bool ┆ list[i64] │
82
+ # # ╞═════╪═════╪══════╪═══════════╡
83
+ # # │ 1 ┆ ab ┆ true ┆ [1, 2] │
84
+ # # │ 2 ┆ cd ┆ null ┆ [3] │
85
+ # # └─────┴─────┴──────┴───────────┘
86
+ def unnest
87
+ field("*")
88
+ end
89
+
60
90
  # Rename the fields of the struct.
61
91
  #
62
92
  # @param names [Array]
@@ -94,5 +124,78 @@ module Polars
94
124
  def rename_fields(names)
95
125
  Utils.wrap_expr(_rbexpr.struct_rename_fields(names))
96
126
  end
127
+
128
+ # Convert this struct to a string column with json values.
129
+ #
130
+ # @return [Expr]
131
+ #
132
+ # @example
133
+ # Polars::DataFrame.new(
134
+ # {"a" => [{"a" => [1, 2], "b" => [45]}, {"a" => [9, 1, 3], "b" => nil}]}
135
+ # ).with_columns(Polars.col("a").struct.json_encode.alias("encoded"))
136
+ # # =>
137
+ # # shape: (2, 2)
138
+ # # ┌──────────────────┬────────────────────────┐
139
+ # # │ a ┆ encoded │
140
+ # # │ --- ┆ --- │
141
+ # # │ struct[2] ┆ str │
142
+ # # ╞══════════════════╪════════════════════════╡
143
+ # # │ {[1, 2],[45]} ┆ {"a":[1,2],"b":[45]} │
144
+ # # │ {[9, 1, 3],null} ┆ {"a":[9,1,3],"b":null} │
145
+ # # └──────────────────┴────────────────────────┘
146
+ def json_encode
147
+ Utils.wrap_expr(_rbexpr.struct_json_encode)
148
+ end
149
+
150
+ # Add or overwrite fields of this struct.
151
+ #
152
+ # This is similar to `with_columns` on `DataFrame`.
153
+ #
154
+ # @param exprs [Array]
155
+ # Field(s) to add, specified as positional arguments.
156
+ # Accepts expression input. Strings are parsed as column names, other
157
+ # non-expression inputs are parsed as literals.
158
+ # @param named_exprs [Hash]
159
+ # Additional fields to add, specified as keyword arguments.
160
+ # The columns will be renamed to the keyword used.
161
+ #
162
+ # @return [Expr]
163
+ #
164
+ # @example
165
+ # df = Polars::DataFrame.new(
166
+ # {
167
+ # "coords" => [{"x" => 1, "y" => 4}, {"x" => 4, "y" => 9}, {"x" => 9, "y" => 16}],
168
+ # "multiply" => [10, 2, 3]
169
+ # }
170
+ # )
171
+ # df.with_columns(
172
+ # Polars.col("coords").struct.with_fields(
173
+ # Polars.field("x").sqrt,
174
+ # y_mul: Polars.field("y") * Polars.col("multiply")
175
+ # )
176
+ # )
177
+ # # =>
178
+ # # shape: (3, 2)
179
+ # # ┌─────────────┬──────────┐
180
+ # # │ coords ┆ multiply │
181
+ # # │ --- ┆ --- │
182
+ # # │ struct[3] ┆ i64 │
183
+ # # ╞═════════════╪══════════╡
184
+ # # │ {1.0,4,40} ┆ 10 │
185
+ # # │ {2.0,9,18} ┆ 2 │
186
+ # # │ {3.0,16,48} ┆ 3 │
187
+ # # └─────────────┴──────────┘
188
+ def with_fields(
189
+ *exprs,
190
+ **named_exprs
191
+ )
192
+ structify = ENV.fetch("POLARS_AUTO_STRUCTIFY", 0).to_i != 0
193
+
194
+ rbexprs = Utils.parse_into_list_of_expressions(
195
+ *exprs, **named_exprs, __structify: structify
196
+ )
197
+
198
+ Utils.wrap_expr(_rbexpr.struct_with_fields(rbexprs))
199
+ end
97
200
  end
98
201
  end
@@ -80,7 +80,7 @@ module Polars
80
80
  super
81
81
  end
82
82
 
83
- # Get the struct definition as a name/dtype schema dict.
83
+ # Get the struct definition as a name/dtype schema hash.
84
84
  #
85
85
  # @return [Object]
86
86
  #
@@ -116,5 +116,23 @@ module Polars
116
116
  def unnest
117
117
  Utils.wrap_df(_s.struct_unnest)
118
118
  end
119
+
120
+ # Convert this struct to a string column with json values.
121
+ #
122
+ # @return [Series]
123
+ #
124
+ # @example
125
+ # s = Polars::Series.new("a", [{"a" => [1, 2], "b" => [45]}, {"a" => [9, 1, 3], "b" => nil}])
126
+ # s.struct.json_encode
127
+ # # =>
128
+ # # shape: (2,)
129
+ # # Series: 'a' [str]
130
+ # # [
131
+ # # "{"a":[1,2],"b":[45]}"
132
+ # # "{"a":[9,1,3],"b":null}"
133
+ # # ]
134
+ def json_encode
135
+ super
136
+ end
119
137
  end
120
138
  end
@@ -33,6 +33,46 @@ module Polars
33
33
  exprs
34
34
  end
35
35
 
36
+ def self.parse_into_selector(i, strict: true)
37
+ if i.is_a?(::String)
38
+ cs = Selectors
39
+
40
+ cs.by_name([i], require_all: strict)
41
+ elsif i.is_a?(Selector)
42
+ i
43
+ elsif i.is_a?(Expr)
44
+ i.meta.as_selector
45
+ else
46
+ msg = "cannot turn #{i.inspect} into selector"
47
+ raise TypeError, msg
48
+ end
49
+ end
50
+
51
+ def self.parse_list_into_selector(inputs, strict: true)
52
+ if inputs.is_a?(::Array)
53
+ cs = Selectors
54
+
55
+ columns = inputs.select { |i| i.is_a?(::String) }
56
+ selector = cs.by_name(columns, require_all: strict)
57
+
58
+ if columns.length == inputs.length
59
+ return selector
60
+ end
61
+
62
+ # A bit cleaner
63
+ if columns.length == 0
64
+ selector = cs.empty
65
+ end
66
+
67
+ inputs.each do |i|
68
+ selector |= parse_into_selector(i, strict: strict)
69
+ end
70
+ selector
71
+ else
72
+ parse_into_selector(inputs, strict: strict)
73
+ end
74
+ end
75
+
36
76
  def self._parse_positional_inputs(inputs, structify: false)
37
77
  inputs_iter = _parse_inputs_as_iterable(inputs)
38
78
  inputs_iter.map { |e| parse_into_expression(e, structify: structify) }
@@ -16,7 +16,10 @@ module Polars
16
16
  val.is_a?(::Array) && val.all? { |x| pathlike?(x) }
17
17
  end
18
18
 
19
- def self.is_bool_sequence(val)
19
+ def self.is_bool_sequence(val, include_series: false)
20
+ if include_series && val.is_a?(Series)
21
+ return val.dtype == Boolean
22
+ end
20
23
  val.is_a?(::Array) && val.all? { |x| x == true || x == false }
21
24
  end
22
25
 
@@ -24,6 +27,10 @@ module Polars
24
27
  val.is_a?(::Array) && _is_iterable_of(val, Integer)
25
28
  end
26
29
 
30
+ def self.is_sequence(val, include_series: false)
31
+ val.is_a?(::Array) || (include_series && val.is_a?(Series))
32
+ end
33
+
27
34
  def self.is_str_sequence(val, allow_str: false)
28
35
  if allow_str == false && val.is_a?(::String)
29
36
  false
@@ -76,5 +83,15 @@ module Polars
76
83
  end
77
84
  values
78
85
  end
86
+
87
+ def self.require_same_type(current, other)
88
+ if !other.is_a?(current.class) && !current.is_a?(other.class)
89
+ msg = (
90
+ "expected `other` to be a #{current.inspect}, " +
91
+ "not #{other.inspect}"
92
+ )
93
+ raise TypeError, msg
94
+ end
95
+ end
79
96
  end
80
97
  end
data/lib/polars/utils.rb CHANGED
@@ -107,7 +107,7 @@ module Polars
107
107
  end
108
108
 
109
109
  def self.is_selector(obj)
110
- obj.is_a?(Selectors::SelectorProxy)
110
+ obj.is_a?(Selector)
111
111
  end
112
112
 
113
113
  def self.expand_selector(target, selector, strict: true)
@@ -161,5 +161,13 @@ module Polars
161
161
  # escapes _only_ those metachars with meaning to the rust regex crate
162
162
  Plr.re_escape(s)
163
163
  end
164
+
165
+ def self.parse_into_datatype_expr(input)
166
+ if input.is_a?(DataTypeExpr)
167
+ input
168
+ else
169
+ parse_into_dtype(input).to_dtype_expr
170
+ end
171
+ end
164
172
  end
165
173
  end
@@ -1,4 +1,4 @@
1
1
  module Polars
2
2
  # @private
3
- VERSION = "0.20.0"
3
+ VERSION = "0.21.1"
4
4
  end
data/lib/polars.rb CHANGED
@@ -19,11 +19,17 @@ require_relative "polars/binary_expr"
19
19
  require_relative "polars/binary_name_space"
20
20
  require_relative "polars/cat_expr"
21
21
  require_relative "polars/cat_name_space"
22
+ require_relative "polars/catalog"
23
+ require_relative "polars/catalog/unity/catalog_info"
24
+ require_relative "polars/catalog/unity/column_info"
25
+ require_relative "polars/catalog/unity/namespace_info"
26
+ require_relative "polars/catalog/unity/table_info"
22
27
  require_relative "polars/config"
23
28
  require_relative "polars/convert"
24
29
  require_relative "polars/plot"
25
30
  require_relative "polars/data_frame"
26
31
  require_relative "polars/data_types"
32
+ require_relative "polars/data_type_expr"
27
33
  require_relative "polars/data_type_group"
28
34
  require_relative "polars/date_time_expr"
29
35
  require_relative "polars/date_time_name_space"
@@ -32,6 +38,7 @@ require_relative "polars/exceptions"
32
38
  require_relative "polars/expr"
33
39
  require_relative "polars/functions/as_datatype"
34
40
  require_relative "polars/functions/col"
41
+ require_relative "polars/functions/datatype"
35
42
  require_relative "polars/functions/eager"
36
43
  require_relative "polars/functions/lazy"
37
44
  require_relative "polars/functions/len"
@@ -54,6 +61,7 @@ require_relative "polars/io/ipc"
54
61
  require_relative "polars/io/json"
55
62
  require_relative "polars/io/ndjson"
56
63
  require_relative "polars/io/parquet"
64
+ require_relative "polars/io/scan_options"
57
65
  require_relative "polars/lazy_frame"
58
66
  require_relative "polars/lazy_group_by"
59
67
  require_relative "polars/list_expr"
@@ -61,7 +69,9 @@ require_relative "polars/list_name_space"
61
69
  require_relative "polars/meta_expr"
62
70
  require_relative "polars/name_expr"
63
71
  require_relative "polars/rolling_group_by"
72
+ require_relative "polars/scan_cast_options"
64
73
  require_relative "polars/schema"
74
+ require_relative "polars/selector"
65
75
  require_relative "polars/selectors"
66
76
  require_relative "polars/series"
67
77
  require_relative "polars/slice"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polars-df
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 0.21.1
5
5
  platform: x64-mingw-ucrt
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-06-24 00:00:00.000000000 Z
11
+ date: 2025-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bigdecimal
@@ -49,9 +49,15 @@ files:
49
49
  - lib/polars/binary_name_space.rb
50
50
  - lib/polars/cat_expr.rb
51
51
  - lib/polars/cat_name_space.rb
52
+ - lib/polars/catalog.rb
53
+ - lib/polars/catalog/unity/catalog_info.rb
54
+ - lib/polars/catalog/unity/column_info.rb
55
+ - lib/polars/catalog/unity/namespace_info.rb
56
+ - lib/polars/catalog/unity/table_info.rb
52
57
  - lib/polars/config.rb
53
58
  - lib/polars/convert.rb
54
59
  - lib/polars/data_frame.rb
60
+ - lib/polars/data_type_expr.rb
55
61
  - lib/polars/data_type_group.rb
56
62
  - lib/polars/data_types.rb
57
63
  - lib/polars/date_time_expr.rb
@@ -64,6 +70,7 @@ files:
64
70
  - lib/polars/functions/aggregation/vertical.rb
65
71
  - lib/polars/functions/as_datatype.rb
66
72
  - lib/polars/functions/col.rb
73
+ - lib/polars/functions/datatype.rb
67
74
  - lib/polars/functions/eager.rb
68
75
  - lib/polars/functions/lazy.rb
69
76
  - lib/polars/functions/len.rb
@@ -84,6 +91,7 @@ files:
84
91
  - lib/polars/io/json.rb
85
92
  - lib/polars/io/ndjson.rb
86
93
  - lib/polars/io/parquet.rb
94
+ - lib/polars/io/scan_options.rb
87
95
  - lib/polars/lazy_frame.rb
88
96
  - lib/polars/lazy_group_by.rb
89
97
  - lib/polars/list_expr.rb
@@ -92,7 +100,9 @@ files:
92
100
  - lib/polars/name_expr.rb
93
101
  - lib/polars/plot.rb
94
102
  - lib/polars/rolling_group_by.rb
103
+ - lib/polars/scan_cast_options.rb
95
104
  - lib/polars/schema.rb
105
+ - lib/polars/selector.rb
96
106
  - lib/polars/selectors.rb
97
107
  - lib/polars/series.rb
98
108
  - lib/polars/slice.rb