polars-df 0.13.0-x64-mingw-ucrt
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 +208 -0
- data/Cargo.lock +2556 -0
- data/Cargo.toml +6 -0
- data/LICENSE-THIRD-PARTY.txt +39278 -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 +104 -0
- data/lib/polars/binary_expr.rb +77 -0
- data/lib/polars/binary_name_space.rb +66 -0
- data/lib/polars/cat_expr.rb +36 -0
- data/lib/polars/cat_name_space.rb +88 -0
- data/lib/polars/config.rb +530 -0
- data/lib/polars/convert.rb +98 -0
- data/lib/polars/data_frame.rb +5191 -0
- data/lib/polars/data_types.rb +466 -0
- data/lib/polars/date_time_expr.rb +1397 -0
- data/lib/polars/date_time_name_space.rb +1287 -0
- data/lib/polars/dynamic_group_by.rb +52 -0
- data/lib/polars/exceptions.rb +38 -0
- data/lib/polars/expr.rb +7256 -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 +271 -0
- data/lib/polars/functions/col.rb +47 -0
- data/lib/polars/functions/eager.rb +182 -0
- data/lib/polars/functions/lazy.rb +1329 -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 +136 -0
- data/lib/polars/functions/range/datetime_range.rb +149 -0
- data/lib/polars/functions/range/int_range.rb +51 -0
- data/lib/polars/functions/range/time_range.rb +141 -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 +613 -0
- data/lib/polars/io/avro.rb +24 -0
- data/lib/polars/io/csv.rb +696 -0
- data/lib/polars/io/database.rb +73 -0
- data/lib/polars/io/ipc.rb +275 -0
- data/lib/polars/io/json.rb +29 -0
- data/lib/polars/io/ndjson.rb +80 -0
- data/lib/polars/io/parquet.rb +233 -0
- data/lib/polars/lazy_frame.rb +2708 -0
- data/lib/polars/lazy_group_by.rb +181 -0
- data/lib/polars/list_expr.rb +791 -0
- data/lib/polars/list_name_space.rb +449 -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 +35 -0
- data/lib/polars/series.rb +4444 -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 +1495 -0
- data/lib/polars/string_name_space.rb +811 -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/constants.rb +9 -0
- data/lib/polars/utils/convert.rb +97 -0
- data/lib/polars/utils/parse.rb +89 -0
- data/lib/polars/utils/various.rb +76 -0
- data/lib/polars/utils/wrap.rb +19 -0
- data/lib/polars/utils.rb +130 -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 +91 -0
- metadata +138 -0
@@ -0,0 +1,97 @@
|
|
1
|
+
module Polars
|
2
|
+
module Utils
|
3
|
+
def self.parse_as_duration_string(td)
|
4
|
+
if td.nil? || td.is_a?(::String)
|
5
|
+
return td
|
6
|
+
end
|
7
|
+
_timedelta_to_duration_string(td)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self._timedelta_to_pl_duration(td)
|
11
|
+
td
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.negate_duration_string(duration)
|
15
|
+
if duration.start_with?("-")
|
16
|
+
duration[1..]
|
17
|
+
else
|
18
|
+
"-#{duration}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.date_to_int(d)
|
23
|
+
dt = d.to_datetime.to_time
|
24
|
+
dt.to_i / SECONDS_PER_DAY
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.datetime_to_int(dt, time_unit)
|
28
|
+
dt = dt.to_datetime.to_time
|
29
|
+
if time_unit == "ns"
|
30
|
+
nanos = dt.nsec
|
31
|
+
dt.to_i * NS_PER_SECOND + nanos
|
32
|
+
elsif time_unit == "us"
|
33
|
+
micros = dt.usec
|
34
|
+
dt.to_i * US_PER_SECOND + micros
|
35
|
+
elsif time_unit == "ms"
|
36
|
+
millis = dt.usec / 1000
|
37
|
+
dt.to_i * MS_PER_SECOND + millis
|
38
|
+
elsif time_unit.nil?
|
39
|
+
# Ruby has ns precision
|
40
|
+
nanos = dt.nsec
|
41
|
+
dt.to_i * NS_PER_SECOND + nanos
|
42
|
+
else
|
43
|
+
raise ArgumentError, "time_unit must be one of {{'ns', 'us', 'ms'}}, got #{tu}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self._to_ruby_date(value)
|
48
|
+
# days to seconds
|
49
|
+
# important to create from utc. Not doing this leads
|
50
|
+
# to inconsistencies dependent on the timezone you are in.
|
51
|
+
::Time.at(value * 86400).utc.to_date
|
52
|
+
end
|
53
|
+
|
54
|
+
def self._to_ruby_time(value)
|
55
|
+
if value == 0
|
56
|
+
::Time.utc(2000, 1, 1)
|
57
|
+
else
|
58
|
+
seconds, nanoseconds = value.divmod(1_000_000_000)
|
59
|
+
minutes, seconds = seconds.divmod(60)
|
60
|
+
hours, minutes = minutes.divmod(60)
|
61
|
+
::Time.utc(2000, 1, 1, hours, minutes, seconds, nanoseconds / 1000.0)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def self._to_ruby_datetime(value, time_unit = "ns", time_zone = nil)
|
66
|
+
if time_zone.nil? || time_zone == "" || time_zone == "UTC"
|
67
|
+
if time_unit == "ns"
|
68
|
+
::Time.at(value / 1000000000, value % 1000000000, :nsec).utc
|
69
|
+
elsif time_unit == "us"
|
70
|
+
::Time.at(value / 1000000, value % 1000000, :usec).utc
|
71
|
+
elsif time_unit == "ms"
|
72
|
+
::Time.at(value / 1000, value % 1000, :millisecond).utc
|
73
|
+
else
|
74
|
+
raise ArgumentError, "time_unit must be one of {{'ns', 'us', 'ms'}}, got #{time_unit}"
|
75
|
+
end
|
76
|
+
else
|
77
|
+
raise Todo
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def self._to_ruby_duration(value, time_unit = "ns")
|
82
|
+
if time_unit == "ns"
|
83
|
+
value / 1e9
|
84
|
+
elsif time_unit == "us"
|
85
|
+
value / 1e6
|
86
|
+
elsif time_unit == "ms"
|
87
|
+
value / 1e3
|
88
|
+
else
|
89
|
+
raise ArgumentError, "time_unit must be one of {{'ns', 'us', 'ms'}}, got #{time_unit}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def self._to_ruby_decimal(digits, scale)
|
94
|
+
BigDecimal("#{digits}e#{scale}")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Polars
|
2
|
+
module Utils
|
3
|
+
def self.parse_into_expression(
|
4
|
+
input,
|
5
|
+
str_as_lit: false,
|
6
|
+
list_as_series: false,
|
7
|
+
structify: false,
|
8
|
+
dtype: nil
|
9
|
+
)
|
10
|
+
if input.is_a?(Expr)
|
11
|
+
expr = input
|
12
|
+
if structify
|
13
|
+
expr = _structify_expression(expr)
|
14
|
+
end
|
15
|
+
elsif (input.is_a?(::String) || input.is_a?(Symbol)) && !str_as_lit
|
16
|
+
expr = F.col(input)
|
17
|
+
elsif input.is_a?(::Array) && list_as_series
|
18
|
+
expr = F.lit(Series.new(input), dtype: dtype)
|
19
|
+
else
|
20
|
+
expr = F.lit(input, dtype: dtype)
|
21
|
+
end
|
22
|
+
|
23
|
+
expr._rbexpr
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.parse_into_list_of_expressions(*inputs, __structify: false, **named_inputs)
|
27
|
+
exprs = _parse_positional_inputs(inputs, structify: __structify)
|
28
|
+
if named_inputs.any?
|
29
|
+
named_exprs = _parse_named_inputs(named_inputs, structify: __structify)
|
30
|
+
exprs.concat(named_exprs)
|
31
|
+
end
|
32
|
+
|
33
|
+
exprs
|
34
|
+
end
|
35
|
+
|
36
|
+
def self._parse_positional_inputs(inputs, structify: false)
|
37
|
+
inputs_iter = _parse_inputs_as_iterable(inputs)
|
38
|
+
inputs_iter.map { |e| parse_into_expression(e, structify: structify) }
|
39
|
+
end
|
40
|
+
|
41
|
+
def self._parse_inputs_as_iterable(inputs)
|
42
|
+
if inputs.empty?
|
43
|
+
return []
|
44
|
+
end
|
45
|
+
|
46
|
+
if inputs.length == 1 && inputs[0].is_a?(::Array)
|
47
|
+
return inputs[0]
|
48
|
+
end
|
49
|
+
|
50
|
+
inputs
|
51
|
+
end
|
52
|
+
|
53
|
+
def self._parse_named_inputs(named_inputs, structify: false)
|
54
|
+
named_inputs.map do |name, input|
|
55
|
+
parse_into_expression(input, structify: structify)._alias(name.to_s)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.parse_predicates_constraints_into_expression(*predicates, **constraints)
|
60
|
+
all_predicates = _parse_positional_inputs(predicates)
|
61
|
+
|
62
|
+
if constraints.any?
|
63
|
+
constraint_predicates = _parse_constraints(constraints)
|
64
|
+
all_predicates.concat(constraint_predicates)
|
65
|
+
end
|
66
|
+
|
67
|
+
_combine_predicates(all_predicates)
|
68
|
+
end
|
69
|
+
|
70
|
+
def self._parse_constraints(constraints)
|
71
|
+
constraints.map do |name, value|
|
72
|
+
Polars.col(name).eq(value)._rbexpr
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def self._combine_predicates(predicates)
|
77
|
+
if !predicates.any?
|
78
|
+
msg = "at least one predicate or constraint must be provided"
|
79
|
+
raise TypeError, msg
|
80
|
+
end
|
81
|
+
|
82
|
+
if predicates.length == 1
|
83
|
+
return predicates[0]
|
84
|
+
end
|
85
|
+
|
86
|
+
Plr.all_horizontal(predicates)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Polars
|
2
|
+
module Utils
|
3
|
+
def self._process_null_values(null_values)
|
4
|
+
if null_values.is_a?(Hash)
|
5
|
+
null_values.to_a
|
6
|
+
else
|
7
|
+
null_values
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self._is_iterable_of(val, eltype)
|
12
|
+
val.all? { |x| x.is_a?(eltype) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.is_bool_sequence(val)
|
16
|
+
val.is_a?(::Array) && val.all? { |x| x == true || x == false }
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.is_int_sequence(val)
|
20
|
+
val.is_a?(::Array) && _is_iterable_of(val, Integer)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.is_str_sequence(val, allow_str: false)
|
24
|
+
if allow_str == false && val.is_a?(::String)
|
25
|
+
false
|
26
|
+
else
|
27
|
+
val.is_a?(::Array) && _is_iterable_of(val, ::String)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.arrlen(obj)
|
32
|
+
if obj.is_a?(Range)
|
33
|
+
# size only works for numeric ranges
|
34
|
+
obj.to_a.length
|
35
|
+
elsif obj.is_a?(::String)
|
36
|
+
nil
|
37
|
+
else
|
38
|
+
obj.length
|
39
|
+
end
|
40
|
+
rescue
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.normalize_filepath(path, check_not_directory: true)
|
45
|
+
path = File.expand_path(path)
|
46
|
+
if check_not_directory && File.exist?(path) && Dir.exist?(path)
|
47
|
+
raise ArgumentError, "Expected a file path; #{path} is a directory"
|
48
|
+
end
|
49
|
+
path
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.scale_bytes(sz, to:)
|
53
|
+
scaling_factor = {
|
54
|
+
"b" => 1,
|
55
|
+
"k" => 1024,
|
56
|
+
"m" => 1024 ** 2,
|
57
|
+
"g" => 1024 ** 3,
|
58
|
+
"t" => 1024 ** 4
|
59
|
+
}[to[0]]
|
60
|
+
if scaling_factor > 1
|
61
|
+
sz / scaling_factor.to_f
|
62
|
+
else
|
63
|
+
sz
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.extend_bool(value, n_match, value_name, match_name)
|
68
|
+
values = bool?(value) ? [value] * n_match : value
|
69
|
+
if n_match != values.length
|
70
|
+
msg = "the length of `#{value_name}` (#{values.length}) does not match the length of `#{match_name}` (#{n_match})"
|
71
|
+
raise ValueError, msg
|
72
|
+
end
|
73
|
+
values
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Polars
|
2
|
+
module Utils
|
3
|
+
def self.wrap_df(df)
|
4
|
+
DataFrame._from_rbdf(df)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.wrap_ldf(ldf)
|
8
|
+
LazyFrame._from_rbldf(ldf)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.wrap_s(s)
|
12
|
+
Series._from_rbseries(s)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.wrap_expr(rbexpr)
|
16
|
+
Expr._from_rbexpr(rbexpr)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/polars/utils.rb
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
module Polars
|
2
|
+
# @private
|
3
|
+
module Utils
|
4
|
+
DTYPE_TEMPORAL_UNITS = ["ns", "us", "ms"]
|
5
|
+
|
6
|
+
# TODO fix
|
7
|
+
def self.is_polars_dtype(data_type, include_unknown: false)
|
8
|
+
if data_type == Unknown
|
9
|
+
return include_unknown
|
10
|
+
end
|
11
|
+
data_type.is_a?(Symbol) || data_type.is_a?(::String) || data_type.is_a?(DataType) || (data_type.is_a?(Class) && data_type < DataType)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.map_rb_type_to_dtype(ruby_dtype)
|
15
|
+
if ruby_dtype == Float
|
16
|
+
Float64
|
17
|
+
elsif ruby_dtype == Integer
|
18
|
+
Int64
|
19
|
+
elsif ruby_dtype == ::String
|
20
|
+
Utf8
|
21
|
+
elsif ruby_dtype == TrueClass || ruby_dtype == FalseClass
|
22
|
+
Boolean
|
23
|
+
elsif ruby_dtype == DateTime || ruby_dtype == ::Time || (defined?(ActiveSupport::TimeWithZone) && ruby_dtype == ActiveSupport::TimeWithZone)
|
24
|
+
Datetime.new("ns")
|
25
|
+
elsif ruby_dtype == ::Date
|
26
|
+
Date
|
27
|
+
elsif ruby_dtype == ::Array
|
28
|
+
List
|
29
|
+
elsif ruby_dtype == NilClass
|
30
|
+
Null
|
31
|
+
else
|
32
|
+
raise TypeError, "Invalid type"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# TODO fix
|
37
|
+
def self.rb_type_to_dtype(data_type)
|
38
|
+
if is_polars_dtype(data_type)
|
39
|
+
data_type = data_type.to_s if data_type.is_a?(Symbol)
|
40
|
+
return data_type
|
41
|
+
end
|
42
|
+
|
43
|
+
begin
|
44
|
+
map_rb_type_to_dtype(data_type)
|
45
|
+
rescue TypeError
|
46
|
+
raise ArgumentError, "Conversion of Ruby data type #{data_type.inspect} to Polars data type not implemented."
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.parse_row_index_args(row_index_name = nil, row_index_offset = 0)
|
51
|
+
if row_index_name.nil?
|
52
|
+
nil
|
53
|
+
else
|
54
|
+
[row_index_name, row_index_offset]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.handle_projection_columns(columns)
|
59
|
+
projection = nil
|
60
|
+
if columns
|
61
|
+
raise Todo
|
62
|
+
# if columns.is_a?(::String) || columns.is_a?(Symbol)
|
63
|
+
# columns = [columns]
|
64
|
+
# elsif is_int_sequence(columns)
|
65
|
+
# projection = columns.to_a
|
66
|
+
# columns = nil
|
67
|
+
# elsif !is_str_sequence(columns)
|
68
|
+
# raise ArgumentError, "columns arg should contain a list of all integers or all strings values."
|
69
|
+
# end
|
70
|
+
end
|
71
|
+
[projection, columns]
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.bool?(value)
|
75
|
+
value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.strlike?(value)
|
79
|
+
value.is_a?(::String) || value.is_a?(Symbol)
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.pathlike?(value)
|
83
|
+
value.is_a?(::String) || (defined?(Pathname) && value.is_a?(Pathname))
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.local_file?(file)
|
87
|
+
Dir.glob(file).any?
|
88
|
+
end
|
89
|
+
|
90
|
+
def self._check_arg_is_1byte(arg_name, arg, can_be_empty = false)
|
91
|
+
if arg.is_a?(::String)
|
92
|
+
arg_byte_length = arg.bytesize
|
93
|
+
if can_be_empty
|
94
|
+
if arg_byte_length > 1
|
95
|
+
raise ArgumentError, "#{arg_name} should be a single byte character or empty, but is #{arg_byte_length} bytes long."
|
96
|
+
end
|
97
|
+
elsif arg_byte_length != 1
|
98
|
+
raise ArgumentError, "#{arg_name} should be a single byte character, but is #{arg_byte_length} bytes long."
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def self._expand_selectors(frame, *items)
|
104
|
+
items_iter = _parse_inputs_as_iterable(items)
|
105
|
+
|
106
|
+
expanded = []
|
107
|
+
items_iter.each do |item|
|
108
|
+
if is_selector(item)
|
109
|
+
selector_cols = expand_selector(frame, item)
|
110
|
+
expanded.concat(selector_cols)
|
111
|
+
else
|
112
|
+
expanded << item
|
113
|
+
end
|
114
|
+
end
|
115
|
+
expanded
|
116
|
+
end
|
117
|
+
|
118
|
+
# TODO
|
119
|
+
def self.is_selector(obj)
|
120
|
+
false
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.parse_interval_argument(interval)
|
124
|
+
if interval.include?(" ")
|
125
|
+
interval = interval.gsub(" ", "")
|
126
|
+
end
|
127
|
+
interval.downcase
|
128
|
+
end
|
129
|
+
end
|
130
|
+
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_into_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_predicates_constraints_into_expression(*predicates, **constraints)
|
34
|
+
ChainedWhen.new(_then.when(condition_rbexpr))
|
35
|
+
end
|
36
|
+
|
37
|
+
def otherwise(statement)
|
38
|
+
statement_rbexpr = Utils.parse_into_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_into_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_predicates_constraints_into_expression(*predicates, **constraints)
|
75
|
+
ChainedWhen.new(_chained_then.when(condition_rbexpr))
|
76
|
+
end
|
77
|
+
|
78
|
+
def otherwise(statement)
|
79
|
+
statement_rbexpr = Utils.parse_into_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,91 @@
|
|
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/datetime_range"
|
46
|
+
require_relative "polars/functions/range/int_range"
|
47
|
+
require_relative "polars/functions/range/time_range"
|
48
|
+
require_relative "polars/group_by"
|
49
|
+
require_relative "polars/io/avro"
|
50
|
+
require_relative "polars/io/csv"
|
51
|
+
require_relative "polars/io/database"
|
52
|
+
require_relative "polars/io/ipc"
|
53
|
+
require_relative "polars/io/json"
|
54
|
+
require_relative "polars/io/ndjson"
|
55
|
+
require_relative "polars/io/parquet"
|
56
|
+
require_relative "polars/lazy_frame"
|
57
|
+
require_relative "polars/lazy_group_by"
|
58
|
+
require_relative "polars/list_expr"
|
59
|
+
require_relative "polars/list_name_space"
|
60
|
+
require_relative "polars/meta_expr"
|
61
|
+
require_relative "polars/name_expr"
|
62
|
+
require_relative "polars/rolling_group_by"
|
63
|
+
require_relative "polars/series"
|
64
|
+
require_relative "polars/slice"
|
65
|
+
require_relative "polars/sql_context"
|
66
|
+
require_relative "polars/string_cache"
|
67
|
+
require_relative "polars/string_expr"
|
68
|
+
require_relative "polars/string_name_space"
|
69
|
+
require_relative "polars/struct_expr"
|
70
|
+
require_relative "polars/struct_name_space"
|
71
|
+
require_relative "polars/testing"
|
72
|
+
require_relative "polars/utils"
|
73
|
+
require_relative "polars/utils/constants"
|
74
|
+
require_relative "polars/utils/convert"
|
75
|
+
require_relative "polars/utils/parse"
|
76
|
+
require_relative "polars/utils/various"
|
77
|
+
require_relative "polars/utils/wrap"
|
78
|
+
require_relative "polars/version"
|
79
|
+
require_relative "polars/whenthen"
|
80
|
+
|
81
|
+
module Polars
|
82
|
+
extend Convert
|
83
|
+
extend Functions
|
84
|
+
extend IO
|
85
|
+
|
86
|
+
# @private
|
87
|
+
F = self
|
88
|
+
|
89
|
+
# @private
|
90
|
+
N_INFER_DEFAULT = 100
|
91
|
+
end
|