polars-df 0.2.5 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/Cargo.lock +290 -137
  4. data/Cargo.toml +1 -1
  5. data/README.md +40 -2
  6. data/ext/polars/Cargo.toml +5 -4
  7. data/ext/polars/src/apply/dataframe.rs +6 -6
  8. data/ext/polars/src/apply/series.rs +10 -10
  9. data/ext/polars/src/batched_csv.rs +6 -4
  10. data/ext/polars/src/conversion.rs +56 -17
  11. data/ext/polars/src/dataframe.rs +65 -43
  12. data/ext/polars/src/error.rs +16 -8
  13. data/ext/polars/src/file.rs +5 -4
  14. data/ext/polars/src/lazy/apply.rs +1 -1
  15. data/ext/polars/src/lazy/dataframe.rs +12 -6
  16. data/ext/polars/src/lazy/dsl.rs +99 -45
  17. data/ext/polars/src/lazy/meta.rs +10 -9
  18. data/ext/polars/src/lib.rs +33 -29
  19. data/ext/polars/src/numo.rs +57 -0
  20. data/ext/polars/src/object.rs +2 -1
  21. data/ext/polars/src/series.rs +67 -53
  22. data/lib/polars/cat_expr.rb +0 -4
  23. data/lib/polars/cat_name_space.rb +0 -4
  24. data/lib/polars/convert.rb +0 -7
  25. data/lib/polars/data_frame.rb +165 -209
  26. data/lib/polars/data_types.rb +4 -0
  27. data/lib/polars/date_time_expr.rb +19 -151
  28. data/lib/polars/date_time_name_space.rb +17 -17
  29. data/lib/polars/expr.rb +68 -315
  30. data/lib/polars/group_by.rb +79 -51
  31. data/lib/polars/io.rb +1 -1
  32. data/lib/polars/lazy_frame.rb +1 -103
  33. data/lib/polars/lazy_functions.rb +0 -26
  34. data/lib/polars/lazy_group_by.rb +0 -8
  35. data/lib/polars/list_expr.rb +5 -27
  36. data/lib/polars/list_name_space.rb +5 -8
  37. data/lib/polars/plot.rb +109 -0
  38. data/lib/polars/series.rb +61 -19
  39. data/lib/polars/string_expr.rb +20 -76
  40. data/lib/polars/string_name_space.rb +5 -15
  41. data/lib/polars/struct_expr.rb +0 -2
  42. data/lib/polars/version.rb +1 -1
  43. data/lib/polars.rb +1 -0
  44. metadata +5 -3
@@ -6,6 +6,7 @@ mod error;
6
6
  mod file;
7
7
  mod lazy;
8
8
  mod list_construction;
9
+ mod numo;
9
10
  mod object;
10
11
  mod prelude;
11
12
  pub(crate) mod rb_modules;
@@ -21,7 +22,7 @@ use file::get_file_like;
21
22
  use lazy::dataframe::{RbLazyFrame, RbLazyGroupBy};
22
23
  use lazy::dsl::{RbExpr, RbWhen, RbWhenThen};
23
24
  use lazy::utils::rb_exprs_to_exprs;
24
- use magnus::{define_module, function, method, prelude::*, Error, RArray, RHash, Value};
25
+ use magnus::{define_module, function, method, prelude::*, Error, IntoValue, RArray, RHash, Value};
25
26
  use polars::datatypes::{DataType, TimeUnit, IDX_DTYPE};
26
27
  use polars::error::PolarsResult;
27
28
  use polars::frame::DataFrame;
