polars-df 0.11.0 → 0.12.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.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/Cargo.lock +360 -361
  4. data/ext/polars/Cargo.toml +10 -7
  5. data/ext/polars/src/batched_csv.rs +1 -1
  6. data/ext/polars/src/conversion/any_value.rs +261 -0
  7. data/ext/polars/src/conversion/chunked_array.rs +4 -4
  8. data/ext/polars/src/conversion/mod.rs +51 -10
  9. data/ext/polars/src/dataframe/construction.rs +6 -8
  10. data/ext/polars/src/dataframe/general.rs +19 -29
  11. data/ext/polars/src/dataframe/io.rs +43 -33
  12. data/ext/polars/src/error.rs +26 -4
  13. data/ext/polars/src/expr/categorical.rs +0 -10
  14. data/ext/polars/src/expr/datetime.rs +4 -12
  15. data/ext/polars/src/expr/general.rs +123 -110
  16. data/ext/polars/src/expr/mod.rs +2 -2
  17. data/ext/polars/src/expr/rolling.rs +17 -9
  18. data/ext/polars/src/expr/string.rs +2 -6
  19. data/ext/polars/src/functions/eager.rs +10 -10
  20. data/ext/polars/src/functions/lazy.rs +21 -21
  21. data/ext/polars/src/functions/range.rs +6 -12
  22. data/ext/polars/src/interop/numo/to_numo_series.rs +2 -1
  23. data/ext/polars/src/lazyframe/mod.rs +81 -98
  24. data/ext/polars/src/lib.rs +55 -45
  25. data/ext/polars/src/map/dataframe.rs +2 -2
  26. data/ext/polars/src/rb_modules.rs +25 -1
  27. data/ext/polars/src/series/aggregation.rs +4 -2
  28. data/ext/polars/src/series/arithmetic.rs +21 -11
  29. data/ext/polars/src/series/construction.rs +56 -38
  30. data/ext/polars/src/series/export.rs +1 -1
  31. data/ext/polars/src/series/mod.rs +31 -10
  32. data/ext/polars/src/sql.rs +3 -1
  33. data/lib/polars/array_expr.rb +4 -4
  34. data/lib/polars/batched_csv_reader.rb +2 -2
  35. data/lib/polars/cat_expr.rb +0 -36
  36. data/lib/polars/cat_name_space.rb +0 -37
  37. data/lib/polars/data_frame.rb +93 -101
  38. data/lib/polars/data_types.rb +1 -1
  39. data/lib/polars/date_time_expr.rb +525 -573
  40. data/lib/polars/date_time_name_space.rb +263 -464
  41. data/lib/polars/dynamic_group_by.rb +3 -3
  42. data/lib/polars/exceptions.rb +3 -0
  43. data/lib/polars/expr.rb +367 -330
  44. data/lib/polars/expr_dispatch.rb +1 -1
  45. data/lib/polars/functions/aggregation/horizontal.rb +8 -8
  46. data/lib/polars/functions/as_datatype.rb +63 -40
  47. data/lib/polars/functions/lazy.rb +63 -14
  48. data/lib/polars/functions/lit.rb +1 -1
  49. data/lib/polars/functions/range/date_range.rb +18 -77
  50. data/lib/polars/functions/range/datetime_range.rb +4 -4
  51. data/lib/polars/functions/range/int_range.rb +2 -2
  52. data/lib/polars/functions/range/time_range.rb +4 -4
  53. data/lib/polars/functions/repeat.rb +1 -1
  54. data/lib/polars/functions/whenthen.rb +1 -1
  55. data/lib/polars/io/csv.rb +8 -8
  56. data/lib/polars/io/ipc.rb +3 -3
  57. data/lib/polars/io/json.rb +13 -2
  58. data/lib/polars/io/ndjson.rb +15 -4
  59. data/lib/polars/io/parquet.rb +5 -4
  60. data/lib/polars/lazy_frame.rb +120 -106
  61. data/lib/polars/lazy_group_by.rb +1 -1
  62. data/lib/polars/list_expr.rb +11 -11
  63. data/lib/polars/list_name_space.rb +5 -1
  64. data/lib/polars/rolling_group_by.rb +5 -7
  65. data/lib/polars/series.rb +105 -189
  66. data/lib/polars/string_expr.rb +42 -67
  67. data/lib/polars/string_name_space.rb +5 -4
  68. data/lib/polars/testing.rb +2 -2
  69. data/lib/polars/utils/constants.rb +9 -0
  70. data/lib/polars/utils/convert.rb +97 -0
  71. data/lib/polars/utils/parse.rb +89 -0
  72. data/lib/polars/utils/various.rb +76 -0
  73. data/lib/polars/utils/wrap.rb +19 -0
  74. data/lib/polars/utils.rb +4 -330
  75. data/lib/polars/version.rb +1 -1
  76. data/lib/polars/whenthen.rb +6 -6
  77. data/lib/polars.rb +11 -0
  78. metadata +9 -4
  79. data/ext/polars/src/conversion/anyvalue.rs +0 -186
