polars-df 0.20.0 → 0.21.1
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 +27 -0
- data/Cargo.lock +192 -186
- data/LICENSE.txt +1 -1
- data/ext/polars/Cargo.toml +19 -9
- data/ext/polars/src/batched_csv.rs +2 -2
- data/ext/polars/src/catalog/mod.rs +1 -0
- data/ext/polars/src/catalog/unity.rs +450 -0
- data/ext/polars/src/conversion/any_value.rs +9 -19
- data/ext/polars/src/conversion/categorical.rs +30 -0
- data/ext/polars/src/conversion/chunked_array.rs +8 -8
- data/ext/polars/src/conversion/mod.rs +275 -109
- data/ext/polars/src/dataframe/construction.rs +2 -2
- data/ext/polars/src/dataframe/export.rs +2 -2
- data/ext/polars/src/dataframe/general.rs +4 -2
- data/ext/polars/src/dataframe/io.rs +2 -2
- data/ext/polars/src/exceptions.rs +2 -1
- data/ext/polars/src/expr/array.rs +73 -4
- data/ext/polars/src/expr/binary.rs +26 -1
- data/ext/polars/src/expr/bitwise.rs +39 -0
- data/ext/polars/src/expr/categorical.rs +20 -0
- data/ext/polars/src/expr/datatype.rs +37 -0
- data/ext/polars/src/expr/datetime.rs +58 -0
- data/ext/polars/src/expr/general.rs +106 -22
- data/ext/polars/src/expr/list.rs +45 -2
- data/ext/polars/src/expr/meta.rs +5 -28
- data/ext/polars/src/expr/mod.rs +4 -1
- data/ext/polars/src/expr/name.rs +10 -2
- data/ext/polars/src/expr/rolling.rs +21 -1
- data/ext/polars/src/expr/selector.rs +219 -0
- data/ext/polars/src/expr/string.rs +73 -6
- data/ext/polars/src/expr/struct.rs +9 -1
- data/ext/polars/src/file.rs +11 -5
- data/ext/polars/src/functions/io.rs +21 -11
- data/ext/polars/src/functions/lazy.rs +26 -54
- data/ext/polars/src/functions/meta.rs +2 -2
- data/ext/polars/src/functions/misc.rs +1 -1
- data/ext/polars/src/functions/string_cache.rs +4 -5
- data/ext/polars/src/interop/numo/numo_rs.rs +1 -1
- data/ext/polars/src/interop/numo/to_numo_series.rs +1 -1
- data/ext/polars/src/io/mod.rs +102 -0
- data/ext/polars/src/lazyframe/general.rs +124 -111
- data/ext/polars/src/lazyframe/serde.rs +1 -1
- data/ext/polars/src/lazyframe/sink.rs +6 -6
- data/ext/polars/src/lib.rs +216 -29
- data/ext/polars/src/map/dataframe.rs +9 -9
- data/ext/polars/src/map/lazy.rs +1 -1
- data/ext/polars/src/map/mod.rs +31 -19
- data/ext/polars/src/map/series.rs +9 -9
- data/ext/polars/src/on_startup.rs +5 -2
- data/ext/polars/src/rb_modules.rs +1 -1
- data/ext/polars/src/series/aggregation.rs +44 -0
- data/ext/polars/src/series/construction.rs +11 -7
- data/ext/polars/src/series/export.rs +6 -4
- data/ext/polars/src/series/general.rs +75 -210
- data/ext/polars/src/series/import.rs +2 -2
- data/ext/polars/src/series/map.rs +227 -0
- data/ext/polars/src/series/mod.rs +2 -1
- data/ext/polars/src/series/scatter.rs +1 -1
- data/ext/polars/src/utils.rs +10 -2
- data/lib/polars/array_expr.rb +382 -3
- data/lib/polars/array_name_space.rb +281 -0
- data/lib/polars/binary_expr.rb +67 -0
- data/lib/polars/binary_name_space.rb +43 -0
- data/lib/polars/cat_expr.rb +224 -0
- data/lib/polars/cat_name_space.rb +130 -32
- data/lib/polars/catalog/unity/catalog_info.rb +20 -0
- data/lib/polars/catalog/unity/column_info.rb +31 -0
- data/lib/polars/catalog/unity/namespace_info.rb +21 -0
- data/lib/polars/catalog/unity/table_info.rb +50 -0
- data/lib/polars/catalog.rb +448 -0
- data/lib/polars/config.rb +2 -2
- data/lib/polars/convert.rb +12 -2
- data/lib/polars/data_frame.rb +834 -48
- data/lib/polars/data_type_expr.rb +52 -0
- data/lib/polars/data_types.rb +61 -5
- data/lib/polars/date_time_expr.rb +251 -0
- data/lib/polars/date_time_name_space.rb +299 -0
- data/lib/polars/exceptions.rb +7 -2
- data/lib/polars/expr.rb +1247 -211
- data/lib/polars/functions/col.rb +6 -5
- data/lib/polars/functions/datatype.rb +21 -0
- data/lib/polars/functions/lazy.rb +127 -15
- data/lib/polars/functions/repeat.rb +4 -0
- data/lib/polars/io/csv.rb +19 -1
- data/lib/polars/io/json.rb +16 -0
- data/lib/polars/io/ndjson.rb +13 -0
- data/lib/polars/io/parquet.rb +70 -66
- data/lib/polars/io/scan_options.rb +47 -0
- data/lib/polars/lazy_frame.rb +1099 -95
- data/lib/polars/list_expr.rb +400 -11
- data/lib/polars/list_name_space.rb +321 -5
- data/lib/polars/meta_expr.rb +71 -22
- data/lib/polars/name_expr.rb +36 -0
- data/lib/polars/scan_cast_options.rb +64 -0
- data/lib/polars/schema.rb +84 -3
- data/lib/polars/selector.rb +210 -0
- data/lib/polars/selectors.rb +932 -203
- data/lib/polars/series.rb +1083 -63
- data/lib/polars/string_expr.rb +435 -9
- data/lib/polars/string_name_space.rb +729 -45
- data/lib/polars/struct_expr.rb +103 -0
- data/lib/polars/struct_name_space.rb +19 -1
- data/lib/polars/utils/parse.rb +40 -0
- data/lib/polars/utils/various.rb +18 -1
- data/lib/polars/utils.rb +9 -1
- data/lib/polars/version.rb +1 -1
- data/lib/polars.rb +10 -0
- metadata +20 -2
@@ -1,5 +1,5 @@
|
|
1
|
-
use magnus::{
|
2
|
-
use polars::frame::row::{rows_to_schema_supertypes, rows_to_supertypes
|
1
|
+
use magnus::{RArray, RHash, Symbol, Value, prelude::*, r_hash::ForEach};
|
2
|
+
use polars::frame::row::{Row, rows_to_schema_supertypes, rows_to_supertypes};
|
3
3
|
use polars::prelude::*;
|
4
4
|
|
5
5
|
use super::*;
|
@@ -1,9 +1,9 @@
|
|
1
|
-
use magnus::{
|
1
|
+
use magnus::{IntoValue, RArray, Value, prelude::*};
|
2
2
|
|
3
3
|
use super::*;
|
4
|
+
use crate::RbResult;
|
4
5
|
use crate::conversion::{ObjectValue, Wrap};
|
5
6
|
use crate::interop::arrow::to_ruby::dataframe_to_stream;
|
6
|
-
use crate::RbResult;
|
7
7
|
|
8
8
|
impl RbDataFrame {
|
9
9
|
pub fn row_tuple(&self, idx: i64) -> Value {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
use std::hash::BuildHasher;
|
2
2
|
|
3
3
|
use either::Either;
|
4
|
-
use magnus::{
|
4
|
+
use magnus::{IntoValue, RArray, Value, prelude::*, typed_data::Obj};
|
5
5
|
use polars::prelude::pivot::{pivot, pivot_stable};
|
6
6
|
use polars::prelude::*;
|
7
7
|
|
@@ -416,17 +416,19 @@ impl RbDataFrame {
|
|
416
416
|
columns: Option<Vec<String>>,
|
417
417
|
separator: Option<String>,
|
418
418
|
drop_first: bool,
|
419
|
+
drop_nulls: bool,
|
419
420
|
) -> RbResult<Self> {
|
420
421
|
let df = match columns {
|
421
422
|
Some(cols) => self.df.borrow().columns_to_dummies(
|
422
423
|
cols.iter().map(|x| x as &str).collect(),
|
423
424
|
separator.as_deref(),
|
424
425
|
drop_first,
|
426
|
+
drop_nulls,
|
425
427
|
),
|
426
428
|
None => self
|
427
429
|
.df
|
428
430
|
.borrow()
|
429
|
-
.to_dummies(separator.as_deref(), drop_first),
|
431
|
+
.to_dummies(separator.as_deref(), drop_first, drop_nulls),
|
430
432
|
}
|
431
433
|
.map_err(RbPolarsErr::from)?;
|
432
434
|
Ok(df.into())
|
@@ -1,5 +1,5 @@
|
|
1
1
|
use crate::rb_modules;
|
2
|
-
use magnus::{
|
2
|
+
use magnus::{Error, exception};
|
3
3
|
use std::borrow::Cow;
|
4
4
|
|
5
5
|
macro_rules! create_exception {
|
@@ -20,5 +20,6 @@ macro_rules! create_exception {
|
|
20
20
|
create_exception!(RbTypeError, exception::type_error());
|
21
21
|
create_exception!(RbValueError, exception::arg_error());
|
22
22
|
create_exception!(RbOverflowError, exception::range_error());
|
23
|
+
create_exception!(RbIndexError, exception::index_error());
|
23
24
|
create_exception!(ComputeError, rb_modules::compute_error());
|
24
25
|
create_exception!(InvalidOperationError, rb_modules::invalid_operation_error());
|
@@ -1,20 +1,41 @@
|
|
1
|
+
use magnus::Value;
|
1
2
|
use polars::prelude::*;
|
2
3
|
|
3
|
-
use crate::RbExpr;
|
4
|
+
use crate::{RbExpr, RbPolarsErr, RbResult};
|
4
5
|
|
5
6
|
impl RbExpr {
|
6
|
-
pub fn
|
7
|
+
pub fn arr_len(&self) -> Self {
|
8
|
+
self.inner.clone().arr().len().into()
|
9
|
+
}
|
10
|
+
|
11
|
+
pub fn arr_max(&self) -> Self {
|
7
12
|
self.inner.clone().arr().max().into()
|
8
13
|
}
|
9
14
|
|
10
|
-
pub fn
|
15
|
+
pub fn arr_min(&self) -> Self {
|
11
16
|
self.inner.clone().arr().min().into()
|
12
17
|
}
|
13
18
|
|
14
|
-
pub fn
|
19
|
+
pub fn arr_sum(&self) -> Self {
|
15
20
|
self.inner.clone().arr().sum().into()
|
16
21
|
}
|
17
22
|
|
23
|
+
pub fn arr_std(&self, ddof: u8) -> Self {
|
24
|
+
self.inner.clone().arr().std(ddof).into()
|
25
|
+
}
|
26
|
+
|
27
|
+
pub fn arr_var(&self, ddof: u8) -> Self {
|
28
|
+
self.inner.clone().arr().var(ddof).into()
|
29
|
+
}
|
30
|
+
|
31
|
+
pub fn arr_mean(&self) -> Self {
|
32
|
+
self.inner.clone().arr().mean().into()
|
33
|
+
}
|
34
|
+
|
35
|
+
pub fn arr_median(&self) -> Self {
|
36
|
+
self.inner.clone().arr().median().into()
|
37
|
+
}
|
38
|
+
|
18
39
|
pub fn arr_unique(&self, maintain_order: bool) -> Self {
|
19
40
|
if maintain_order {
|
20
41
|
self.inner.clone().arr().unique_stable().into()
|
@@ -23,6 +44,10 @@ impl RbExpr {
|
|
23
44
|
}
|
24
45
|
}
|
25
46
|
|
47
|
+
pub fn arr_n_unique(&self) -> Self {
|
48
|
+
self.inner.clone().arr().n_unique().into()
|
49
|
+
}
|
50
|
+
|
26
51
|
pub fn arr_to_list(&self) -> Self {
|
27
52
|
self.inner.clone().arr().to_list().into()
|
28
53
|
}
|
@@ -90,4 +115,48 @@ impl RbExpr {
|
|
90
115
|
.count_matches(expr.inner.clone())
|
91
116
|
.into()
|
92
117
|
}
|
118
|
+
|
119
|
+
pub fn arr_to_struct(&self, name_gen: Option<Value>) -> Self {
|
120
|
+
if name_gen.is_some() {
|
121
|
+
todo!();
|
122
|
+
}
|
123
|
+
self.inner.clone().arr().to_struct(None).into()
|
124
|
+
}
|
125
|
+
|
126
|
+
pub fn arr_slice(
|
127
|
+
&self,
|
128
|
+
offset: &RbExpr,
|
129
|
+
length: Option<&RbExpr>,
|
130
|
+
as_array: bool,
|
131
|
+
) -> RbResult<Self> {
|
132
|
+
let length = match length {
|
133
|
+
Some(i) => i.inner.clone(),
|
134
|
+
None => lit(i64::MAX),
|
135
|
+
};
|
136
|
+
Ok(self
|
137
|
+
.inner
|
138
|
+
.clone()
|
139
|
+
.arr()
|
140
|
+
.slice(offset.inner.clone(), length, as_array)
|
141
|
+
.map_err(RbPolarsErr::from)?
|
142
|
+
.into())
|
143
|
+
}
|
144
|
+
|
145
|
+
pub fn arr_tail(&self, n: &RbExpr, as_array: bool) -> RbResult<Self> {
|
146
|
+
Ok(self
|
147
|
+
.inner
|
148
|
+
.clone()
|
149
|
+
.arr()
|
150
|
+
.tail(n.inner.clone(), as_array)
|
151
|
+
.map_err(RbPolarsErr::from)?
|
152
|
+
.into())
|
153
|
+
}
|
154
|
+
|
155
|
+
pub fn arr_shift(&self, n: &RbExpr) -> Self {
|
156
|
+
self.inner.clone().arr().shift(n.inner.clone()).into()
|
157
|
+
}
|
158
|
+
|
159
|
+
pub fn arr_explode(&self) -> Self {
|
160
|
+
self.inner.clone().arr().explode().into()
|
161
|
+
}
|
93
162
|
}
|
@@ -1,4 +1,5 @@
|
|
1
|
-
use crate::
|
1
|
+
use crate::expr::datatype::RbDataTypeExpr;
|
2
|
+
use crate::{RbExpr, RbResult};
|
2
3
|
|
3
4
|
impl RbExpr {
|
4
5
|
pub fn bin_contains(&self, lit: &RbExpr) -> Self {
|
@@ -40,4 +41,28 @@ impl RbExpr {
|
|
40
41
|
pub fn bin_base64_encode(&self) -> Self {
|
41
42
|
self.inner.clone().binary().base64_encode().into()
|
42
43
|
}
|
44
|
+
|
45
|
+
pub fn bin_reinterpret(&self, dtype: &RbDataTypeExpr, kind: String) -> RbResult<Self> {
|
46
|
+
use crate::RbValueError;
|
47
|
+
|
48
|
+
let is_little_endian = match kind.to_lowercase().as_str() {
|
49
|
+
"little" => true,
|
50
|
+
"big" => false,
|
51
|
+
_ => {
|
52
|
+
return Err(RbValueError::new_err(format!(
|
53
|
+
"Invalid endianness: {kind}. Valid values are \"little\" or \"big\"."
|
54
|
+
)));
|
55
|
+
}
|
56
|
+
};
|
57
|
+
Ok(self
|
58
|
+
.inner
|
59
|
+
.clone()
|
60
|
+
.binary()
|
61
|
+
.reinterpret(dtype.inner.clone(), is_little_endian)
|
62
|
+
.into())
|
63
|
+
}
|
64
|
+
|
65
|
+
pub fn bin_size_bytes(&self) -> Self {
|
66
|
+
self.inner.clone().binary().size_bytes().into()
|
67
|
+
}
|
43
68
|
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
use crate::RbExpr;
|
2
|
+
|
3
|
+
impl RbExpr {
|
4
|
+
pub fn bitwise_count_ones(&self) -> Self {
|
5
|
+
self.inner.clone().bitwise_count_ones().into()
|
6
|
+
}
|
7
|
+
|
8
|
+
pub fn bitwise_count_zeros(&self) -> Self {
|
9
|
+
self.inner.clone().bitwise_count_zeros().into()
|
10
|
+
}
|
11
|
+
|
12
|
+
pub fn bitwise_leading_ones(&self) -> Self {
|
13
|
+
self.inner.clone().bitwise_leading_ones().into()
|
14
|
+
}
|
15
|
+
|
16
|
+
pub fn bitwise_leading_zeros(&self) -> Self {
|
17
|
+
self.inner.clone().bitwise_leading_zeros().into()
|
18
|
+
}
|
19
|
+
|
20
|
+
pub fn bitwise_trailing_ones(&self) -> Self {
|
21
|
+
self.inner.clone().bitwise_trailing_ones().into()
|
22
|
+
}
|
23
|
+
|
24
|
+
pub fn bitwise_trailing_zeros(&self) -> Self {
|
25
|
+
self.inner.clone().bitwise_trailing_zeros().into()
|
26
|
+
}
|
27
|
+
|
28
|
+
pub fn bitwise_and(&self) -> Self {
|
29
|
+
self.inner.clone().bitwise_and().into()
|
30
|
+
}
|
31
|
+
|
32
|
+
pub fn bitwise_or(&self) -> Self {
|
33
|
+
self.inner.clone().bitwise_or().into()
|
34
|
+
}
|
35
|
+
|
36
|
+
pub fn bitwise_xor(&self) -> Self {
|
37
|
+
self.inner.clone().bitwise_xor().into()
|
38
|
+
}
|
39
|
+
}
|
@@ -4,4 +4,24 @@ impl RbExpr {
|
|
4
4
|
pub fn cat_get_categories(&self) -> Self {
|
5
5
|
self.inner.clone().cat().get_categories().into()
|
6
6
|
}
|
7
|
+
|
8
|
+
pub fn cat_len_bytes(&self) -> Self {
|
9
|
+
self.inner.clone().cat().len_bytes().into()
|
10
|
+
}
|
11
|
+
|
12
|
+
pub fn cat_len_chars(&self) -> Self {
|
13
|
+
self.inner.clone().cat().len_chars().into()
|
14
|
+
}
|
15
|
+
|
16
|
+
pub fn cat_starts_with(&self, prefix: String) -> Self {
|
17
|
+
self.inner.clone().cat().starts_with(prefix).into()
|
18
|
+
}
|
19
|
+
|
20
|
+
pub fn cat_ends_with(&self, suffix: String) -> Self {
|
21
|
+
self.inner.clone().cat().ends_with(suffix).into()
|
22
|
+
}
|
23
|
+
|
24
|
+
pub fn cat_slice(&self, offset: i64, length: Option<usize>) -> Self {
|
25
|
+
self.inner.clone().cat().slice(offset, length).into()
|
26
|
+
}
|
7
27
|
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
use magnus::{IntoValue, Value};
|
2
|
+
use polars::prelude::{DataType, DataTypeExpr, Schema};
|
3
|
+
|
4
|
+
use crate::prelude::Wrap;
|
5
|
+
use crate::{RbExpr, RbPolarsErr, RbResult};
|
6
|
+
|
7
|
+
#[magnus::wrap(class = "Polars::RbDataTypeExpr")]
|
8
|
+
#[repr(transparent)]
|
9
|
+
#[derive(Clone)]
|
10
|
+
pub struct RbDataTypeExpr {
|
11
|
+
pub inner: DataTypeExpr,
|
12
|
+
}
|
13
|
+
|
14
|
+
impl From<DataTypeExpr> for RbDataTypeExpr {
|
15
|
+
fn from(expr: DataTypeExpr) -> Self {
|
16
|
+
RbDataTypeExpr { inner: expr }
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
impl RbDataTypeExpr {
|
21
|
+
pub fn from_dtype(datatype: Wrap<DataType>) -> Self {
|
22
|
+
DataTypeExpr::Literal(datatype.0).into()
|
23
|
+
}
|
24
|
+
|
25
|
+
pub fn of_expr(expr: &RbExpr) -> Self {
|
26
|
+
DataTypeExpr::OfExpr(Box::new(expr.inner.clone())).into()
|
27
|
+
}
|
28
|
+
|
29
|
+
pub fn collect_dtype(&self, schema: Wrap<Schema>) -> RbResult<Value> {
|
30
|
+
let dtype = self
|
31
|
+
.clone()
|
32
|
+
.inner
|
33
|
+
.into_datatype(&schema.0)
|
34
|
+
.map_err(RbPolarsErr::from)?;
|
35
|
+
Ok(Wrap(dtype).into_value())
|
36
|
+
}
|
37
|
+
}
|
@@ -4,6 +4,20 @@ use crate::conversion::Wrap;
|
|
4
4
|
use crate::{RbExpr, RbPolarsErr, RbResult};
|
5
5
|
|
6
6
|
impl RbExpr {
|
7
|
+
pub fn dt_add_business_days(
|
8
|
+
&self,
|
9
|
+
n: &RbExpr,
|
10
|
+
week_mask: [bool; 7],
|
11
|
+
holidays: Vec<i32>,
|
12
|
+
roll: Wrap<Roll>,
|
13
|
+
) -> Self {
|
14
|
+
self.inner
|
15
|
+
.clone()
|
16
|
+
.dt()
|
17
|
+
.add_business_days(n.inner.clone(), week_mask, holidays, roll.0)
|
18
|
+
.into()
|
19
|
+
}
|
20
|
+
|
7
21
|
pub fn dt_to_string(&self, format: String) -> Self {
|
8
22
|
self.inner.clone().dt().to_string(&format).into()
|
9
23
|
}
|
@@ -90,6 +104,34 @@ impl RbExpr {
|
|
90
104
|
self.inner.clone().dt().round(every.inner.clone()).into()
|
91
105
|
}
|
92
106
|
|
107
|
+
#[allow(clippy::too_many_arguments)]
|
108
|
+
pub fn dt_replace(
|
109
|
+
&self,
|
110
|
+
year: &Self,
|
111
|
+
month: &Self,
|
112
|
+
day: &Self,
|
113
|
+
hour: &Self,
|
114
|
+
minute: &Self,
|
115
|
+
second: &Self,
|
116
|
+
microsecond: &Self,
|
117
|
+
ambiguous: &Self,
|
118
|
+
) -> Self {
|
119
|
+
self.inner
|
120
|
+
.clone()
|
121
|
+
.dt()
|
122
|
+
.replace(
|
123
|
+
year.inner.clone(),
|
124
|
+
month.inner.clone(),
|
125
|
+
day.inner.clone(),
|
126
|
+
hour.inner.clone(),
|
127
|
+
minute.inner.clone(),
|
128
|
+
second.inner.clone(),
|
129
|
+
microsecond.inner.clone(),
|
130
|
+
ambiguous.inner.clone(),
|
131
|
+
)
|
132
|
+
.into()
|
133
|
+
}
|
134
|
+
|
93
135
|
pub fn dt_combine(&self, time: &Self, time_unit: Wrap<TimeUnit>) -> Self {
|
94
136
|
self.inner
|
95
137
|
.clone()
|
@@ -98,10 +140,26 @@ impl RbExpr {
|
|
98
140
|
.into()
|
99
141
|
}
|
100
142
|
|
143
|
+
pub fn dt_millennium(&self) -> Self {
|
144
|
+
self.inner.clone().dt().millennium().into()
|
145
|
+
}
|
146
|
+
|
147
|
+
pub fn dt_century(&self) -> Self {
|
148
|
+
self.inner.clone().dt().century().into()
|
149
|
+
}
|
150
|
+
|
101
151
|
pub fn dt_year(&self) -> Self {
|
102
152
|
self.clone().inner.dt().year().into()
|
103
153
|
}
|
104
154
|
|
155
|
+
pub fn dt_is_business_day(&self, week_mask: [bool; 7], holidays: Vec<i32>) -> Self {
|
156
|
+
self.inner
|
157
|
+
.clone()
|
158
|
+
.dt()
|
159
|
+
.is_business_day(week_mask, holidays)
|
160
|
+
.into()
|
161
|
+
}
|
162
|
+
|
105
163
|
pub fn dt_is_leap_year(&self) -> Self {
|
106
164
|
self.clone().inner.dt().is_leap_year().into()
|
107
165
|
}
|
@@ -6,10 +6,11 @@ use polars::prelude::*;
|
|
6
6
|
use polars::series::ops::NullBehavior;
|
7
7
|
use polars_core::series::IsSorted;
|
8
8
|
|
9
|
-
use
|
9
|
+
use super::selector::RbSelector;
|
10
|
+
use crate::conversion::{Wrap, parse_fill_null_strategy};
|
10
11
|
use crate::map::lazy::map_single;
|
11
12
|
use crate::rb_exprs_to_exprs;
|
12
|
-
use crate::{RbExpr, RbResult};
|
13
|
+
use crate::{RbExpr, RbPolarsErr, RbResult};
|
13
14
|
|
14
15
|
impl RbExpr {
|
15
16
|
pub fn add(&self, rhs: &Self) -> RbResult<Self> {
|
@@ -276,17 +277,8 @@ impl RbExpr {
|
|
276
277
|
.into()
|
277
278
|
}
|
278
279
|
|
279
|
-
pub fn arg_sort(&self,
|
280
|
-
self.clone()
|
281
|
-
.inner
|
282
|
-
.arg_sort(SortOptions {
|
283
|
-
descending: reverse,
|
284
|
-
nulls_last,
|
285
|
-
multithreaded: true,
|
286
|
-
maintain_order: false,
|
287
|
-
limit: None,
|
288
|
-
})
|
289
|
-
.into()
|
280
|
+
pub fn arg_sort(&self, descending: bool, nulls_last: bool) -> Self {
|
281
|
+
self.inner.clone().arg_sort(descending, nulls_last).into()
|
290
282
|
}
|
291
283
|
|
292
284
|
pub fn top_k(&self, k: &Self) -> Self {
|
@@ -331,6 +323,10 @@ impl RbExpr {
|
|
331
323
|
self.inner.clone().arg_min().into()
|
332
324
|
}
|
333
325
|
|
326
|
+
pub fn index_of(&self, element: &Self) -> Self {
|
327
|
+
self.inner.clone().index_of(element.inner.clone()).into()
|
328
|
+
}
|
329
|
+
|
334
330
|
pub fn search_sorted(
|
335
331
|
&self,
|
336
332
|
element: &Self,
|
@@ -437,6 +433,13 @@ impl RbExpr {
|
|
437
433
|
.into()
|
438
434
|
}
|
439
435
|
|
436
|
+
pub fn is_close(&self, other: &Self, abs_tol: f64, rel_tol: f64, nans_equal: bool) -> Self {
|
437
|
+
self.inner
|
438
|
+
.clone()
|
439
|
+
.is_close(other.inner.clone(), abs_tol, rel_tol, nans_equal)
|
440
|
+
.into()
|
441
|
+
}
|
442
|
+
|
440
443
|
pub fn approx_n_unique(&self) -> Self {
|
441
444
|
self.inner.clone().approx_n_unique().into()
|
442
445
|
}
|
@@ -490,6 +493,10 @@ impl RbExpr {
|
|
490
493
|
self.inner.clone().round(decimals, mode.0).into()
|
491
494
|
}
|
492
495
|
|
496
|
+
pub fn round_sig_figs(&self, digits: i32) -> Self {
|
497
|
+
self.clone().inner.round_sig_figs(digits).into()
|
498
|
+
}
|
499
|
+
|
493
500
|
pub fn floor(&self) -> Self {
|
494
501
|
self.inner.clone().floor().into()
|
495
502
|
}
|
@@ -525,6 +532,10 @@ impl RbExpr {
|
|
525
532
|
self.inner.clone().tan().into()
|
526
533
|
}
|
527
534
|
|
535
|
+
pub fn cot(&self) -> Self {
|
536
|
+
self.inner.clone().cot().into()
|
537
|
+
}
|
538
|
+
|
528
539
|
pub fn arcsin(&self) -> Self {
|
529
540
|
self.inner.clone().arcsin().into()
|
530
541
|
}
|
@@ -561,6 +572,14 @@ impl RbExpr {
|
|
561
572
|
self.inner.clone().arctanh().into()
|
562
573
|
}
|
563
574
|
|
575
|
+
pub fn degrees(&self) -> Self {
|
576
|
+
self.inner.clone().degrees().into()
|
577
|
+
}
|
578
|
+
|
579
|
+
pub fn radians(&self) -> Self {
|
580
|
+
self.inner.clone().radians().into()
|
581
|
+
}
|
582
|
+
|
564
583
|
pub fn sign(&self) -> Self {
|
565
584
|
self.inner.clone().sign().into()
|
566
585
|
}
|
@@ -574,18 +593,35 @@ impl RbExpr {
|
|
574
593
|
Ok(self.inner.clone().over(partition_by).into())
|
575
594
|
}
|
576
595
|
|
577
|
-
pub fn
|
578
|
-
self
|
596
|
+
pub fn rolling(
|
597
|
+
&self,
|
598
|
+
index_column: String,
|
599
|
+
period: String,
|
600
|
+
offset: String,
|
601
|
+
closed: Wrap<ClosedWindow>,
|
602
|
+
) -> RbResult<Self> {
|
603
|
+
let options = RollingGroupOptions {
|
604
|
+
index_column: index_column.into(),
|
605
|
+
period: Duration::try_parse(&period).map_err(RbPolarsErr::from)?,
|
606
|
+
offset: Duration::try_parse(&offset).map_err(RbPolarsErr::from)?,
|
607
|
+
closed_window: closed.0,
|
608
|
+
};
|
609
|
+
|
610
|
+
Ok(self.inner.clone().rolling(options).into())
|
579
611
|
}
|
580
612
|
|
581
|
-
pub fn
|
582
|
-
self.inner.clone().
|
613
|
+
pub fn and_(&self, expr: &Self) -> Self {
|
614
|
+
self.inner.clone().and(expr.inner.clone()).into()
|
583
615
|
}
|
584
616
|
|
585
|
-
pub fn
|
617
|
+
pub fn or_(&self, expr: &Self) -> Self {
|
586
618
|
self.inner.clone().or(expr.inner.clone()).into()
|
587
619
|
}
|
588
620
|
|
621
|
+
pub fn xor_(&self, expr: &Self) -> Self {
|
622
|
+
self.inner.clone().xor(expr.inner.clone()).into()
|
623
|
+
}
|
624
|
+
|
589
625
|
pub fn is_in(&self, expr: &Self, nulls_equal: bool) -> Self {
|
590
626
|
self.inner
|
591
627
|
.clone()
|
@@ -601,6 +637,14 @@ impl RbExpr {
|
|
601
637
|
self.inner.clone().pow(exponent.inner.clone()).into()
|
602
638
|
}
|
603
639
|
|
640
|
+
pub fn sqrt(&self) -> Self {
|
641
|
+
self.inner.clone().sqrt().into()
|
642
|
+
}
|
643
|
+
|
644
|
+
pub fn cbrt(&self) -> Self {
|
645
|
+
self.inner.clone().cbrt().into()
|
646
|
+
}
|
647
|
+
|
604
648
|
pub fn cum_sum(&self, reverse: bool) -> Self {
|
605
649
|
self.inner.clone().cum_sum(reverse).into()
|
606
650
|
}
|
@@ -655,10 +699,6 @@ impl RbExpr {
|
|
655
699
|
self.inner.clone().mode().into()
|
656
700
|
}
|
657
701
|
|
658
|
-
pub fn exclude(&self, columns: Vec<String>) -> Self {
|
659
|
-
self.inner.clone().exclude(columns).into()
|
660
|
-
}
|
661
|
-
|
662
702
|
pub fn interpolate(&self, method: Wrap<InterpolationMethod>) -> Self {
|
663
703
|
self.inner.clone().interpolate(method.0).into()
|
664
704
|
}
|
@@ -768,6 +808,15 @@ impl RbExpr {
|
|
768
808
|
self.inner.clone().ewm_mean(options).into()
|
769
809
|
}
|
770
810
|
|
811
|
+
pub fn ewm_mean_by(&self, times: &RbExpr, half_life: String) -> RbResult<Self> {
|
812
|
+
let half_life = Duration::try_parse(&half_life).map_err(RbPolarsErr::from)?;
|
813
|
+
Ok(self
|
814
|
+
.inner
|
815
|
+
.clone()
|
816
|
+
.ewm_mean_by(times.inner.clone(), half_life)
|
817
|
+
.into())
|
818
|
+
}
|
819
|
+
|
771
820
|
pub fn ewm_std(
|
772
821
|
&self,
|
773
822
|
alpha: f64,
|
@@ -823,6 +872,10 @@ impl RbExpr {
|
|
823
872
|
self.inner.clone().log(base).into()
|
824
873
|
}
|
825
874
|
|
875
|
+
pub fn log1p(&self) -> Self {
|
876
|
+
self.inner.clone().log1p().into()
|
877
|
+
}
|
878
|
+
|
826
879
|
pub fn exp(&self) -> Self {
|
827
880
|
self.inner.clone().exp().into()
|
828
881
|
}
|
@@ -868,4 +921,35 @@ impl RbExpr {
|
|
868
921
|
)
|
869
922
|
.into()
|
870
923
|
}
|
924
|
+
|
925
|
+
pub fn hist(
|
926
|
+
&self,
|
927
|
+
bins: Option<&RbExpr>,
|
928
|
+
bin_count: Option<usize>,
|
929
|
+
include_category: bool,
|
930
|
+
include_breakpoint: bool,
|
931
|
+
) -> Self {
|
932
|
+
let bins = bins.map(|e| e.inner.clone());
|
933
|
+
self.inner
|
934
|
+
.clone()
|
935
|
+
.hist(bins, bin_count, include_category, include_breakpoint)
|
936
|
+
.into()
|
937
|
+
}
|
938
|
+
|
939
|
+
#[allow(clippy::wrong_self_convention)]
|
940
|
+
pub fn into_selector(&self) -> RbResult<RbSelector> {
|
941
|
+
Ok(self
|
942
|
+
.inner
|
943
|
+
.clone()
|
944
|
+
.into_selector()
|
945
|
+
.ok_or_else(
|
946
|
+
|| polars_err!(InvalidOperation: "expr `{}` is not a selector", &self.inner),
|
947
|
+
)
|
948
|
+
.map_err(RbPolarsErr::from)?
|
949
|
+
.into())
|
950
|
+
}
|
951
|
+
|
952
|
+
pub fn new_selector(selector: &RbSelector) -> Self {
|
953
|
+
Expr::Selector(selector.inner.clone()).into()
|
954
|
+
}
|
871
955
|
}
|