polars-df 0.13.0 → 0.15.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 +30 -0
- data/Cargo.lock +1368 -319
- data/LICENSE.txt +1 -0
- data/README.md +1 -2
- data/ext/polars/Cargo.toml +15 -6
- data/ext/polars/src/batched_csv.rs +10 -13
- data/ext/polars/src/conversion/any_value.rs +37 -21
- data/ext/polars/src/conversion/chunked_array.rs +3 -3
- data/ext/polars/src/conversion/mod.rs +159 -46
- data/ext/polars/src/dataframe/construction.rs +4 -7
- data/ext/polars/src/dataframe/export.rs +9 -2
- data/ext/polars/src/dataframe/general.rs +22 -16
- data/ext/polars/src/dataframe/io.rs +78 -174
- data/ext/polars/src/dataframe/mod.rs +1 -0
- data/ext/polars/src/dataframe/serde.rs +15 -0
- data/ext/polars/src/error.rs +31 -48
- data/ext/polars/src/exceptions.rs +24 -0
- data/ext/polars/src/expr/binary.rs +4 -42
- data/ext/polars/src/expr/datetime.rs +16 -7
- data/ext/polars/src/expr/general.rs +14 -23
- data/ext/polars/src/expr/list.rs +18 -11
- data/ext/polars/src/expr/name.rs +3 -2
- data/ext/polars/src/expr/rolling.rs +6 -7
- data/ext/polars/src/expr/string.rs +17 -37
- data/ext/polars/src/file.rs +59 -22
- data/ext/polars/src/functions/business.rs +15 -0
- data/ext/polars/src/functions/io.rs +6 -6
- data/ext/polars/src/functions/lazy.rs +17 -8
- data/ext/polars/src/functions/mod.rs +1 -0
- data/ext/polars/src/functions/range.rs +4 -2
- data/ext/polars/src/interop/arrow/mod.rs +1 -0
- data/ext/polars/src/interop/arrow/to_ruby.rs +83 -0
- data/ext/polars/src/interop/mod.rs +1 -0
- data/ext/polars/src/lazyframe/general.rs +877 -0
- data/ext/polars/src/lazyframe/mod.rs +3 -825
- data/ext/polars/src/lazyframe/serde.rs +31 -0
- data/ext/polars/src/lib.rs +44 -13
- data/ext/polars/src/map/dataframe.rs +46 -14
- data/ext/polars/src/map/lazy.rs +65 -4
- data/ext/polars/src/map/mod.rs +17 -16
- data/ext/polars/src/map/series.rs +106 -64
- data/ext/polars/src/on_startup.rs +2 -2
- data/ext/polars/src/series/aggregation.rs +1 -5
- data/ext/polars/src/series/arithmetic.rs +10 -10
- data/ext/polars/src/series/construction.rs +52 -25
- data/ext/polars/src/series/export.rs +1 -1
- data/ext/polars/src/series/general.rs +643 -0
- data/ext/polars/src/series/import.rs +55 -0
- data/ext/polars/src/series/mod.rs +11 -638
- data/ext/polars/src/series/scatter.rs +2 -2
- data/ext/polars/src/utils.rs +0 -20
- data/lib/polars/batched_csv_reader.rb +0 -2
- data/lib/polars/binary_expr.rb +133 -9
- data/lib/polars/binary_name_space.rb +101 -6
- data/lib/polars/config.rb +4 -0
- data/lib/polars/data_frame.rb +285 -62
- data/lib/polars/data_type_group.rb +28 -0
- data/lib/polars/data_types.rb +2 -0
- data/lib/polars/date_time_expr.rb +244 -0
- data/lib/polars/date_time_name_space.rb +87 -0
- data/lib/polars/expr.rb +109 -8
- data/lib/polars/functions/as_datatype.rb +51 -2
- data/lib/polars/functions/col.rb +1 -1
- data/lib/polars/functions/eager.rb +1 -3
- data/lib/polars/functions/lazy.rb +88 -10
- data/lib/polars/functions/range/time_range.rb +21 -21
- data/lib/polars/io/csv.rb +14 -16
- data/lib/polars/io/database.rb +2 -2
- data/lib/polars/io/ipc.rb +14 -12
- data/lib/polars/io/ndjson.rb +10 -0
- data/lib/polars/io/parquet.rb +168 -111
- data/lib/polars/lazy_frame.rb +649 -15
- data/lib/polars/list_name_space.rb +169 -0
- data/lib/polars/selectors.rb +1144 -0
- data/lib/polars/series.rb +470 -40
- data/lib/polars/string_cache.rb +27 -1
- data/lib/polars/string_expr.rb +0 -1
- data/lib/polars/string_name_space.rb +73 -3
- data/lib/polars/struct_name_space.rb +31 -7
- data/lib/polars/utils/various.rb +5 -1
- data/lib/polars/utils.rb +45 -10
- data/lib/polars/version.rb +1 -1
- data/lib/polars.rb +2 -1
- metadata +14 -4
- data/lib/polars/functions.rb +0 -57
@@ -1,16 +1,16 @@
|
|
1
|
-
use magnus::{prelude::*, RArray};
|
1
|
+
use magnus::{prelude::*, RArray, RString};
|
2
2
|
use polars_core::prelude::*;
|
3
3
|
|
4
4
|
use crate::any_value::rb_object_to_any_value;
|
5
5
|
use crate::conversion::{slice_extract_wrapped, vec_extract_wrapped, Wrap};
|
6
6
|
use crate::prelude::ObjectValue;
|
7
|
-
use crate::series::
|
7
|
+
use crate::series::to_series;
|
8
8
|
use crate::{RbPolarsErr, RbResult, RbSeries, RbTypeError, RbValueError};
|
9
9
|
|
10
10
|
impl RbSeries {
|
11
11
|
pub fn new_opt_bool(name: String, obj: RArray, strict: bool) -> RbResult<RbSeries> {
|
12
12
|
let len = obj.len();
|
13
|
-
let mut builder = BooleanChunkedBuilder::new(
|
13
|
+
let mut builder = BooleanChunkedBuilder::new(name.into(), len);
|
14
14
|
|
15
15
|
unsafe {
|
16
16
|
for item in obj.as_slice().iter() {
|
@@ -43,7 +43,7 @@ where
|
|
43
43
|
T::Native: magnus::TryConvert,
|
44
44
|
{
|
45
45
|
let len = values.len();
|
46
|
-
let mut builder = PrimitiveChunkedBuilder::<T>::new(name, len);
|
46
|
+
let mut builder = PrimitiveChunkedBuilder::<T>::new(name.into(), len);
|
47
47
|
|
48
48
|
for res in values.into_iter() {
|
49
49
|
let value = res;
|
@@ -96,7 +96,7 @@ impl RbSeries {
|
|
96
96
|
// from anyvalues is fallible
|
97
97
|
let result = any_values_result.and_then(|avs| {
|
98
98
|
let avs = slice_extract_wrapped(&avs);
|
99
|
-
let s = Series::from_any_values(
|
99
|
+
let s = Series::from_any_values(name.clone().into(), avs, strict).map_err(|e| {
|
100
100
|
RbTypeError::new_err(format!(
|
101
101
|
"{e}\n\nHint: Try setting `strict: false` to allow passing data with mixed types."
|
102
102
|
))
|
@@ -122,44 +122,71 @@ impl RbSeries {
|
|
122
122
|
.into_iter()
|
123
123
|
.map(|v| rb_object_to_any_value(v, strict))
|
124
124
|
.collect::<RbResult<Vec<AnyValue>>>()?;
|
125
|
-
let s =
|
126
|
-
.
|
127
|
-
|
125
|
+
let s =
|
126
|
+
Series::from_any_values_and_dtype(name.into(), any_values.as_slice(), &dtype.0, strict)
|
127
|
+
.map_err(|e| {
|
128
|
+
RbTypeError::new_err(format!(
|
128
129
|
"{e}\n\nHint: Try setting `strict: false` to allow passing data with mixed types."
|
129
130
|
))
|
130
|
-
|
131
|
+
})?;
|
131
132
|
Ok(s.into())
|
132
133
|
}
|
133
134
|
|
134
|
-
pub fn new_str(name: String,
|
135
|
-
let
|
136
|
-
|
137
|
-
|
138
|
-
|
135
|
+
pub fn new_str(name: String, values: RArray, _strict: bool) -> RbResult<Self> {
|
136
|
+
let len = values.len();
|
137
|
+
let mut builder = StringChunkedBuilder::new(name.into(), len);
|
138
|
+
|
139
|
+
for res in values.into_iter() {
|
140
|
+
let value = res;
|
141
|
+
if value.is_nil() {
|
142
|
+
builder.append_null()
|
143
|
+
} else {
|
144
|
+
let v = String::try_convert(value)?;
|
145
|
+
builder.append_value(v)
|
146
|
+
}
|
147
|
+
}
|
139
148
|
|
140
|
-
|
141
|
-
let
|
142
|
-
s.
|
143
|
-
RbSeries::new(s)
|
149
|
+
let ca = builder.finish();
|
150
|
+
let s = ca.into_series();
|
151
|
+
Ok(s.into())
|
144
152
|
}
|
145
153
|
|
146
|
-
pub fn
|
147
|
-
let
|
154
|
+
pub fn new_binary(name: String, values: RArray, _strict: bool) -> RbResult<Self> {
|
155
|
+
let len = values.len();
|
156
|
+
let mut builder = BinaryChunkedBuilder::new(name.into(), len);
|
157
|
+
|
158
|
+
for res in values.into_iter() {
|
159
|
+
let value = res;
|
160
|
+
if value.is_nil() {
|
161
|
+
builder.append_null()
|
162
|
+
} else {
|
163
|
+
let v = RString::try_convert(value)?;
|
164
|
+
builder.append_value(unsafe { v.as_slice() })
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
let ca = builder.finish();
|
169
|
+
let s = ca.into_series();
|
148
170
|
Ok(s.into())
|
149
171
|
}
|
150
172
|
|
173
|
+
pub fn new_null(name: String, values: RArray, _strict: bool) -> RbResult<Self> {
|
174
|
+
let len = values.len();
|
175
|
+
Ok(Series::new_null(name.into(), len).into())
|
176
|
+
}
|
177
|
+
|
151
178
|
pub fn new_object(name: String, val: RArray, _strict: bool) -> RbResult<Self> {
|
152
179
|
let val = val
|
153
180
|
.into_iter()
|
154
181
|
.map(ObjectValue::from)
|
155
182
|
.collect::<Vec<ObjectValue>>();
|
156
|
-
let s = ObjectChunked::<ObjectValue>::new_from_vec(
|
183
|
+
let s = ObjectChunked::<ObjectValue>::new_from_vec(name.into(), val).into_series();
|
157
184
|
Ok(s.into())
|
158
185
|
}
|
159
186
|
|
160
187
|
pub fn new_series_list(name: String, val: RArray, _strict: bool) -> RbResult<Self> {
|
161
|
-
let series_vec =
|
162
|
-
Ok(Series::new(
|
188
|
+
let series_vec = to_series(val)?;
|
189
|
+
Ok(Series::new(name.into(), &series_vec).into())
|
163
190
|
}
|
164
191
|
|
165
192
|
pub fn new_array(
|
@@ -171,7 +198,7 @@ impl RbSeries {
|
|
171
198
|
) -> RbResult<Self> {
|
172
199
|
let val = vec_wrap_any_value(val)?;
|
173
200
|
let val = vec_extract_wrapped(val);
|
174
|
-
let out = Series::new(
|
201
|
+
let out = Series::new(name.into(), &val);
|
175
202
|
match out.dtype() {
|
176
203
|
DataType::List(list_inner) => {
|
177
204
|
let out = out
|
@@ -199,7 +226,7 @@ impl RbSeries {
|
|
199
226
|
dtype: Wrap<DataType>,
|
200
227
|
) -> RbResult<Self> {
|
201
228
|
let av = val.0;
|
202
|
-
Ok(Series::new(
|
229
|
+
Ok(Series::new(name.into(), &[av])
|
203
230
|
.cast(&dtype.0)
|
204
231
|
.map_err(RbPolarsErr::from)?
|
205
232
|
.new_from_index(0, n)
|
@@ -31,7 +31,7 @@ impl RbSeries {
|
|
31
31
|
for i in 0..series.len() {
|
32
32
|
let obj: Option<&ObjectValue> = series.get_object(i).map(|any| any.into());
|
33
33
|
match obj {
|
34
|
-
Some(val) => v.push(val.
|
34
|
+
Some(val) => v.push(val.to_value()).unwrap(),
|
35
35
|
None => v.push(qnil()).unwrap(),
|
36
36
|
};
|
37
37
|
}
|