polars-df 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Cargo.lock +90 -45
- data/README.md +1 -0
- data/ext/polars/Cargo.toml +8 -6
- data/ext/polars/src/batched_csv.rs +3 -1
- data/ext/polars/src/conversion/anyvalue.rs +3 -2
- data/ext/polars/src/conversion/mod.rs +18 -7
- data/ext/polars/src/dataframe.rs +40 -14
- data/ext/polars/src/expr/array.rs +6 -2
- data/ext/polars/src/expr/datetime.rs +7 -2
- data/ext/polars/src/expr/general.rs +22 -3
- data/ext/polars/src/expr/list.rs +6 -2
- data/ext/polars/src/expr/string.rs +3 -3
- data/ext/polars/src/file.rs +158 -11
- data/ext/polars/src/functions/lazy.rs +18 -3
- data/ext/polars/src/functions/whenthen.rs +47 -17
- data/ext/polars/src/lazyframe/mod.rs +58 -19
- data/ext/polars/src/lib.rs +23 -14
- data/ext/polars/src/map/dataframe.rs +17 -9
- data/ext/polars/src/series/mod.rs +12 -2
- data/lib/polars/array_expr.rb +6 -2
- data/lib/polars/batched_csv_reader.rb +4 -2
- data/lib/polars/data_frame.rb +148 -74
- data/lib/polars/date_time_expr.rb +10 -4
- data/lib/polars/date_time_name_space.rb +9 -3
- data/lib/polars/expr.rb +37 -34
- data/lib/polars/functions/lazy.rb +3 -3
- data/lib/polars/functions/whenthen.rb +74 -5
- data/lib/polars/io.rb +18 -6
- data/lib/polars/lazy_frame.rb +39 -36
- data/lib/polars/list_expr.rb +6 -2
- data/lib/polars/series.rb +12 -10
- data/lib/polars/string_expr.rb +1 -0
- data/lib/polars/utils.rb +54 -0
- data/lib/polars/version.rb +1 -1
- data/lib/polars/whenthen.rb +83 -0
- data/lib/polars.rb +1 -2
- metadata +4 -5
- data/lib/polars/when.rb +0 -16
- data/lib/polars/when_then.rb +0 -19
@@ -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.rb
CHANGED
@@ -63,8 +63,7 @@ require_relative "polars/struct_name_space"
|
|
63
63
|
require_relative "polars/testing"
|
64
64
|
require_relative "polars/utils"
|
65
65
|
require_relative "polars/version"
|
66
|
-
require_relative "polars/
|
67
|
-
require_relative "polars/when_then"
|
66
|
+
require_relative "polars/whenthen"
|
68
67
|
|
69
68
|
module Polars
|
70
69
|
extend Convert
|
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.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bigdecimal
|
@@ -157,8 +157,7 @@ files:
|
|
157
157
|
- lib/polars/testing.rb
|
158
158
|
- lib/polars/utils.rb
|
159
159
|
- lib/polars/version.rb
|
160
|
-
- lib/polars/
|
161
|
-
- lib/polars/when_then.rb
|
160
|
+
- lib/polars/whenthen.rb
|
162
161
|
homepage: https://github.com/ankane/polars-ruby
|
163
162
|
licenses:
|
164
163
|
- MIT
|
@@ -178,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
177
|
- !ruby/object:Gem::Version
|
179
178
|
version: '0'
|
180
179
|
requirements: []
|
181
|
-
rubygems_version: 3.5.
|
180
|
+
rubygems_version: 3.5.9
|
182
181
|
signing_key:
|
183
182
|
specification_version: 4
|
184
183
|
summary: Blazingly fast DataFrames for Ruby
|
data/lib/polars/when.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module Polars
|
2
|
-
# @private
|
3
|
-
class When
|
4
|
-
attr_accessor :_rbwhen
|
5
|
-
|
6
|
-
def initialize(rbwhen)
|
7
|
-
self._rbwhen = rbwhen
|
8
|
-
end
|
9
|
-
|
10
|
-
def then(expr)
|
11
|
-
expr = Utils.expr_to_lit_or_expr(expr)
|
12
|
-
rbwhenthen = _rbwhen._then(expr._rbexpr)
|
13
|
-
WhenThen.new(rbwhenthen)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/lib/polars/when_then.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module Polars
|
2
|
-
# @private
|
3
|
-
class WhenThen
|
4
|
-
attr_accessor :_rbwhenthen
|
5
|
-
|
6
|
-
def initialize(rbwhenthen)
|
7
|
-
self._rbwhenthen = rbwhenthen
|
8
|
-
end
|
9
|
-
|
10
|
-
def when(predicate)
|
11
|
-
WhenThenThen.new(_rbwhenthen.when(predicate._rbexpr))
|
12
|
-
end
|
13
|
-
|
14
|
-
def otherwise(expr)
|
15
|
-
expr = Utils.expr_to_lit_or_expr(expr)
|
16
|
-
Utils.wrap_expr(_rbwhenthen.otherwise(expr._rbexpr))
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|