polars-df 0.10.0-x86_64-linux-musl
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +175 -0
- data/Cargo.lock +2536 -0
- data/Cargo.toml +6 -0
- data/LICENSE-THIRD-PARTY.txt +38726 -0
- data/LICENSE.txt +20 -0
- data/README.md +437 -0
- data/lib/polars/3.1/polars.so +0 -0
- data/lib/polars/3.2/polars.so +0 -0
- data/lib/polars/3.3/polars.so +0 -0
- data/lib/polars/array_expr.rb +537 -0
- data/lib/polars/array_name_space.rb +423 -0
- data/lib/polars/batched_csv_reader.rb +98 -0
- data/lib/polars/binary_expr.rb +77 -0
- data/lib/polars/binary_name_space.rb +66 -0
- data/lib/polars/cat_expr.rb +72 -0
- data/lib/polars/cat_name_space.rb +125 -0
- data/lib/polars/config.rb +530 -0
- data/lib/polars/convert.rb +93 -0
- data/lib/polars/data_frame.rb +5418 -0
- data/lib/polars/data_types.rb +466 -0
- data/lib/polars/date_time_expr.rb +1444 -0
- data/lib/polars/date_time_name_space.rb +1484 -0
- data/lib/polars/dynamic_group_by.rb +52 -0
- data/lib/polars/exceptions.rb +31 -0
- data/lib/polars/expr.rb +6105 -0
- data/lib/polars/expr_dispatch.rb +22 -0
- data/lib/polars/functions/aggregation/horizontal.rb +246 -0
- data/lib/polars/functions/aggregation/vertical.rb +282 -0
- data/lib/polars/functions/as_datatype.rb +248 -0
- data/lib/polars/functions/col.rb +47 -0
- data/lib/polars/functions/eager.rb +182 -0
- data/lib/polars/functions/lazy.rb +1280 -0
- data/lib/polars/functions/len.rb +49 -0
- data/lib/polars/functions/lit.rb +35 -0
- data/lib/polars/functions/random.rb +16 -0
- data/lib/polars/functions/range/date_range.rb +103 -0
- data/lib/polars/functions/range/int_range.rb +51 -0
- data/lib/polars/functions/repeat.rb +144 -0
- data/lib/polars/functions/whenthen.rb +96 -0
- data/lib/polars/functions.rb +57 -0
- data/lib/polars/group_by.rb +548 -0
- data/lib/polars/io.rb +890 -0
- data/lib/polars/lazy_frame.rb +2833 -0
- data/lib/polars/lazy_group_by.rb +84 -0
- data/lib/polars/list_expr.rb +791 -0
- data/lib/polars/list_name_space.rb +445 -0
- data/lib/polars/meta_expr.rb +222 -0
- data/lib/polars/name_expr.rb +198 -0
- data/lib/polars/plot.rb +109 -0
- data/lib/polars/rolling_group_by.rb +37 -0
- data/lib/polars/series.rb +4527 -0
- data/lib/polars/slice.rb +104 -0
- data/lib/polars/sql_context.rb +194 -0
- data/lib/polars/string_cache.rb +75 -0
- data/lib/polars/string_expr.rb +1519 -0
- data/lib/polars/string_name_space.rb +810 -0
- data/lib/polars/struct_expr.rb +98 -0
- data/lib/polars/struct_name_space.rb +96 -0
- data/lib/polars/testing.rb +507 -0
- data/lib/polars/utils.rb +422 -0
- data/lib/polars/version.rb +4 -0
- data/lib/polars/whenthen.rb +83 -0
- data/lib/polars-df.rb +1 -0
- data/lib/polars.rb +72 -0
- metadata +125 -0
data/lib/polars/utils.rb
ADDED
@@ -0,0 +1,422 @@
|
|
1
|
+
module Polars
|
2
|
+
# @private
|
3
|
+
module Utils
|
4
|
+
DTYPE_TEMPORAL_UNITS = ["ns", "us", "ms"]
|
5
|
+
|
6
|
+
def self.wrap_s(s)
|
7
|
+
Series._from_rbseries(s)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.wrap_df(df)
|
11
|
+
DataFrame._from_rbdf(df)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.wrap_ldf(ldf)
|
15
|
+
LazyFrame._from_rbldf(ldf)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.wrap_expr(rbexpr)
|
19
|
+
Expr._from_rbexpr(rbexpr)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.col(name)
|
23
|
+
Polars.col(name)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.arrlen(obj)
|
27
|
+
if obj.is_a?(Range)
|
28
|
+
# size only works for numeric ranges
|
29
|
+
obj.to_a.length
|
30
|
+
elsif obj.is_a?(::String)
|
31
|
+
nil
|
32
|
+
else
|
33
|
+
obj.length
|
34
|
+
end
|
35
|
+
rescue
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def self._timedelta_to_pl_duration(td)
|
40
|
+
td
|
41
|
+
end
|
42
|
+
|
43
|
+
def self._datetime_to_pl_timestamp(dt, time_unit)
|
44
|
+
dt = dt.to_datetime.to_time
|
45
|
+
if time_unit == "ns"
|
46
|
+
nanos = dt.nsec
|
47
|
+
dt.to_i * 1_000_000_000 + nanos
|
48
|
+
elsif time_unit == "us"
|
49
|
+
micros = dt.usec
|
50
|
+
dt.to_i * 1_000_000 + micros
|
51
|
+
elsif time_unit == "ms"
|
52
|
+
millis = dt.usec / 1000
|
53
|
+
dt.to_i * 1_000 + millis
|
54
|
+
elsif time_unit.nil?
|
55
|
+
# Ruby has ns precision
|
56
|
+
nanos = dt.nsec
|
57
|
+
dt.to_i * 1_000_000_000 + nanos
|
58
|
+
else
|
59
|
+
raise ArgumentError, "time_unit must be one of {{'ns', 'us', 'ms'}}, got #{tu}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def self._date_to_pl_date(d)
|
64
|
+
dt = d.to_datetime.to_time
|
65
|
+
dt.to_i / (3600 * 24)
|
66
|
+
end
|
67
|
+
|
68
|
+
def self._to_ruby_time(value)
|
69
|
+
if value == 0
|
70
|
+
::Time.utc(2000, 1, 1)
|
71
|
+
else
|
72
|
+
seconds, nanoseconds = value.divmod(1_000_000_000)
|
73
|
+
minutes, seconds = seconds.divmod(60)
|
74
|
+
hours, minutes = minutes.divmod(60)
|
75
|
+
::Time.utc(2000, 1, 1, hours, minutes, seconds, nanoseconds / 1000.0)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def self._to_ruby_duration(value, time_unit = "ns")
|
80
|
+
if time_unit == "ns"
|
81
|
+
value / 1e9
|
82
|
+
elsif time_unit == "us"
|
83
|
+
value / 1e6
|
84
|
+
elsif time_unit == "ms"
|
85
|
+
value / 1e3
|
86
|
+
else
|
87
|
+
raise ArgumentError, "time_unit must be one of {{'ns', 'us', 'ms'}}, got #{time_unit}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def self._to_ruby_date(value)
|
92
|
+
# days to seconds
|
93
|
+
# important to create from utc. Not doing this leads
|
94
|
+
# to inconsistencies dependent on the timezone you are in.
|
95
|
+
::Time.at(value * 86400).utc.to_date
|
96
|
+
end
|
97
|
+
|
98
|
+
def self._to_ruby_datetime(value, time_unit = "ns", time_zone = nil)
|
99
|
+
if time_zone.nil? || time_zone == ""
|
100
|
+
if time_unit == "ns"
|
101
|
+
return ::Time.at(value / 1000000000, value % 1000000000, :nsec).utc
|
102
|
+
elsif time_unit == "us"
|
103
|
+
return ::Time.at(value / 1000000, value % 1000000, :usec).utc
|
104
|
+
elsif time_unit == "ms"
|
105
|
+
return ::Time.at(value / 1000, value % 1000, :millisecond).utc
|
106
|
+
else
|
107
|
+
raise ArgumentError, "time_unit must be one of {{'ns', 'us', 'ms'}}, got #{time_unit}"
|
108
|
+
end
|
109
|
+
else
|
110
|
+
raise Todo
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def self._to_ruby_decimal(digits, scale)
|
115
|
+
BigDecimal("#{digits}e#{scale}")
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.selection_to_rbexpr_list(exprs)
|
119
|
+
if exprs.is_a?(::String) || exprs.is_a?(Symbol) || exprs.is_a?(Expr) || exprs.is_a?(Series)
|
120
|
+
exprs = [exprs]
|
121
|
+
end
|
122
|
+
|
123
|
+
exprs.map { |e| expr_to_lit_or_expr(e, str_to_lit: false)._rbexpr }
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.expr_to_lit_or_expr(expr, str_to_lit: true)
|
127
|
+
if (expr.is_a?(::String) || expr.is_a?(Symbol)) && !str_to_lit
|
128
|
+
col(expr)
|
129
|
+
elsif expr.is_a?(Integer) || expr.is_a?(Float) || expr.is_a?(::String) || expr.is_a?(Symbol) || expr.is_a?(Series) || expr.nil?
|
130
|
+
lit(expr)
|
131
|
+
elsif expr.is_a?(Expr)
|
132
|
+
expr
|
133
|
+
else
|
134
|
+
raise ArgumentError, "did not expect value #{expr} of type #{expr.class.name}, maybe disambiguate with Polars.lit or Polars.col"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.lit(value)
|
139
|
+
Polars.lit(value)
|
140
|
+
end
|
141
|
+
|
142
|
+
def self.normalise_filepath(path, check_not_directory: true)
|
143
|
+
path = File.expand_path(path)
|
144
|
+
if check_not_directory && File.exist?(path) && Dir.exist?(path)
|
145
|
+
raise ArgumentError, "Expected a file path; #{path} is a directory"
|
146
|
+
end
|
147
|
+
path
|
148
|
+
end
|
149
|
+
|
150
|
+
# TODO fix
|
151
|
+
def self.is_polars_dtype(data_type, include_unknown: false)
|
152
|
+
if data_type == Unknown
|
153
|
+
return include_unknown
|
154
|
+
end
|
155
|
+
data_type.is_a?(Symbol) || data_type.is_a?(::String) || data_type.is_a?(DataType) || (data_type.is_a?(Class) && data_type < DataType)
|
156
|
+
end
|
157
|
+
|
158
|
+
def self.map_rb_type_to_dtype(ruby_dtype)
|
159
|
+
if ruby_dtype == Float
|
160
|
+
Float64
|
161
|
+
elsif ruby_dtype == Integer
|
162
|
+
Int64
|
163
|
+
elsif ruby_dtype == ::String
|
164
|
+
Utf8
|
165
|
+
elsif ruby_dtype == TrueClass || ruby_dtype == FalseClass
|
166
|
+
Boolean
|
167
|
+
elsif ruby_dtype == DateTime || ruby_dtype == ::Time || (defined?(ActiveSupport::TimeWithZone) && ruby_dtype == ActiveSupport::TimeWithZone)
|
168
|
+
Datetime.new("ns")
|
169
|
+
elsif ruby_dtype == ::Date
|
170
|
+
Date
|
171
|
+
elsif ruby_dtype == ::Array
|
172
|
+
List
|
173
|
+
elsif ruby_dtype == NilClass
|
174
|
+
Null
|
175
|
+
else
|
176
|
+
raise TypeError, "Invalid type"
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# TODO fix
|
181
|
+
def self.rb_type_to_dtype(data_type)
|
182
|
+
if is_polars_dtype(data_type)
|
183
|
+
data_type = data_type.to_s if data_type.is_a?(Symbol)
|
184
|
+
return data_type
|
185
|
+
end
|
186
|
+
|
187
|
+
begin
|
188
|
+
map_rb_type_to_dtype(data_type)
|
189
|
+
rescue TypeError
|
190
|
+
raise ArgumentError, "Conversion of Ruby data type #{data_type.inspect} to Polars data type not implemented."
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def self._process_null_values(null_values)
|
195
|
+
if null_values.is_a?(Hash)
|
196
|
+
null_values.to_a
|
197
|
+
else
|
198
|
+
null_values
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def self._prepare_row_count_args(row_count_name = nil, row_count_offset = 0)
|
203
|
+
if !row_count_name.nil?
|
204
|
+
[row_count_name, row_count_offset]
|
205
|
+
else
|
206
|
+
nil
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def self.handle_projection_columns(columns)
|
211
|
+
projection = nil
|
212
|
+
if columns
|
213
|
+
raise Todo
|
214
|
+
# if columns.is_a?(::String) || columns.is_a?(Symbol)
|
215
|
+
# columns = [columns]
|
216
|
+
# elsif is_int_sequence(columns)
|
217
|
+
# projection = columns.to_a
|
218
|
+
# columns = nil
|
219
|
+
# elsif !is_str_sequence(columns)
|
220
|
+
# raise ArgumentError, "columns arg should contain a list of all integers or all strings values."
|
221
|
+
# end
|
222
|
+
end
|
223
|
+
[projection, columns]
|
224
|
+
end
|
225
|
+
|
226
|
+
def self.scale_bytes(sz, to:)
|
227
|
+
scaling_factor = {
|
228
|
+
"b" => 1,
|
229
|
+
"k" => 1024,
|
230
|
+
"m" => 1024 ** 2,
|
231
|
+
"g" => 1024 ** 3,
|
232
|
+
"t" => 1024 ** 4
|
233
|
+
}[to[0]]
|
234
|
+
if scaling_factor > 1
|
235
|
+
sz / scaling_factor.to_f
|
236
|
+
else
|
237
|
+
sz
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
def self.bool?(value)
|
242
|
+
value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
243
|
+
end
|
244
|
+
|
245
|
+
def self.strlike?(value)
|
246
|
+
value.is_a?(::String) || value.is_a?(Symbol)
|
247
|
+
end
|
248
|
+
|
249
|
+
def self.pathlike?(value)
|
250
|
+
value.is_a?(::String) || (defined?(Pathname) && value.is_a?(Pathname))
|
251
|
+
end
|
252
|
+
|
253
|
+
def self._is_iterable_of(val, eltype)
|
254
|
+
val.all? { |x| x.is_a?(eltype) }
|
255
|
+
end
|
256
|
+
|
257
|
+
def self.is_bool_sequence(val)
|
258
|
+
val.is_a?(::Array) && val.all? { |x| x == true || x == false }
|
259
|
+
end
|
260
|
+
|
261
|
+
def self.is_dtype_sequence(val)
|
262
|
+
val.is_a?(::Array) && val.all? { |x| is_polars_dtype(x) }
|
263
|
+
end
|
264
|
+
|
265
|
+
def self.is_int_sequence(val)
|
266
|
+
val.is_a?(::Array) && _is_iterable_of(val, Integer)
|
267
|
+
end
|
268
|
+
|
269
|
+
def self.is_expr_sequence(val)
|
270
|
+
val.is_a?(::Array) && _is_iterable_of(val, Expr)
|
271
|
+
end
|
272
|
+
|
273
|
+
def self.is_rbexpr_sequence(val)
|
274
|
+
val.is_a?(::Array) && _is_iterable_of(val, RbExpr)
|
275
|
+
end
|
276
|
+
|
277
|
+
def self.is_str_sequence(val, allow_str: false)
|
278
|
+
if allow_str == false && val.is_a?(::String)
|
279
|
+
false
|
280
|
+
else
|
281
|
+
val.is_a?(::Array) && _is_iterable_of(val, ::String)
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
def self.local_file?(file)
|
286
|
+
Dir.glob(file).any?
|
287
|
+
end
|
288
|
+
|
289
|
+
def self.parse_as_list_of_expressions(*inputs, __structify: false, **named_inputs)
|
290
|
+
exprs = _parse_positional_inputs(inputs, structify: __structify)
|
291
|
+
if named_inputs.any?
|
292
|
+
named_exprs = _parse_named_inputs(named_inputs, structify: __structify)
|
293
|
+
exprs.concat(named_exprs)
|
294
|
+
end
|
295
|
+
|
296
|
+
exprs
|
297
|
+
end
|
298
|
+
|
299
|
+
def self._parse_positional_inputs(inputs, structify: false)
|
300
|
+
inputs_iter = _parse_inputs_as_iterable(inputs)
|
301
|
+
inputs_iter.map { |e| parse_as_expression(e, structify: structify) }
|
302
|
+
end
|
303
|
+
|
304
|
+
def self._parse_inputs_as_iterable(inputs)
|
305
|
+
if inputs.empty?
|
306
|
+
return []
|
307
|
+
end
|
308
|
+
|
309
|
+
if inputs.length == 1 && inputs[0].is_a?(::Array)
|
310
|
+
return inputs[0]
|
311
|
+
end
|
312
|
+
|
313
|
+
inputs
|
314
|
+
end
|
315
|
+
|
316
|
+
def self._parse_named_inputs(named_inputs, structify: false)
|
317
|
+
named_inputs.map do |name, input|
|
318
|
+
parse_as_expression(input, structify: structify)._alias(name.to_s)
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
def self.parse_as_expression(input, str_as_lit: false, list_as_lit: true, structify: false, dtype: nil)
|
323
|
+
if input.is_a?(Expr)
|
324
|
+
expr = input
|
325
|
+
elsif input.is_a?(::String) && !str_as_lit
|
326
|
+
expr = Polars.col(input)
|
327
|
+
structify = false
|
328
|
+
elsif input.is_a?(::Array) && !list_as_lit
|
329
|
+
expr = Polars.lit(Series.new(input), dtype: dtype)
|
330
|
+
structify = false
|
331
|
+
else
|
332
|
+
expr = Polars.lit(input, dtype: dtype)
|
333
|
+
structify = false
|
334
|
+
end
|
335
|
+
|
336
|
+
if structify
|
337
|
+
raise Todo
|
338
|
+
end
|
339
|
+
|
340
|
+
expr._rbexpr
|
341
|
+
end
|
342
|
+
|
343
|
+
USE_EARLIEST_TO_AMBIGUOUS = {
|
344
|
+
true => "earliest",
|
345
|
+
false => "latest"
|
346
|
+
}
|
347
|
+
|
348
|
+
def self.rename_use_earliest_to_ambiguous(use_earliest, ambiguous)
|
349
|
+
unless use_earliest.nil?
|
350
|
+
ambiguous = USE_EARLIEST_TO_AMBIGUOUS.fetch(use_earliest)
|
351
|
+
end
|
352
|
+
ambiguous
|
353
|
+
end
|
354
|
+
|
355
|
+
def self._check_arg_is_1byte(arg_name, arg, can_be_empty = false)
|
356
|
+
if arg.is_a?(::String)
|
357
|
+
arg_byte_length = arg.bytesize
|
358
|
+
if can_be_empty
|
359
|
+
if arg_byte_length > 1
|
360
|
+
raise ArgumentError, "#{arg_name} should be a single byte character or empty, but is #{arg_byte_length} bytes long."
|
361
|
+
end
|
362
|
+
elsif arg_byte_length != 1
|
363
|
+
raise ArgumentError, "#{arg_name} should be a single byte character, but is #{arg_byte_length} bytes long."
|
364
|
+
end
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
def self._expand_selectors(frame, *items)
|
369
|
+
items_iter = _parse_inputs_as_iterable(items)
|
370
|
+
|
371
|
+
expanded = []
|
372
|
+
items_iter.each do |item|
|
373
|
+
if is_selector(item)
|
374
|
+
selector_cols = expand_selector(frame, item)
|
375
|
+
expanded.concat(selector_cols)
|
376
|
+
else
|
377
|
+
expanded << item
|
378
|
+
end
|
379
|
+
end
|
380
|
+
expanded
|
381
|
+
end
|
382
|
+
|
383
|
+
# TODO
|
384
|
+
def self.is_selector(obj)
|
385
|
+
false
|
386
|
+
end
|
387
|
+
|
388
|
+
def self.parse_predicates_constraints_as_expression(*predicates, **constraints)
|
389
|
+
all_predicates = _parse_positional_inputs(predicates)
|
390
|
+
|
391
|
+
if constraints.any?
|
392
|
+
constraint_predicates = _parse_constraints(constraints)
|
393
|
+
all_predicates.concat(constraint_predicates)
|
394
|
+
end
|
395
|
+
|
396
|
+
_combine_predicates(all_predicates)
|
397
|
+
end
|
398
|
+
|
399
|
+
def self._parse_constraints(constraints)
|
400
|
+
constraints.map do |name, value|
|
401
|
+
Polars.col(name).eq(value)._rbexpr
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
def self._combine_predicates(predicates)
|
406
|
+
if !predicates.any?
|
407
|
+
msg = "at least one predicate or constraint must be provided"
|
408
|
+
raise TypeError, msg
|
409
|
+
end
|
410
|
+
|
411
|
+
if predicates.length == 1
|
412
|
+
return predicates[0]
|
413
|
+
end
|
414
|
+
|
415
|
+
Plr.all_horizontal(predicates)
|
416
|
+
end
|
417
|
+
|
418
|
+
def self.parse_when_inputs(*predicates, **constraints)
|
419
|
+
parse_predicates_constraints_as_expression(*predicates, **constraints)
|
420
|
+
end
|
421
|
+
end
|
422
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Polars
|
2
|
+
# @private
|
3
|
+
class When
|
4
|
+
attr_accessor :_when
|
5
|
+
|
6
|
+
def initialize(rbwhen)
|
7
|
+
self._when = rbwhen
|
8
|
+
end
|
9
|
+
|
10
|
+
def then(statement)
|
11
|
+
statement_rbexpr = Utils.parse_as_expression(statement)
|
12
|
+
Then.new(_when.then(statement_rbexpr))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# @private
|
17
|
+
class Then < Expr
|
18
|
+
attr_accessor :_then
|
19
|
+
|
20
|
+
def initialize(rbthen)
|
21
|
+
self._then = rbthen
|
22
|
+
end
|
23
|
+
|
24
|
+
def self._from_rbexpr(rbexpr)
|
25
|
+
Utils.wrap_expr(rbexpr)
|
26
|
+
end
|
27
|
+
|
28
|
+
def _rbexpr
|
29
|
+
_then.otherwise(Polars.lit(nil)._rbexpr)
|
30
|
+
end
|
31
|
+
|
32
|
+
def when(*predicates, **constraints)
|
33
|
+
condition_rbexpr = Utils.parse_when_inputs(*predicates, **constraints)
|
34
|
+
ChainedWhen.new(_then.when(condition_rbexpr))
|
35
|
+
end
|
36
|
+
|
37
|
+
def otherwise(statement)
|
38
|
+
statement_rbexpr = Utils.parse_as_expression(statement)
|
39
|
+
Utils.wrap_expr(_then.otherwise(statement_rbexpr))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# @private
|
44
|
+
class ChainedWhen
|
45
|
+
attr_accessor :_chained_when
|
46
|
+
|
47
|
+
def initialize(chained_when)
|
48
|
+
self._chained_when = chained_when
|
49
|
+
end
|
50
|
+
|
51
|
+
def then(statement)
|
52
|
+
statement_rbexpr = Utils.parse_as_expression(statement)
|
53
|
+
ChainedThen.new(_chained_when.then(statement_rbexpr))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# @private
|
58
|
+
class ChainedThen < Expr
|
59
|
+
attr_accessor :_chained_then
|
60
|
+
|
61
|
+
def initialize(chained_then)
|
62
|
+
self._chained_then = chained_then
|
63
|
+
end
|
64
|
+
|
65
|
+
def self._from_rbexpr(rbexpr)
|
66
|
+
Utils.wrap_expr(rbexpr)
|
67
|
+
end
|
68
|
+
|
69
|
+
def _rbexpr
|
70
|
+
_chained_then.otherwise(Polars.lit(nil)._rbexpr)
|
71
|
+
end
|
72
|
+
|
73
|
+
def when(*predicates, **constraints)
|
74
|
+
condition_rbexpr = Utils.parse_when_inputs(*predicates, **constraints)
|
75
|
+
ChainedWhen.new(_chained_then.when(condition_rbexpr))
|
76
|
+
end
|
77
|
+
|
78
|
+
def otherwise(statement)
|
79
|
+
statement_rbexpr = Utils.parse_as_expression(statement)
|
80
|
+
Utils.wrap_expr(_chained_then.otherwise(statement_rbexpr))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/lib/polars-df.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "polars"
|
data/lib/polars.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# ext
|
2
|
+
begin
|
3
|
+
require "polars/#{RUBY_VERSION.to_f}/polars"
|
4
|
+
rescue LoadError
|
5
|
+
require "polars/polars"
|
6
|
+
end
|
7
|
+
|
8
|
+
# stdlib
|
9
|
+
require "bigdecimal"
|
10
|
+
require "date"
|
11
|
+
require "stringio"
|
12
|
+
|
13
|
+
# modules
|
14
|
+
require_relative "polars/expr_dispatch"
|
15
|
+
require_relative "polars/array_expr"
|
16
|
+
require_relative "polars/array_name_space"
|
17
|
+
require_relative "polars/batched_csv_reader"
|
18
|
+
require_relative "polars/binary_expr"
|
19
|
+
require_relative "polars/binary_name_space"
|
20
|
+
require_relative "polars/cat_expr"
|
21
|
+
require_relative "polars/cat_name_space"
|
22
|
+
require_relative "polars/config"
|
23
|
+
require_relative "polars/convert"
|
24
|
+
require_relative "polars/plot"
|
25
|
+
require_relative "polars/data_frame"
|
26
|
+
require_relative "polars/data_types"
|
27
|
+
require_relative "polars/date_time_expr"
|
28
|
+
require_relative "polars/date_time_name_space"
|
29
|
+
require_relative "polars/dynamic_group_by"
|
30
|
+
require_relative "polars/exceptions"
|
31
|
+
require_relative "polars/expr"
|
32
|
+
require_relative "polars/functions"
|
33
|
+
require_relative "polars/functions/as_datatype"
|
34
|
+
require_relative "polars/functions/col"
|
35
|
+
require_relative "polars/functions/eager"
|
36
|
+
require_relative "polars/functions/lazy"
|
37
|
+
require_relative "polars/functions/len"
|
38
|
+
require_relative "polars/functions/lit"
|
39
|
+
require_relative "polars/functions/random"
|
40
|
+
require_relative "polars/functions/repeat"
|
41
|
+
require_relative "polars/functions/whenthen"
|
42
|
+
require_relative "polars/functions/aggregation/horizontal"
|
43
|
+
require_relative "polars/functions/aggregation/vertical"
|
44
|
+
require_relative "polars/functions/range/date_range"
|
45
|
+
require_relative "polars/functions/range/int_range"
|
46
|
+
require_relative "polars/group_by"
|
47
|
+
require_relative "polars/io"
|
48
|
+
require_relative "polars/lazy_frame"
|
49
|
+
require_relative "polars/lazy_group_by"
|
50
|
+
require_relative "polars/list_expr"
|
51
|
+
require_relative "polars/list_name_space"
|
52
|
+
require_relative "polars/meta_expr"
|
53
|
+
require_relative "polars/name_expr"
|
54
|
+
require_relative "polars/rolling_group_by"
|
55
|
+
require_relative "polars/series"
|
56
|
+
require_relative "polars/slice"
|
57
|
+
require_relative "polars/sql_context"
|
58
|
+
require_relative "polars/string_cache"
|
59
|
+
require_relative "polars/string_expr"
|
60
|
+
require_relative "polars/string_name_space"
|
61
|
+
require_relative "polars/struct_expr"
|
62
|
+
require_relative "polars/struct_name_space"
|
63
|
+
require_relative "polars/testing"
|
64
|
+
require_relative "polars/utils"
|
65
|
+
require_relative "polars/version"
|
66
|
+
require_relative "polars/whenthen"
|
67
|
+
|
68
|
+
module Polars
|
69
|
+
extend Convert
|
70
|
+
extend Functions
|
71
|
+
extend IO
|
72
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: polars-df
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.10.0
|
5
|
+
platform: x86_64-linux-musl
|
6
|
+
authors:
|
7
|
+
- Andrew Kane
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-05-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bigdecimal
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
force_ruby_platform: false
|
28
|
+
description:
|
29
|
+
email: andrew@ankane.org
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".yardopts"
|
35
|
+
- CHANGELOG.md
|
36
|
+
- Cargo.lock
|
37
|
+
- Cargo.toml
|
38
|
+
- LICENSE-THIRD-PARTY.txt
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- lib/polars-df.rb
|
42
|
+
- lib/polars.rb
|
43
|
+
- lib/polars/3.1/polars.so
|
44
|
+
- lib/polars/3.2/polars.so
|
45
|
+
- lib/polars/3.3/polars.so
|
46
|
+
- lib/polars/array_expr.rb
|
47
|
+
- lib/polars/array_name_space.rb
|
48
|
+
- lib/polars/batched_csv_reader.rb
|
49
|
+
- lib/polars/binary_expr.rb
|
50
|
+
- lib/polars/binary_name_space.rb
|
51
|
+
- lib/polars/cat_expr.rb
|
52
|
+
- lib/polars/cat_name_space.rb
|
53
|
+
- lib/polars/config.rb
|
54
|
+
- lib/polars/convert.rb
|
55
|
+
- lib/polars/data_frame.rb
|
56
|
+
- lib/polars/data_types.rb
|
57
|
+
- lib/polars/date_time_expr.rb
|
58
|
+
- lib/polars/date_time_name_space.rb
|
59
|
+
- lib/polars/dynamic_group_by.rb
|
60
|
+
- lib/polars/exceptions.rb
|
61
|
+
- lib/polars/expr.rb
|
62
|
+
- lib/polars/expr_dispatch.rb
|
63
|
+
- lib/polars/functions.rb
|
64
|
+
- lib/polars/functions/aggregation/horizontal.rb
|
65
|
+
- lib/polars/functions/aggregation/vertical.rb
|
66
|
+
- lib/polars/functions/as_datatype.rb
|
67
|
+
- lib/polars/functions/col.rb
|
68
|
+
- lib/polars/functions/eager.rb
|
69
|
+
- lib/polars/functions/lazy.rb
|
70
|
+
- lib/polars/functions/len.rb
|
71
|
+
- lib/polars/functions/lit.rb
|
72
|
+
- lib/polars/functions/random.rb
|
73
|
+
- lib/polars/functions/range/date_range.rb
|
74
|
+
- lib/polars/functions/range/int_range.rb
|
75
|
+
- lib/polars/functions/repeat.rb
|
76
|
+
- lib/polars/functions/whenthen.rb
|
77
|
+
- lib/polars/group_by.rb
|
78
|
+
- lib/polars/io.rb
|
79
|
+
- lib/polars/lazy_frame.rb
|
80
|
+
- lib/polars/lazy_group_by.rb
|
81
|
+
- lib/polars/list_expr.rb
|
82
|
+
- lib/polars/list_name_space.rb
|
83
|
+
- lib/polars/meta_expr.rb
|
84
|
+
- lib/polars/name_expr.rb
|
85
|
+
- lib/polars/plot.rb
|
86
|
+
- lib/polars/rolling_group_by.rb
|
87
|
+
- lib/polars/series.rb
|
88
|
+
- lib/polars/slice.rb
|
89
|
+
- lib/polars/sql_context.rb
|
90
|
+
- lib/polars/string_cache.rb
|
91
|
+
- lib/polars/string_expr.rb
|
92
|
+
- lib/polars/string_name_space.rb
|
93
|
+
- lib/polars/struct_expr.rb
|
94
|
+
- lib/polars/struct_name_space.rb
|
95
|
+
- lib/polars/testing.rb
|
96
|
+
- lib/polars/utils.rb
|
97
|
+
- lib/polars/version.rb
|
98
|
+
- lib/polars/whenthen.rb
|
99
|
+
homepage: https://github.com/ankane/polars-ruby
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '3.1'
|
112
|
+
- - "<"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: 3.4.dev
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: 3.3.22
|
120
|
+
requirements: []
|
121
|
+
rubygems_version: 3.4.4
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Blazingly fast DataFrames for Ruby
|
125
|
+
test_files: []
|