@@ -15,19 +15,14 @@ use crate::{RbDataFrame, RbExpr, RbLazyGroupBy, RbPolarsErr, RbResult, RbValueEr
15
15
  #[magnus::wrap(class = "Polars::RbLazyFrame")]
16
16
  #[derive(Clone)]
17
17
  pub struct RbLazyFrame {
18
- pub ldf: LazyFrame,
19
- }
20
-
21
- impl RbLazyFrame {
22
- fn get_schema(&self) -> RbResult<SchemaRef> {
23
- let schema = self.ldf.schema().map_err(RbPolarsErr::from)?;
24
- Ok(schema)
25
- }
18
+ pub ldf: RefCell<LazyFrame>,
26
19
  }
27
20
 
28
21
  impl From<LazyFrame> for RbLazyFrame {
29
22
  fn from(ldf: LazyFrame) -> Self {
30
- RbLazyFrame { ldf }
23
+ RbLazyFrame {
24
+ ldf: RefCell::new(ldf),
25
+ }
31
26
  }
32
27
  }
33
28
 
@@ -69,7 +64,7 @@ impl RbLazyFrame {
69
64
  });
70
65
 
71
66
  let lf = LazyJsonLineReader::new(path)
72
- .with_infer_schema_length(infer_schema_length)
67
+ .with_infer_schema_length(infer_schema_length.and_then(NonZeroUsize::new))
73
68
  .with_batch_size(batch_size)
74
69
  .with_n_rows(n_rows)
75
70
  .low_memory(low_memory)
@@ -163,8 +158,9 @@ impl RbLazyFrame {
163
158
  row_index: Option<(String, IdxSize)>,
164
159
  low_memory: bool,
165
160
  use_statistics: bool,
166
- hive_partitioning: bool,
161
+ hive_partitioning: Option<bool>,
167
162
  hive_schema: Option<Wrap<Schema>>,
163
+ try_parse_hive_dates: bool,
168
164
  glob: bool,
169
165
  ) -> RbResult<Self> {
170
166
  let parallel = parallel.0;
@@ -184,7 +180,9 @@ impl RbLazyFrame {
184
180
  });
185
181
  let hive_options = HiveOptions {
186
182
  enabled: hive_partitioning,
183
+ hive_start_idx: 0,
187
184
  schema: hive_schema,
185
+ try_parse_dates: try_parse_hive_dates,
188
186
  };
189
187
 
