Skip to content

Commit

Permalink
test(rust): Add a test for AnonymousScan options (projection and slic…
Browse files Browse the repository at this point in the history
…e pushdown) (#17149)
  • Loading branch information
datapythonista committed Jun 24, 2024
1 parent 0b1f5ec commit 42ba1b0
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions crates/polars-lazy/src/tests/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,45 @@ fn scan_anonymous_fn() -> PolarsResult<()> {
Ok(())
}

#[test]
fn scan_anonymous_fn_with_options() -> PolarsResult<()> {
struct MyScan {}

impl AnonymousScan for MyScan {
fn as_any(&self) -> &dyn std::any::Any {
self
}

fn allows_projection_pushdown(&self) -> bool {
true
}

fn scan(&self, scan_opts: AnonymousScanArgs) -> PolarsResult<DataFrame> {
assert_eq!(scan_opts.with_columns.clone().unwrap().len(), 2);
assert_eq!(scan_opts.n_rows, Some(3));
let out = fruits_cars().select(scan_opts.with_columns.unwrap().as_ref())?;
Ok(out.slice(0, scan_opts.n_rows.unwrap()))
}
}

let function = Arc::new(MyScan {});

let args = ScanArgsAnonymous {
schema: Some(Arc::new(fruits_cars().schema())),
..ScanArgsAnonymous::default()
};

let q = LazyFrame::anonymous_scan(function, args)?
.with_column((col("A") * lit(2)).alias("A2"))
.select([col("A2"), col("fruits")])
.limit(3);

let df = q.collect()?;

assert_eq!(df.shape(), (3, 2));
Ok(())
}

#[test]
#[cfg(feature = "dtype-full")]
fn scan_small_dtypes() -> PolarsResult<()> {
Expand Down

0 comments on commit 42ba1b0

Please sign in to comment.