polars-df 0.4.0-x86_64-darwin → 0.5.0-x86_64-darwin
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 +272 -191
- data/Cargo.toml +0 -1
- data/LICENSE-THIRD-PARTY.txt +2043 -1202
- data/README.md +2 -2
- data/lib/polars/3.0/polars.bundle +0 -0
- data/lib/polars/3.1/polars.bundle +0 -0
- data/lib/polars/3.2/polars.bundle +0 -0
- data/lib/polars/convert.rb +2 -2
- data/lib/polars/data_frame.rb +201 -50
- data/lib/polars/data_types.rb +6 -4
- data/lib/polars/date_time_expr.rb +142 -2
- data/lib/polars/expr.rb +70 -10
- data/lib/polars/lazy_frame.rb +4 -3
- data/lib/polars/lazy_functions.rb +4 -1
- data/lib/polars/list_expr.rb +68 -19
- data/lib/polars/series.rb +181 -73
- data/lib/polars/string_expr.rb +149 -43
- data/lib/polars/string_name_space.rb +4 -4
- data/lib/polars/struct_name_space.rb +32 -0
- data/lib/polars/utils.rb +41 -7
- data/lib/polars/version.rb +1 -1
- data/lib/polars.rb +2 -2
- metadata +2 -2
@@ -60,5 +60,37 @@ module Polars
|
|
60
60
|
def rename_fields(names)
|
61
61
|
super
|
62
62
|
end
|
63
|
+
|
64
|
+
# Get the struct definition as a name/dtype schema dict.
|
65
|
+
#
|
66
|
+
# @return [Object]
|
67
|
+
def schema
|
68
|
+
if _s.nil?
|
69
|
+
{}
|
70
|
+
else
|
71
|
+
_s.dtype.to_schema
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Convert this struct Series to a DataFrame with a separate column for each field.
|
76
|
+
#
|
77
|
+
# @return [DataFrame]
|
78
|
+
#
|
79
|
+
# @example
|
80
|
+
# s = Polars::Series.new([{"a" => 1, "b" => 2}, {"a" => 3, "b" => 4}])
|
81
|
+
# s.struct.unnest
|
82
|
+
# # =>
|
83
|
+
# # shape: (2, 2)
|
84
|
+
# # ┌─────┬─────┐
|
85
|
+
# # │ a ┆ b │
|
86
|
+
# # │ --- ┆ --- │
|
87
|
+
# # │ i64 ┆ i64 │
|
88
|
+
# # ╞═════╪═════╡
|
89
|
+
# # │ 1 ┆ 2 │
|
90
|
+
# # │ 3 ┆ 4 │
|
91
|
+
# # └─────┴─────┘
|
92
|
+
def unnest
|
93
|
+
Utils.wrap_df(_s.struct_unnest)
|
94
|
+
end
|
63
95
|
end
|
64
96
|
end
|
data/lib/polars/utils.rb
CHANGED
@@ -23,24 +23,42 @@ module Polars
|
|
23
23
|
Polars.col(name)
|
24
24
|
end
|
25
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
|
+
|
26
39
|
def self._timedelta_to_pl_duration(td)
|
27
40
|
td
|
28
41
|
end
|
29
42
|
|
30
43
|
def self._datetime_to_pl_timestamp(dt, tu)
|
31
44
|
if tu == "ns"
|
32
|
-
(dt.to_datetime.
|
45
|
+
(dt.to_datetime.to_time.to_f * 1e9).to_i
|
33
46
|
elsif tu == "us"
|
34
|
-
(dt.to_datetime.
|
47
|
+
(dt.to_datetime.to_time.to_f * 1e6).to_i
|
35
48
|
elsif tu == "ms"
|
36
|
-
(dt.to_datetime.
|
49
|
+
(dt.to_datetime.to_time.to_f * 1e3).to_i
|
37
50
|
elsif tu.nil?
|
38
|
-
(dt.to_datetime.
|
51
|
+
(dt.to_datetime.to_time.to_f * 1e6).to_i
|
39
52
|
else
|
40
53
|
raise ArgumentError, "tu must be one of {{'ns', 'us', 'ms'}}, got #{tu}"
|
41
54
|
end
|
42
55
|
end
|
43
56
|
|
57
|
+
def self._date_to_pl_date(d)
|
58
|
+
dt = d.to_datetime.to_time
|
59
|
+
dt.to_i / (3600 * 24)
|
60
|
+
end
|
61
|
+
|
44
62
|
def self._to_ruby_datetime(value, dtype, tu: "ns", tz: nil)
|
45
63
|
if dtype == :date || dtype == Date
|
46
64
|
# days to seconds
|
@@ -69,6 +87,18 @@ module Polars
|
|
69
87
|
end
|
70
88
|
end
|
71
89
|
|
90
|
+
def self._to_ruby_duration(value, tu = "ns")
|
91
|
+
if tu == "ns"
|
92
|
+
value / 1e9
|
93
|
+
elsif tu == "us"
|
94
|
+
value / 1e6
|
95
|
+
elsif tu == "ms"
|
96
|
+
value / 1e3
|
97
|
+
else
|
98
|
+
raise ArgumentError, "tu must be one of {{'ns', 'us', 'ms'}}, got #{tu}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
72
102
|
def self.selection_to_rbexpr_list(exprs)
|
73
103
|
if exprs.is_a?(String) || exprs.is_a?(Symbol) || exprs.is_a?(Expr) || exprs.is_a?(Series)
|
74
104
|
exprs = [exprs]
|
@@ -102,7 +132,10 @@ module Polars
|
|
102
132
|
end
|
103
133
|
|
104
134
|
# TODO fix
|
105
|
-
def self.is_polars_dtype(data_type)
|
135
|
+
def self.is_polars_dtype(data_type, include_unknown: false)
|
136
|
+
if data_type == Unknown
|
137
|
+
return include_unknown
|
138
|
+
end
|
106
139
|
data_type.is_a?(Symbol) || data_type.is_a?(String) || data_type.is_a?(DataType) || (data_type.is_a?(Class) && data_type < DataType)
|
107
140
|
end
|
108
141
|
|
@@ -113,7 +146,8 @@ module Polars
|
|
113
146
|
TrueClass => :bool,
|
114
147
|
FalseClass => :bool,
|
115
148
|
::Date => :date,
|
116
|
-
::DateTime => :datetime
|
149
|
+
::DateTime => :datetime,
|
150
|
+
::Time => :datetime
|
117
151
|
}
|
118
152
|
|
119
153
|
# TODO fix
|
@@ -178,7 +212,7 @@ module Polars
|
|
178
212
|
end
|
179
213
|
|
180
214
|
def self.bool?(value)
|
181
|
-
value
|
215
|
+
value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
182
216
|
end
|
183
217
|
|
184
218
|
def self.strlike?(value)
|
data/lib/polars/version.rb
CHANGED
data/lib/polars.rb
CHANGED
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.5.0
|
5
5
|
platform: x86_64-darwin
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: andrew@ankane.org
|