190
188
  let args = ScanArgsParquet {
@@ -236,13 +234,14 @@ impl RbLazyFrame {
236
234
 
237
235
  pub fn write_json(&self, rb_f: Value) -> RbResult<()> {
238
236
  let file = BufWriter::new(get_file_like(rb_f, true)?);
239
- serde_json::to_writer(file, &self.ldf.logical_plan)
237
+ serde_json::to_writer(file, &self.ldf.borrow().logical_plan)
240
238
  .map_err(|err| RbValueError::new_err(format!("{:?}", err)))?;
241
239
  Ok(())
242
240
  }
243
241
 
244
242
  pub fn describe_plan(&self) -> RbResult<String> {
245
243
  self.ldf
244
+ .borrow()
246
245
  .describe_plan()
247
246
  .map_err(RbPolarsErr::from)
248
247
  .map_err(Into::into)
@@ -251,6 +250,7 @@ impl RbLazyFrame {
251
250
  pub fn describe_optimized_plan(&self) -> RbResult<String> {
252
251
  let result = self
253
252
  .ldf
253
+ .borrow()
254
254
  .describe_optimized_plan()
255
255
  .map_err(RbPolarsErr::from)?;
256
256
  Ok(result)
@@ -269,7 +269,7 @@ impl RbLazyFrame {
269
269
  allow_streaming: bool,
270
270
  _eager: bool,
271
271
  ) -> RbLazyFrame {
272
- let ldf = self.ldf.clone();
272
+ let ldf = self.ldf.borrow().clone();
273
273
  let mut ldf = ldf
274
274
  .with_type_coercion(type_coercion)
275
275
  .with_predicate_pushdown(predicate_pushdown)
@@ -293,12 +293,12 @@ impl RbLazyFrame {
293
293
  maintain_order: bool,
294
294
  multithreaded: bool,
295
295
  ) -> Self {
296
- let ldf = self.ldf.clone();
296
+ let ldf = self.ldf.borrow().clone();
297
297
  ldf.sort(
298
298
  [&by_column],
299
299
  SortMultipleOptions {
300
300
  descending: vec![descending],
301
- nulls_last,
301
+ nulls_last: vec![nulls_last],
302
302
  multithreaded,
303
303
  maintain_order,
304
304
  },
@@ -310,11 +310,11 @@ impl RbLazyFrame {
310
310
  &self,
311
311
  by: RArray,
312
312
  descending: Vec<bool>,
313
- nulls_last: bool,
313
+ nulls_last: Vec<bool>,
314
314
  maintain_order: bool,
315
315
  multithreaded: bool,
316
316
  ) -> RbResult<Self> {
317
- let ldf = self.ldf.clone();
317
+ let ldf = self.ldf.borrow().clone();
318
318
  let exprs = rb_exprs_to_exprs(by)?;
319
319
  Ok(ldf
320
320
  .sort_by_exprs(
@@ -330,12 +330,12 @@ impl RbLazyFrame {
330
330
  }
331
331
 
332
332
  pub fn cache(&self) -> Self {
333
- let ldf = self.ldf.clone();
333
+ let ldf = self.ldf.borrow().clone();
334
334
  ldf.cache().into()
335
335
  }
336
336
 
337
337
  pub fn collect(&self) -> RbResult<RbDataFrame> {
338
- let ldf = self.ldf.clone();
338
+ let ldf = self.ldf.borrow().clone();
339
339
  let df = ldf.collect().map_err(RbPolarsErr::from)?;
340
340
  Ok(df.into())
341
341
  }
@@ -346,7 +346,7 @@ impl RbLazyFrame {
346
346
  path: PathBuf,
347
347
  compression: String,
348
348
  compression_level: Option<i32>,
349
- statistics: bool,
349
+ statistics: Wrap<StatisticsOptions>,
350
350
  row_group_size: Option<usize>,
351
351
  data_pagesize_limit: Option<usize>,
352
352
  maintain_order: bool,
@@ -355,13 +355,13 @@ impl RbLazyFrame {
355
355
 
356
356
  let options = ParquetWriteOptions {
357
357
  compression,
358
- statistics,
358
+ statistics: statistics.0,
359
359
  row_group_size,
360
360
  data_pagesize_limit,
361
361
  maintain_order,
362
362
  };
363
363
 
364
- let ldf = self.ldf.clone();
364
+ let ldf = self.ldf.borrow().clone();
365
365
  ldf.sink_parquet(path, options).map_err(RbPolarsErr::from)?;
366
366
  Ok(())
367
367
  }
@@ -377,7 +377,7 @@ impl RbLazyFrame {
377
377
  maintain_order,
378
378
  };
379
379
 
380
- let ldf = self.ldf.clone();
380
+ let ldf = self.ldf.borrow().clone();
381
381
  ldf.sink_ipc(path, options).map_err(RbPolarsErr::from)?;
382
382
  Ok(())
383
383
  }
@@ -395,6 +395,7 @@ impl RbLazyFrame {
395
395
  datetime_format: Option<String>,
396
396
  date_format: Option<String>,
397
397
  time_format: Option<String>,
398
+ float_scientific: Option<bool>,
398
399
  float_precision: Option<usize>,
399
400
  null_value: Option<String>,
400
401
  quote_style: Option<Wrap<QuoteStyle>>,
@@ -407,6 +408,7 @@ impl RbLazyFrame {
407
408
  date_format,
408
409
  time_format,
409
410
  datetime_format,
411
+ float_scientific,
410
412
  float_precision,
411
413
  separator,
412
414
  quote_char,
@@ -423,7 +425,7 @@ impl RbLazyFrame {
423
425
  serialize_options,
424
426
  };
425
427
 
426
- let ldf = self.ldf.clone();
428
+ let ldf = self.ldf.borrow().clone();
427
429
  ldf.sink_csv(path, options).map_err(RbPolarsErr::from)?;
428
430
  Ok(())
429
431
  }
@@ -431,36 +433,36 @@ impl RbLazyFrame {
431
433
  pub fn sink_json(&self, path: PathBuf, maintain_order: bool) -> RbResult<()> {
432
434
  let options = JsonWriterOptions { maintain_order };
433
435
 
434
- let ldf = self.ldf.clone();
436
+ let ldf = self.ldf.borrow().clone();
435
437
  ldf.sink_json(path, options).map_err(RbPolarsErr::from)?;
436
438
  Ok(())
437
439
  }
438
440
 
439
441
  pub fn fetch(&self, n_rows: usize) -> RbResult<RbDataFrame> {
440
- let ldf = self.ldf.clone();
442
+ let ldf = self.ldf.borrow().clone();
441
443
  let df = ldf.fetch(n_rows).map_err(RbPolarsErr::from)?;
442
444
  Ok(df.into())
443
445
  }
444
446
 
445
447
  pub fn filter(&self, predicate: &RbExpr) -> Self {
446
- let ldf = self.ldf.clone();
448
+ let ldf = self.ldf.borrow().clone();
447
449
  ldf.filter(predicate.inner.clone()).into()
448
450
  }
449
451
 
450
452
  pub fn select(&self, exprs: RArray) -> RbResult<Self> {
451
- let ldf = self.ldf.clone();
453
+ let ldf = self.ldf.borrow().clone();
452
454
  let exprs = rb_exprs_to_exprs(exprs)?;
453
455
  Ok(ldf.select(exprs).into())
454
456
  }
455
457
 
456
458
  pub fn select_seq(&self, exprs: RArray) -> RbResult<Self> {
457
- let ldf = self.ldf.clone();
459
+ let ldf = self.ldf.borrow().clone();
458
460
  let exprs = rb_exprs_to_exprs(exprs)?;
459
461
  Ok(ldf.select_seq(exprs).into())
460
462
  }
461
463
 
462
464
  pub fn group_by(&self, by: RArray, maintain_order: bool) -> RbResult<RbLazyGroupBy> {
463
- let ldf = self.ldf.clone();
465
+ let ldf = self.ldf.borrow().clone();
464
466
  let by = rb_exprs_to_exprs(by)?;
465
467
  let lazy_gb = if maintain_order {
466
468
  ldf.group_by_stable(by)
@@ -479,10 +481,9 @@ impl RbLazyFrame {
479
481
  offset: String,
480
482
  closed: Wrap<ClosedWindow>,
481
483
  by: RArray,
482
- check_sorted: bool,
483
484
  ) -> RbResult<RbLazyGroupBy> {
484
485
  let closed_window = closed.0;
485
- let ldf = self.ldf.clone();
486
+ let ldf = self.ldf.borrow().clone();
486
487
  let by = rb_exprs_to_exprs(by)?;
487
488
  let lazy_gb = ldf.rolling(
488
489
  index_column.inner.clone(),
@@ -492,7 +493,6 @@ impl RbLazyFrame {
492
493
  period: Duration::parse(&period),
493
494
  offset: Duration::parse(&offset),
494
495
  closed_window,
495
- check_sorted,
496
496
  },
497
497
  );
498
498
 
@@ -513,11 +513,10 @@ impl RbLazyFrame {
513
513
  closed: Wrap<ClosedWindow>,
514
514
  by: RArray,
515
515
  start_by: Wrap<StartBy>,
516
- check_sorted: bool,
517
516
  ) -> RbResult<RbLazyGroupBy> {
518
517
  let closed_window = closed.0;
519
518
  let by = rb_exprs_to_exprs(by)?;
520
- let ldf = self.ldf.clone();
519
+ let ldf = self.ldf.borrow().clone();
521
520
  let lazy_gb = ldf.group_by_dynamic(
522
521
  index_column.inner.clone(),
523
522
  by,
@@ -529,7 +528,6 @@ impl RbLazyFrame {
529
528
  include_boundaries,
530
529
  closed_window,
531
530
  start_by: start_by.0,
532
- check_sorted,
533
531
  ..Default::default()
534
532
  },
535
533
  );
@@ -541,14 +539,14 @@ impl RbLazyFrame {
541
539
 
542
540
  pub fn with_context(&self, contexts: RArray) -> RbResult<Self> {
543
541
  let contexts = contexts
544
- .each()
545
- .map(|v| TryConvert::try_convert(v.unwrap()))
542
+ .into_iter()
543
+ .map(TryConvert::try_convert)
546
544
  .collect::<RbResult<Vec<&RbLazyFrame>>>()?;
547
545
  let contexts = contexts
548
546
  .into_iter()
549
- .map(|ldf| ldf.ldf.clone())
547
+ .map(|ldf| ldf.ldf.borrow().clone())
550
548
  .collect::<Vec<_>>();
551
- Ok(self.ldf.clone().with_context(contexts).into())
549
+ Ok(self.ldf.borrow().clone().with_context(contexts).into())
552
550
  }
553
551
 
554
552
  #[allow(clippy::too_many_arguments)]
@@ -566,8 +564,8 @@ impl RbLazyFrame {
566
564
  tolerance: Option<Wrap<AnyValue<'_>>>,
567
565
  tolerance_str: Option<String>,
568
566
  ) -> RbResult<Self> {
569
- let ldf = self.ldf.clone();
570
- let other = other.ldf.clone();
567
+ let ldf = self.ldf.borrow().clone();
568
+ let other = other.ldf.borrow().clone();
571
569
  let left_on = left_on.inner.clone();
572
570
  let right_on = right_on.inner.clone();
573
571
  Ok(ldf
@@ -601,8 +599,8 @@ impl RbLazyFrame {
601
599
  how: Wrap<JoinType>,
602
600
  suffix: String,
603
601
  ) -> RbResult<Self> {
604
- let ldf = self.ldf.clone();
605
- let other = other.ldf.clone();
602
+ let ldf = self.ldf.borrow().clone();
603
+ let other = other.ldf.borrow().clone();
606
604
  let left_on = rb_exprs_to_exprs(left_on)?;
607
605
  let right_on = rb_exprs_to_exprs(right_on)?;
608
606
 
@@ -621,32 +619,32 @@ impl RbLazyFrame {
621
619
  }
622
620
 
623
621
  pub fn with_column(&self, expr: &RbExpr) -> Self {
624
- let ldf = self.ldf.clone();
622
+ let ldf = self.ldf.borrow().clone();
625
623
  ldf.with_column(expr.inner.clone()).into()
626
624
  }
627
625
 
628
626
  pub fn with_columns(&self, exprs: RArray) -> RbResult<Self> {
629
- let ldf = self.ldf.clone();
627
+ let ldf = self.ldf.borrow().clone();
630
628
  Ok(ldf.with_columns(rb_exprs_to_exprs(exprs)?).into())
631
629
  }
632
630
 
633
631
  pub fn with_columns_seq(&self, exprs: RArray) -> RbResult<Self> {
634
- let ldf = self.ldf.clone();
632
+ let ldf = self.ldf.borrow().clone();
635
633
  Ok(ldf.with_columns_seq(rb_exprs_to_exprs(exprs)?).into())
636
634
  }
637
635
 
638
636
  pub fn rename(&self, existing: Vec<String>, new: Vec<String>) -> Self {
639
- let ldf = self.ldf.clone();
637
+ let ldf = self.ldf.borrow().clone();
640
638
  ldf.rename(existing, new).into()
641
639
  }
642
640
 
643
641
  pub fn reverse(&self) -> Self {
644
- let ldf = self.ldf.clone();
642
+ let ldf = self.ldf.borrow().clone();
645
643
  ldf.reverse().into()
646
644
  }
647
645
 
648
646
  pub fn shift(&self, n: &RbExpr, fill_value: Option<&RbExpr>) -> Self {
649
- let lf = self.ldf.clone();
647
+ let lf = self.ldf.borrow().clone();
650
648
  let out = match fill_value {
651
649
  Some(v) => lf.shift_and_fill(n.inner.clone(), v.inner.clone()),
652
650
  None => lf.shift(n.inner.clone()),
@@ -655,48 +653,48 @@ impl RbLazyFrame {
655
653
  }
656
654
 
657
655
  pub fn fill_nan(&self, fill_value: &RbExpr) -> Self {
658
- let ldf = self.ldf.clone();
656
+ let ldf = self.ldf.borrow().clone();
659
657
  ldf.fill_nan(fill_value.inner.clone()).into()
660
658
  }
661
659
 
662
660
  pub fn min(&self) -> Self {
663
- let ldf = self.ldf.clone();
661
+ let ldf = self.ldf.borrow().clone();
664
662
  let out = ldf.min();
665
663
  out.into()
666
664
  }
667
665
 
668
666
  pub fn max(&self) -> Self {
669
- let ldf = self.ldf.clone();
667
+ let ldf = self.ldf.borrow().clone();
670
668
  let out = ldf.max();
671
669
  out.into()
672
670
  }
673
671
 
674
672
  pub fn sum(&self) -> Self {
675
- let ldf = self.ldf.clone();
673
+ let ldf = self.ldf.borrow().clone();
676
674
  let out = ldf.sum();
677
675
  out.into()
678
676
  }
679
677
 
680
678
  pub fn mean(&self) -> Self {
681
- let ldf = self.ldf.clone();
679
+ let ldf = self.ldf.borrow().clone();
682
680
  let out = ldf.mean();
683
681
  out.into()
684
682
  }
685
683
 
686
684
  pub fn std(&self, ddof: u8) -> Self {
687
- let ldf = self.ldf.clone();
685
+ let ldf = self.ldf.borrow().clone();
688
686
  let out = ldf.std(ddof);
689
687
  out.into()
690
688
  }
691
689
 
692
690
  pub fn var(&self, ddof: u8) -> Self {
693
- let ldf = self.ldf.clone();
691
+ let ldf = self.ldf.borrow().clone();
694
692
  let out = ldf.var(ddof);
695
693
  out.into()
696
694
  }
697
695
 
698
696
  pub fn median(&self) -> Self {
699
- let ldf = self.ldf.clone();
697
+ let ldf = self.ldf.borrow().clone();
700
698
  let out = ldf.median();
701
699
  out.into()
702
700
  }
@@ -706,19 +704,19 @@ impl RbLazyFrame {
706
704
  quantile: &RbExpr,
707
705
  interpolation: Wrap<QuantileInterpolOptions>,
708
706
  ) -> Self {
709
- let ldf = self.ldf.clone();
707
+ let ldf = self.ldf.borrow().clone();
710
708
  let out = ldf.quantile(quantile.inner.clone(), interpolation.0);
711
709
  out.into()
712
710
  }
713
711
 
714
712
  pub fn explode(&self, column: RArray) -> RbResult<Self> {
715
- let ldf = self.ldf.clone();
713
+ let ldf = self.ldf.borrow().clone();
716
714
  let column = rb_exprs_to_exprs(column)?;
717
715
  Ok(ldf.explode(column).into())
718
716
  }
719
717
 
720
718
  pub fn null_count(&self) -> Self {
721
- let ldf = self.ldf.clone();
719
+ let ldf = self.ldf.borrow().clone();
722
720
  ldf.null_count().into()
723
721
  }
724
722
 
@@ -728,7 +726,7 @@ impl RbLazyFrame {
728
726
  subset: Option<Vec<String>>,
729
727
  keep: Wrap<UniqueKeepStrategy>,
730
728
  ) -> RbResult<Self> {
731
- let ldf = self.ldf.clone();
729
+ let ldf = self.ldf.borrow().clone();
732
730
  Ok(match maintain_order {
733
731
  true => ldf.unique_stable(subset, keep.0),
734
732
  false => ldf.unique(subset, keep.0),
@@ -737,75 +735,63 @@ impl RbLazyFrame {
737
735
  }
738
736
 
739
737
  pub fn drop_nulls(&self, subset: Option<Vec<String>>) -> Self {
740
- let ldf = self.ldf.clone();
738
+ let ldf = self.ldf.borrow().clone();
741
739
  ldf.drop_nulls(subset.map(|v| v.into_iter().map(|s| col(&s)).collect()))
742
740
  .into()
743
741
  }
744
742
 
745
743
  pub fn slice(&self, offset: i64, len: Option<IdxSize>) -> Self {
746
- let ldf = self.ldf.clone();
744
+ let ldf = self.ldf.borrow().clone();
747
745
  ldf.slice(offset, len.unwrap_or(IdxSize::MAX)).into()
748
746
  }
749
747
 
750
748
  pub fn tail(&self, n: IdxSize) -> Self {
751
- let ldf = self.ldf.clone();
749
+ let ldf = self.ldf.borrow().clone();
752
750
  ldf.tail(n).into()
753
751
  }
754
752
 
755
- pub fn melt(
753
+ pub fn unpivot(
756
754
  &self,
757
- id_vars: Vec<String>,
758
- value_vars: Vec<String>,
755
+ on: Vec<String>,
756
+ index: Vec<String>,
759
757
  value_name: Option<String>,
760
758
  variable_name: Option<String>,
761
759
  streamable: bool,
762
760
  ) -> Self {
763
- let args = MeltArgs {
764
- id_vars: strings_to_smartstrings(id_vars),
765
- value_vars: strings_to_smartstrings(value_vars),
761
+ let args = UnpivotArgs {
762
+ on: strings_to_smartstrings(on),
763
+ index: strings_to_smartstrings(index),
766
764
  value_name: value_name.map(|s| s.into()),
767
765
  variable_name: variable_name.map(|s| s.into()),
768
766
  streamable,
769
767
  };
770
768
 
771
- let ldf = self.ldf.clone();
772
- ldf.melt(args).into()
769
+ let ldf = self.ldf.borrow().clone();
770
+ ldf.unpivot(args).into()
773
771
  }
774
772
 
775
773
  pub fn with_row_index(&self, name: String, offset: Option<IdxSize>) -> Self {
776
- let ldf = self.ldf.clone();
774
+ let ldf = self.ldf.borrow().clone();
777
775
  ldf.with_row_index(&name, offset).into()
778
776
  }
779
777
 
780
778
  pub fn drop(&self, cols: Vec<String>) -> Self {
781
- let ldf = self.ldf.clone();
779
+ let ldf = self.ldf.borrow().clone();
782
780
  ldf.drop(cols).into()
783
781
  }
784
782
 
785
783
  pub fn cast_all(&self, dtype: Wrap<DataType>, strict: bool) -> Self {
786
- self.ldf.clone().cast_all(dtype.0, strict).into()
784
+ self.ldf.borrow().clone().cast_all(dtype.0, strict).into()
787
785
  }
788
786
 
789
787
  pub fn clone(&self) -> Self {
790
- self.ldf.clone().into()
791
- }
792
-
793
- pub fn columns(&self) -> RbResult<RArray> {
794
- let schema = self.get_schema()?;
795
- let iter = schema.iter_names().map(|s| s.as_str());
796
- Ok(RArray::from_iter(iter))
788
+ self.ldf.borrow().clone().into()
797
789
  }
798
790
 
799
- pub fn dtypes(&self) -> RbResult<RArray> {
800
- let schema = self.get_schema()?;
801
- let iter = schema.iter_dtypes().map(|dt| Wrap(dt.clone()).into_value());
802
- Ok(RArray::from_iter(iter))
803
- }
791
+ pub fn collect_schema(&self) -> RbResult<RHash> {
792
+ let schema = self.ldf.borrow_mut().schema().map_err(RbPolarsErr::from)?;
804
793
 
805
- pub fn schema(&self) -> RbResult<RHash> {
806
- let schema = self.get_schema()?;
807
794
  let schema_dict = RHash::new();
808
-
809
795
  schema.iter_fields().for_each(|fld| {
810
796
  // TODO remove unwrap
811
797
  schema_dict
@@ -819,23 +805,20 @@ impl RbLazyFrame {
819
805
  }
820
806
 
821
807
  pub fn unnest(&self, cols: Vec<String>) -> Self {
822
- self.ldf.clone().unnest(cols).into()
823
- }
824
-
825
- pub fn width(&self) -> RbResult<usize> {
826
- Ok(self.get_schema()?.len())
808
+ self.ldf.borrow().clone().unnest(cols).into()
827
809
  }
828
810
 
829
811
  pub fn count(&self) -> Self {
830
- let ldf = self.ldf.clone();
812
+ let ldf = self.ldf.borrow().clone();
831
813
  ldf.count().into()
832
814
  }
833
815
 
834
816
  pub fn merge_sorted(&self, other: &Self, key: String) -> RbResult<Self> {
835
817
  let out = self
836
818
  .ldf
819
+ .borrow()
837
820
  .clone()
838
- .merge_sorted(other.ldf.clone(), &key)
821
+ .merge_sorted(other.ldf.borrow().clone(), &key)
839
822
  .map_err(RbPolarsErr::from)?;
840
823
  Ok(out.into())
841
824
  }