From afaac6ee8d871746813538913ad6c5c1a4efb741 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Sun, 23 Jun 2024 23:54:48 +0400 Subject: [PATCH 1/2] Add a test for AnonymousScan options (projection and slice pushdown) --- crates/polars-lazy/src/tests/io.rs | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/crates/polars-lazy/src/tests/io.rs b/crates/polars-lazy/src/tests/io.rs index 4afc3feada86..3913c8d22aae 100644 --- a/crates/polars-lazy/src/tests/io.rs +++ b/crates/polars-lazy/src/tests/io.rs @@ -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 { + 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<()> { From 7fd30740290232e908f85a52ab8062a132757a53 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Mon, 24 Jun 2024 00:05:09 +0400 Subject: [PATCH 2/2] rustfmt --- crates/polars-lazy/src/tests/io.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/polars-lazy/src/tests/io.rs b/crates/polars-lazy/src/tests/io.rs index 3913c8d22aae..a81b59dcef61 100644 --- a/crates/polars-lazy/src/tests/io.rs +++ b/crates/polars-lazy/src/tests/io.rs @@ -683,7 +683,7 @@ fn scan_anonymous_fn_with_options() -> PolarsResult<()> { } } - let function = Arc::new( MyScan{}); + let function = Arc::new(MyScan {}); let args = ScanArgsAnonymous { schema: Some(Arc::new(fruits_cars().schema())),