polars-df 0.2.5 → 0.3.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Cargo.lock +290 -137
- data/Cargo.toml +1 -1
- data/ext/polars/Cargo.toml +5 -4
- data/ext/polars/src/apply/dataframe.rs +6 -6
- data/ext/polars/src/apply/series.rs +10 -10
- data/ext/polars/src/batched_csv.rs +6 -4
- data/ext/polars/src/conversion.rs +40 -13
- data/ext/polars/src/dataframe.rs +45 -43
- data/ext/polars/src/error.rs +8 -8
- data/ext/polars/src/file.rs +5 -4
- data/ext/polars/src/lazy/apply.rs +1 -1
- data/ext/polars/src/lazy/dataframe.rs +12 -6
- data/ext/polars/src/lazy/dsl.rs +99 -45
- data/ext/polars/src/lazy/meta.rs +10 -9
- data/ext/polars/src/lib.rs +28 -29
- data/ext/polars/src/object.rs +2 -1
- data/ext/polars/src/series.rs +23 -21
- data/lib/polars/cat_expr.rb +0 -4
- data/lib/polars/cat_name_space.rb +0 -4
- data/lib/polars/convert.rb +0 -7
- data/lib/polars/data_frame.rb +139 -204
- data/lib/polars/date_time_expr.rb +19 -151
- data/lib/polars/date_time_name_space.rb +17 -17
- data/lib/polars/expr.rb +68 -315
- data/lib/polars/group_by.rb +68 -51
- data/lib/polars/io.rb +1 -1
- data/lib/polars/lazy_frame.rb +1 -103
- data/lib/polars/lazy_functions.rb +0 -26
- data/lib/polars/lazy_group_by.rb +0 -8
- data/lib/polars/list_expr.rb +5 -27
- data/lib/polars/list_name_space.rb +5 -8
- data/lib/polars/series.rb +20 -16
- data/lib/polars/string_expr.rb +20 -76
- data/lib/polars/string_name_space.rb +5 -15
- data/lib/polars/struct_expr.rb +0 -2
- data/lib/polars/version.rb +1 -1
- metadata +3 -3
data/ext/polars/src/series.rs
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
use magnus::exception
|
2
|
-
use magnus::{Error, RArray, Value};
|
1
|
+
use magnus::{exception, Error, IntoValue, RArray, Value};
|
3
2
|
use polars::prelude::*;
|
4
3
|
use polars::series::IsSorted;
|
5
4
|
use std::cell::RefCell;
|
@@ -30,11 +29,11 @@ impl RbSeries {
|
|
30
29
|
}
|
31
30
|
|
32
31
|
pub fn is_sorted_flag(&self) -> bool {
|
33
|
-
matches!(self.series.borrow().
|
32
|
+
matches!(self.series.borrow().is_sorted_flag(), IsSorted::Ascending)
|
34
33
|
}
|
35
34
|
|
36
35
|
pub fn is_sorted_reverse_flag(&self) -> bool {
|
37
|
-
matches!(self.series.borrow().
|
36
|
+
matches!(self.series.borrow().is_sorted_flag(), IsSorted::Descending)
|
38
37
|
}
|
39
38
|
|
40
39
|
pub fn new_opt_bool(name: String, obj: RArray, strict: bool) -> RbResult<RbSeries> {
|
@@ -173,7 +172,7 @@ impl RbSeries {
|
|
173
172
|
}
|
174
173
|
|
175
174
|
pub fn get_idx(&self, idx: usize) -> RbResult<Value> {
|
176
|
-
Ok(Wrap(self.series.borrow().get(idx).map_err(RbPolarsErr::from)?).
|
175
|
+
Ok(Wrap(self.series.borrow().get(idx).map_err(RbPolarsErr::from)?).into_value())
|
177
176
|
}
|
178
177
|
|
179
178
|
pub fn bitand(&self, other: &RbSeries) -> RbResult<Self> {
|
@@ -216,7 +215,7 @@ impl RbSeries {
|
|
216
215
|
}
|
217
216
|
|
218
217
|
pub fn dtype(&self) -> Value {
|
219
|
-
Wrap(self.series.borrow().dtype().clone()).
|
218
|
+
Wrap(self.series.borrow().dtype().clone()).into_value()
|
220
219
|
}
|
221
220
|
|
222
221
|
pub fn inner_dtype(&self) -> Option<Value> {
|
@@ -224,15 +223,15 @@ impl RbSeries {
|
|
224
223
|
.borrow()
|
225
224
|
.dtype()
|
226
225
|
.inner_dtype()
|
227
|
-
.map(|dt| Wrap(dt.clone()).
|
226
|
+
.map(|dt| Wrap(dt.clone()).into_value())
|
228
227
|
}
|
229
228
|
|
230
229
|
pub fn set_sorted(&self, reverse: bool) -> Self {
|
231
230
|
let mut out = self.series.borrow().clone();
|
232
231
|
if reverse {
|
233
|
-
out.
|
232
|
+
out.set_sorted_flag(IsSorted::Descending);
|
234
233
|
} else {
|
235
|
-
out.
|
234
|
+
out.set_sorted_flag(IsSorted::Ascending)
|
236
235
|
}
|
237
236
|
out.into()
|
238
237
|
}
|
@@ -255,7 +254,7 @@ impl RbSeries {
|
|
255
254
|
.get(0)
|
256
255
|
.map_err(RbPolarsErr::from)?,
|
257
256
|
)
|
258
|
-
.
|
257
|
+
.into_value())
|
259
258
|
}
|
260
259
|
|
261
260
|
pub fn min(&self) -> RbResult<Value> {
|
@@ -266,7 +265,7 @@ impl RbSeries {
|
|
266
265
|
.get(0)
|
267
266
|
.map_err(RbPolarsErr::from)?,
|
268
267
|
)
|
269
|
-
.
|
268
|
+
.into_value())
|
270
269
|
}
|
271
270
|
|
272
271
|
pub fn sum(&self) -> RbResult<Value> {
|
@@ -277,7 +276,7 @@ impl RbSeries {
|
|
277
276
|
.get(0)
|
278
277
|
.map_err(RbPolarsErr::from)?,
|
279
278
|
)
|
280
|
-
.
|
279
|
+
.into_value())
|
281
280
|
}
|
282
281
|
|
283
282
|
pub fn n_chunks(&self) -> usize {
|
@@ -288,7 +287,7 @@ impl RbSeries {
|
|
288
287
|
let mut binding = self.series.borrow_mut();
|
289
288
|
let res = binding.append(&other.series.borrow());
|
290
289
|
if let Err(e) = res {
|
291
|
-
Err(Error::runtime_error(e.to_string()))
|
290
|
+
Err(Error::new(exception::runtime_error(), e.to_string()))
|
292
291
|
} else {
|
293
292
|
Ok(())
|
294
293
|
}
|
@@ -304,7 +303,7 @@ impl RbSeries {
|
|
304
303
|
|
305
304
|
pub fn new_from_index(&self, index: usize, length: usize) -> RbResult<Self> {
|
306
305
|
if index >= self.series.borrow().len() {
|
307
|
-
Err(Error::new(arg_error(), "index is out of bounds"))
|
306
|
+
Err(Error::new(exception::arg_error(), "index is out of bounds"))
|
308
307
|
} else {
|
309
308
|
Ok(self.series.borrow().new_from_index(index, length).into())
|
310
309
|
}
|
@@ -316,7 +315,10 @@ impl RbSeries {
|
|
316
315
|
let series = self.series.borrow().filter(ca).unwrap();
|
317
316
|
Ok(series.into())
|
318
317
|
} else {
|
319
|
-
Err(Error::
|
318
|
+
Err(Error::new(
|
319
|
+
exception::runtime_error(),
|
320
|
+
"Expected a boolean mask".to_string(),
|
321
|
+
))
|
320
322
|
}
|
321
323
|
}
|
322
324
|
|
@@ -515,7 +517,7 @@ impl RbSeries {
|
|
515
517
|
} else if let Ok(_s) = series.date() {
|
516
518
|
let a = RArray::with_capacity(series.len());
|
517
519
|
for v in series.iter() {
|
518
|
-
a.push::<Value>(Wrap(v).
|
520
|
+
a.push::<Value>(Wrap(v).into_value()).unwrap();
|
519
521
|
}
|
520
522
|
a
|
521
523
|
} else {
|
@@ -546,7 +548,7 @@ impl RbSeries {
|
|
546
548
|
.get(0)
|
547
549
|
.unwrap_or(AnyValue::Null),
|
548
550
|
)
|
549
|
-
.
|
551
|
+
.into_value())
|
550
552
|
}
|
551
553
|
|
552
554
|
pub fn clone(&self) -> Self {
|
@@ -756,11 +758,11 @@ impl RbSeries {
|
|
756
758
|
Ok(RbSeries::new(s))
|
757
759
|
}
|
758
760
|
|
759
|
-
pub fn to_dummies(&self) -> RbResult<RbDataFrame> {
|
761
|
+
pub fn to_dummies(&self, sep: Option<String>) -> RbResult<RbDataFrame> {
|
760
762
|
let df = self
|
761
763
|
.series
|
762
764
|
.borrow()
|
763
|
-
.to_dummies()
|
765
|
+
.to_dummies(sep.as_deref())
|
764
766
|
.map_err(RbPolarsErr::from)?;
|
765
767
|
Ok(df.into())
|
766
768
|
}
|
@@ -1095,8 +1097,8 @@ pub fn to_series_collection(rs: RArray) -> RbResult<Vec<Series>> {
|
|
1095
1097
|
Ok(series)
|
1096
1098
|
}
|
1097
1099
|
|
1098
|
-
pub fn to_rbseries_collection(s: Vec<Series>) ->
|
1099
|
-
s.into_iter().map(RbSeries::new)
|
1100
|
+
pub fn to_rbseries_collection(s: Vec<Series>) -> RArray {
|
1101
|
+
RArray::from_iter(s.into_iter().map(RbSeries::new))
|
1100
1102
|
}
|
1101
1103
|
|
1102
1104
|
impl RbSeries {
|
data/lib/polars/cat_expr.rb
CHANGED
@@ -36,13 +36,9 @@ module Polars
|
|
36
36
|
# # │ cat ┆ i64 │
|
37
37
|
# # ╞══════╪══════╡
|
38
38
|
# # │ a ┆ 2 │
|
39
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
40
39
|
# # │ b ┆ 3 │
|
41
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
42
40
|
# # │ k ┆ 2 │
|
43
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
44
41
|
# # │ z ┆ 1 │
|
45
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
46
42
|
# # │ z ┆ 3 │
|
47
43
|
# # └──────┴──────┘
|
48
44
|
def set_ordering(ordering)
|
@@ -38,13 +38,9 @@ module Polars
|
|
38
38
|
# # │ cat ┆ i64 │
|
39
39
|
# # ╞══════╪══════╡
|
40
40
|
# # │ a ┆ 2 │
|
41
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
42
41
|
# # │ b ┆ 3 │
|
43
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
44
42
|
# # │ k ┆ 2 │
|
45
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
46
43
|
# # │ z ┆ 1 │
|
47
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
48
44
|
# # │ z ┆ 3 │
|
49
45
|
# # └──────┴──────┘
|
50
46
|
def set_ordering(ordering)
|
data/lib/polars/convert.rb
CHANGED
@@ -24,7 +24,6 @@ module Polars
|
|
24
24
|
# # │ i64 ┆ i64 │
|
25
25
|
# # ╞═════╪═════╡
|
26
26
|
# # │ 1 ┆ 3 │
|
27
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
28
27
|
# # │ 2 ┆ 4 │
|
29
28
|
# # └─────┴─────┘
|
30
29
|
def from_hash(data, columns: nil)
|
@@ -54,9 +53,7 @@ module Polars
|
|
54
53
|
# # │ i64 ┆ i64 │
|
55
54
|
# # ╞═════╪═════╡
|
56
55
|
# # │ 1 ┆ 4 │
|
57
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
58
56
|
# # │ 2 ┆ 5 │
|
59
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
60
57
|
# # │ 3 ┆ 6 │
|
61
58
|
# # └─────┴─────┘
|
62
59
|
#
|
@@ -70,9 +67,7 @@ module Polars
|
|
70
67
|
# # │ i32 ┆ i64 │
|
71
68
|
# # ╞═════╪═════╡
|
72
69
|
# # │ 1 ┆ 4 │
|
73
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
74
70
|
# # │ 2 ┆ 5 │
|
75
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
76
71
|
# # │ 3 ┆ 6 │
|
77
72
|
# # └─────┴─────┘
|
78
73
|
#
|
@@ -85,9 +80,7 @@ module Polars
|
|
85
80
|
# # │ i64 ┆ i64 ┆ i32 │
|
86
81
|
# # ╞═════╪═════╪══════╡
|
87
82
|
# # │ 1 ┆ 4 ┆ null │
|
88
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┤
|
89
83
|
# # │ 2 ┆ 5 ┆ null │
|
90
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┤
|
91
84
|
# # │ 3 ┆ 6 ┆ null │
|
92
85
|
# # └─────┴─────┴──────┘
|
93
86
|
# def from_hashes(hashes, infer_schema_length: 50, schema: nil)
|