@@ -87,6 +88,7 @@ fn init() -> RbResult<()> {
87
88
  class.define_method("write_ipc", method!(RbDataFrame::write_ipc, 2))?;
88
89
  class.define_method("row_tuple", method!(RbDataFrame::row_tuple, 1))?;
89
90
  class.define_method("row_tuples", method!(RbDataFrame::row_tuples, 0))?;
91
+ class.define_method("to_numo", method!(RbDataFrame::to_numo, 0))?;
90
92
  class.define_method("write_parquet", method!(RbDataFrame::write_parquet, 5))?;
91
93
  class.define_method("add", method!(RbDataFrame::add, 1))?;
92
94
  class.define_method("sub", method!(RbDataFrame::sub, 1))?;
@@ -146,7 +148,7 @@ fn init() -> RbResult<()> {
146
148
  class.define_method("with_row_count", method!(RbDataFrame::with_row_count, 2))?;
147
149
  class.define_method("_clone", method!(RbDataFrame::clone, 0))?;
148
150
  class.define_method("melt", method!(RbDataFrame::melt, 4))?;
149
- class.define_method("pivot_expr", method!(RbDataFrame::pivot_expr, 6))?;
151
+ class.define_method("pivot_expr", method!(RbDataFrame::pivot_expr, 7))?;
150
152
  class.define_method("partition_by", method!(RbDataFrame::partition_by, 2))?;
151
153
  class.define_method("shift", method!(RbDataFrame::shift, 1))?;
152
154
  class.define_method("unique", method!(RbDataFrame::unique, 3))?;
@@ -163,7 +165,7 @@ fn init() -> RbResult<()> {
163
165
  class.define_method("hmin", method!(RbDataFrame::hmin, 0))?;
164
166
  class.define_method("hsum", method!(RbDataFrame::hsum, 1))?;
165
167
  class.define_method("quantile", method!(RbDataFrame::quantile, 2))?;
166
- class.define_method("to_dummies", method!(RbDataFrame::to_dummies, 1))?;
168
+ class.define_method("to_dummies", method!(RbDataFrame::to_dummies, 2))?;
167
169
  class.define_method("null_count", method!(RbDataFrame::null_count, 0))?;
168
170
  class.define_method("apply", method!(RbDataFrame::apply, 3))?;
169
171
  class.define_method("shrink_to_fit", method!(RbDataFrame::shrink_to_fit, 0))?;
@@ -221,7 +223,7 @@ fn init() -> RbResult<()> {
221
223
  class.define_method("top_k", method!(RbExpr::top_k, 2))?;
222
224
  class.define_method("arg_max", method!(RbExpr::arg_max, 0))?;
223
225
  class.define_method("arg_min", method!(RbExpr::arg_min, 0))?;
224
- class.define_method("search_sorted", method!(RbExpr::search_sorted, 1))?;
226
+ class.define_method("search_sorted", method!(RbExpr::search_sorted, 2))?;
225
227
  class.define_method("take", method!(RbExpr::take, 1))?;
226
228
  class.define_method("sort_by", method!(RbExpr::sort_by, 2))?;
227
229
  class.define_method("backward_fill", method!(RbExpr::backward_fill, 1))?;
@@ -284,7 +286,7 @@ fn init() -> RbResult<()> {
284
286
  class.define_method("product", method!(RbExpr::product, 0))?;
285
287
  class.define_method("shrink_dtype", method!(RbExpr::shrink_dtype, 0))?;
286
288
  class.define_method("str_parse_date", method!(RbExpr::str_parse_date, 4))?;
287
- class.define_method("str_parse_datetime", method!(RbExpr::str_parse_datetime, 5))?;
289
+ class.define_method("str_parse_datetime", method!(RbExpr::str_parse_datetime, 6))?;
288
290
  class.define_method("str_parse_time", method!(RbExpr::str_parse_time, 4))?;
289
291
  class.define_method("str_strip", method!(RbExpr::str_strip, 1))?;
290
292
  class.define_method("str_rstrip", method!(RbExpr::str_rstrip, 1))?;
@@ -299,7 +301,7 @@ fn init() -> RbResult<()> {
299
301
  class.define_method("str_zfill", method!(RbExpr::str_zfill, 1))?;
300
302
  class.define_method("str_ljust", method!(RbExpr::str_ljust, 2))?;
301
303
  class.define_method("str_rjust", method!(RbExpr::str_rjust, 2))?;
302
- class.define_method("str_contains", method!(RbExpr::str_contains, 2))?;
304
+ class.define_method("str_contains", method!(RbExpr::str_contains, 3))?;
303
305
  class.define_method("str_ends_with", method!(RbExpr::str_ends_with, 1))?;
304
306
  class.define_method("str_starts_with", method!(RbExpr::str_starts_with, 1))?;
305
307
  class.define_method("str_hex_encode", method!(RbExpr::str_hex_encode, 0))?;
@@ -361,9 +363,15 @@ fn init() -> RbResult<()> {
361
363
  class.define_method("dt_offset_by", method!(RbExpr::dt_offset_by, 1))?;
362
364
  class.define_method("dt_epoch_seconds", method!(RbExpr::dt_epoch_seconds, 0))?;
363
365
  class.define_method("dt_with_time_unit", method!(RbExpr::dt_with_time_unit, 1))?;
364
- class.define_method("dt_with_time_zone", method!(RbExpr::dt_with_time_zone, 1))?;
366
+ class.define_method(
367
+ "dt_convert_time_zone",
368
+ method!(RbExpr::dt_convert_time_zone, 1),
369
+ )?;
365
370
  class.define_method("dt_cast_time_unit", method!(RbExpr::dt_cast_time_unit, 1))?;
366
- class.define_method("dt_cast_time_zone", method!(RbExpr::dt_cast_time_zone, 1))?;
371
+ class.define_method(
372
+ "dt_replace_time_zone",
373
+ method!(RbExpr::dt_replace_time_zone, 1),
374
+ )?;
367
375
  class.define_method("dt_tz_localize", method!(RbExpr::dt_tz_localize, 1))?;
368
376
  class.define_method("dt_truncate", method!(RbExpr::dt_truncate, 2))?;
369
377
  class.define_method("dt_round", method!(RbExpr::dt_round, 2))?;
@@ -418,9 +426,9 @@ fn init() -> RbResult<()> {
418
426
  class.define_method("shuffle", method!(RbExpr::shuffle, 1))?;
419
427
  class.define_method("sample_n", method!(RbExpr::sample_n, 4))?;
420
428
  class.define_method("sample_frac", method!(RbExpr::sample_frac, 4))?;
421
- class.define_method("ewm_mean", method!(RbExpr::ewm_mean, 3))?;
422
- class.define_method("ewm_std", method!(RbExpr::ewm_std, 4))?;
423
- class.define_method("ewm_var", method!(RbExpr::ewm_var, 4))?;
429
+ class.define_method("ewm_mean", method!(RbExpr::ewm_mean, 4))?;
430
+ class.define_method("ewm_std", method!(RbExpr::ewm_std, 5))?;
431
+ class.define_method("ewm_var", method!(RbExpr::ewm_var, 5))?;
424
432
  class.define_method("extend_constant", method!(RbExpr::extend_constant, 2))?;
425
433
  class.define_method("any", method!(RbExpr::any, 0))?;
426
434
  class.define_method("all", method!(RbExpr::all, 0))?;
@@ -613,7 +621,7 @@ fn init() -> RbResult<()> {
613
621
  class.define_method("_clone", method!(RbSeries::clone, 0))?;
614
622
  class.define_method("apply_lambda", method!(RbSeries::apply_lambda, 3))?;
615
623
  class.define_method("zip_with", method!(RbSeries::zip_with, 2))?;
616
- class.define_method("to_dummies", method!(RbSeries::to_dummies, 0))?;
624
+ class.define_method("to_dummies", method!(RbSeries::to_dummies, 1))?;
617
625
  class.define_method("peak_max", method!(RbSeries::peak_max, 0))?;
618
626
  class.define_method("peak_min", method!(RbSeries::peak_min, 0))?;
619
627
  class.define_method("n_unique", method!(RbSeries::n_unique, 0))?;
@@ -777,6 +785,9 @@ fn init() -> RbResult<()> {
777
785
  class.define_method("lt_eq_f64", method!(RbSeries::lt_eq_f64, 1))?;
778
786
  // class.define_method("lt_eq_str", method!(RbSeries::lt_eq_str, 1))?;
779
787
 
788
+ // npy
789
+ class.define_method("to_numo", method!(RbSeries::to_numo, 0))?;
790
+
780
791
  let class = module.define_class("RbWhen", Default::default())?;
781
792
  class.define_method("_then", method!(RbWhen::then, 1))?;
782
793
 
@@ -922,23 +933,16 @@ fn parquet_schema(rb_f: Value) -> RbResult<Value> {
922
933
  Ok(dict.into())
923
934
  }
924
935
 
925
- fn collect_all(lfs: RArray) -> RbResult<Vec<RbDataFrame>> {
926
- use polars_core::utils::rayon::prelude::*;
927
-
936
+ fn collect_all(lfs: RArray) -> RbResult<RArray> {
928
937
  let lfs = lfs
929
938
  .each()
930
939
  .map(|v| v?.try_convert::<&RbLazyFrame>())
931
940
  .collect::<RbResult<Vec<&RbLazyFrame>>>()?;
932
941
 
933
- polars_core::POOL.install(|| {
934
- lfs.par_iter()
935
- .map(|lf| {
936
- let df = lf.ldf.clone().collect()?;
937
- Ok(RbDataFrame::new(df))
938
- })
939
- .collect::<polars_core::error::PolarsResult<Vec<_>>>()
940
- .map_err(RbPolarsErr::from)
941
- })
942
+ Ok(RArray::from_iter(lfs.iter().map(|lf| {
943
+ let df = lf.ldf.clone().collect().unwrap();
944
+ RbDataFrame::new(df)
945
+ })))
942
946
  }
943
947
 
944
948
  fn rb_date_range(
@@ -949,8 +953,8 @@ fn rb_date_range(
949
953
  name: String,
950
954
  tu: Wrap<TimeUnit>,
951
955
  tz: Option<TimeZone>,
952
- ) -> RbSeries {
953
- polars::time::date_range_impl(
956
+ ) -> RbResult<RbSeries> {
957
+ let date_range = polars::time::date_range_impl(
954
958
  &name,
955
959
  start,
956
960
  stop,
@@ -959,8 +963,8 @@ fn rb_date_range(
959
963
  tu.0,
960
964
  tz.as_ref(),
961
965
  )
962
- .into_series()
963
- .into()
966
+ .map_err(RbPolarsErr::from)?;
967
+ Ok(date_range.into_series().into())
964
968
  }
965
969
 
966
970
  fn coalesce_exprs(exprs: RArray) -> RbResult<RbExpr> {
@@ -983,5 +987,5 @@ fn arg_where(condition: &RbExpr) -> RbExpr {
983
987
  }
984
988
 
985
989
  fn get_idx_type() -> Value {
986
- Wrap(IDX_DTYPE).into()
990
+ Wrap(IDX_DTYPE).into_value()
987
991
  }
@@ -0,0 +1,57 @@
1
+ use magnus::{class, Module, RArray, RClass, RModule, Value};
2
+ use polars_core::prelude::*;
3
+
4
+ use crate::{raise_err, RbPolarsErr, RbResult, RbSeries};
5
+
6
+ impl RbSeries {
7
+ /// For numeric types, this should only be called for Series with null types.
8
+ /// This will cast to floats so that `nil = NAN`
9
+ pub fn to_numo(&self) -> RbResult<Value> {
10
+ let s = &self.series.borrow();
11
+ match s.dtype() {
12
+ DataType::Utf8 => {
13
+ let ca = s.utf8().unwrap();
14
+
15
+ // TODO make more efficient
16
+ let np_arr = RArray::from_iter(ca.into_iter());
17
+ class::object()
18
+ .const_get::<_, RModule>("Numo")?
19
+ .const_get::<_, RClass>("RObject")?
20
+ .funcall("cast", (np_arr,))
21
+ }
22
+ dt if dt.is_numeric() => {
23
+ if s.bit_repr_is_large() {
24
+ let s = s.cast(&DataType::Float64).unwrap();
25
+ let ca = s.f64().unwrap();
26
+ // TODO make more efficient
27
+ let np_arr = RArray::from_iter(ca.into_iter().map(|opt_v| match opt_v {
28
+ Some(v) => v,
29
+ None => f64::NAN,
30
+ }));
31
+ class::object()
32
+ .const_get::<_, RModule>("Numo")?
33
+ .const_get::<_, RClass>("DFloat")?
34
+ .funcall("cast", (np_arr,))
35
+ } else {
36
+ let s = s.cast(&DataType::Float32).unwrap();
37
+ let ca = s.f32().unwrap();
38
+ // TODO make more efficient
39
+ let np_arr = RArray::from_iter(ca.into_iter().map(|opt_v| match opt_v {
40
+ Some(v) => v,
41
+ None => f32::NAN,
42
+ }));
43
+ class::object()
44
+ .const_get::<_, RModule>("Numo")?
45
+ .const_get::<_, RClass>("SFloat")?
46
+ .funcall("cast", (np_arr,))
47
+ }
48
+ }
49
+ dt => {
50
+ raise_err!(
51
+ format!("'to_numo' not supported for dtype: {dt:?}"),
52
+ ComputeError
53
+ );
54
+ }
55
+ }
56
+ }
57
+ }
@@ -1,6 +1,7 @@
1
1
  use std::any::Any;
2
2
  use std::sync::Arc;
3
3
 
4
+ use magnus::IntoValue;
4
5
  use polars_core::chunked_array::object::builder::ObjectChunkedBuilder;
5
6
  use polars_core::chunked_array::object::registry;
6
7
  use polars_core::chunked_array::object::registry::AnonymousObjectBuilder;
@@ -20,7 +21,7 @@ pub(crate) fn register_object_builder() {
20
21
 
21
22
  let object_converter = Arc::new(|av: AnyValue| {
22
23
  let object = ObjectValue {
23
- inner: Wrap(av).into(),
24
+ inner: Wrap(av).into_value(),
24
25
  };
25
26
  Box::new(object) as Box<dyn Any>
26
27
  });
@@ -1,5 +1,4 @@
1
- use magnus::exception::arg_error;
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().is_sorted(), IsSorted::Ascending)
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().is_sorted(), IsSorted::Descending)
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)?).into())
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()).into()
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()).into())
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.set_sorted(IsSorted::Descending);
232
+ out.set_sorted_flag(IsSorted::Descending);
234
233
  } else {
235
- out.set_sorted(IsSorted::Ascending)
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
- .into())
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
- .into())
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
- .into())
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::runtime_error("Expected a boolean mask".to_string()))
318
+ Err(Error::new(
319
+ exception::runtime_error(),
320
+ "Expected a boolean mask".to_string(),
321
+ ))
320
322
  }
321
323
  }
322
324
 
@@ -487,40 +489,52 @@ impl RbSeries {
487
489
  }
488
490
 
489
491
  pub fn to_a(&self) -> RArray {
490
- let series = self.series.borrow();
491
- if let Ok(s) = series.f32() {
492
- s.into_iter().collect()
493
- } else if let Ok(s) = series.f64() {
494
- s.into_iter().collect()
495
- } else if let Ok(s) = series.i8() {
496
- s.into_iter().collect()
497
- } else if let Ok(s) = series.i16() {
498
- s.into_iter().collect()
499
- } else if let Ok(s) = series.i32() {
500
- s.into_iter().collect()
501
- } else if let Ok(s) = series.i64() {
502
- s.into_iter().collect()
503
- } else if let Ok(s) = series.u8() {
504
- s.into_iter().collect()
505
- } else if let Ok(s) = series.u16() {
506
- s.into_iter().collect()
507
- } else if let Ok(s) = series.u32() {
508
- s.into_iter().collect()
509
- } else if let Ok(s) = series.u64() {
510
- s.into_iter().collect()
511
- } else if let Ok(s) = series.bool() {
512
- s.into_iter().collect()
513
- } else if let Ok(s) = series.utf8() {
514
- s.into_iter().collect()
515
- } else if let Ok(_s) = series.date() {
516
- let a = RArray::with_capacity(series.len());
517
- for v in series.iter() {
518
- a.push::<Value>(Wrap(v).into()).unwrap();
519
- }
520
- a
521
- } else {
522
- unimplemented!();
492
+ let series = &self.series.borrow();
493
+
494
+ fn to_list_recursive(series: &Series) -> RArray {
495
+ let rblist = match series.dtype() {
496
+ DataType::Boolean => RArray::from_iter(series.bool().unwrap()),
497
+ DataType::UInt8 => RArray::from_iter(series.u8().unwrap()),
498
+ DataType::UInt16 => RArray::from_iter(series.u16().unwrap()),
499
+ DataType::UInt32 => RArray::from_iter(series.u32().unwrap()),
500
+ DataType::UInt64 => RArray::from_iter(series.u64().unwrap()),
501
+ DataType::Int8 => RArray::from_iter(series.i8().unwrap()),
502
+ DataType::Int16 => RArray::from_iter(series.i16().unwrap()),
503
+ DataType::Int32 => RArray::from_iter(series.i32().unwrap()),
504
+ DataType::Int64 => RArray::from_iter(series.i64().unwrap()),
505
+ DataType::Float32 => RArray::from_iter(series.f32().unwrap()),
506
+ DataType::Float64 => RArray::from_iter(series.f64().unwrap()),
507
+ DataType::Decimal128(_) => todo!(),
508
+ DataType::Categorical(_) => {
509
+ RArray::from_iter(series.categorical().unwrap().iter_str())
510
+ }
511
+ DataType::Date => {
512
+ let a = RArray::with_capacity(series.len());
513
+ for v in series.iter() {
514
+ a.push::<Value>(Wrap(v).into_value()).unwrap();
515
+ }
516
+ return a;
517
+ }
518
+ DataType::Datetime(_, _) => {
519
+ let a = RArray::with_capacity(series.len());
520
+ for v in series.iter() {
521
+ a.push::<Value>(Wrap(v).into_value()).unwrap();
522
+ }
523
+ return a;
524
+ }
525
+ DataType::Utf8 => {
526
+ let ca = series.utf8().unwrap();
527
+ return RArray::from_iter(ca);
528
+ }
529
+ DataType::Null | DataType::Unknown => {
530
+ panic!("to_a not implemented for null/unknown")
531
+ }
532
+ _ => todo!(),
533
+ };
534
+ rblist
523
535
  }
536
+
537
+ to_list_recursive(series)
524
538
  }
525
539
 
526
540
  pub fn median(&self) -> Option<f64> {
@@ -546,7 +560,7 @@ impl RbSeries {
546
560
  .get(0)
547
561
  .unwrap_or(AnyValue::Null),
548
562
  )
549
- .into())
563
+ .into_value())
550
564
  }
551
565
 
552
566
  pub fn clone(&self) -> Self {
@@ -756,11 +770,11 @@ impl RbSeries {
756
770
  Ok(RbSeries::new(s))
757
771
  }
758
772
 
759
- pub fn to_dummies(&self) -> RbResult<RbDataFrame> {
773
+ pub fn to_dummies(&self, sep: Option<String>) -> RbResult<RbDataFrame> {
760
774
  let df = self
761
775
  .series
762
776
  .borrow()
763
- .to_dummies()
777
+ .to_dummies(sep.as_deref())
764
778
  .map_err(RbPolarsErr::from)?;
765
779
  Ok(df.into())
766
780
  }
@@ -1095,8 +1109,8 @@ pub fn to_series_collection(rs: RArray) -> RbResult<Vec<Series>> {
1095
1109
  Ok(series)
1096
1110
  }
1097
1111
 
1098
- pub fn to_rbseries_collection(s: Vec<Series>) -> Vec<RbSeries> {
1099
- s.into_iter().map(RbSeries::new).collect()
1112
+ pub fn to_rbseries_collection(s: Vec<Series>) -> RArray {
1113
+ RArray::from_iter(s.into_iter().map(RbSeries::new))
1100
1114
  }
1101
1115
 
1102
1116
  impl RbSeries {
@@ -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)
@@ -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)