From 09472596b9153af56e93c22d10350e0d51a05a61 Mon Sep 17 00:00:00 2001 From: siddharthv Date: Fri, 25 Oct 2024 10:58:53 +0530 Subject: [PATCH 1/3] Remove wildcard expansion --- crates/polars-plan/src/dsl/functions/temporal.rs | 2 +- crates/polars-plan/src/dsl/list.rs | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/crates/polars-plan/src/dsl/functions/temporal.rs b/crates/polars-plan/src/dsl/functions/temporal.rs index 48508dba40d8..9a18abda55fd 100644 --- a/crates/polars-plan/src/dsl/functions/temporal.rs +++ b/crates/polars-plan/src/dsl/functions/temporal.rs @@ -427,7 +427,7 @@ pub fn duration(args: DurationArgs) -> Expr { function: FunctionExpr::TemporalExpr(TemporalFunction::Duration(args.time_unit)), options: FunctionOptions { collect_groups: ApplyOptions::ElementWise, - flags: FunctionFlags::default() | FunctionFlags::INPUT_WILDCARD_EXPANSION, + flags: FunctionFlags::default(), ..Default::default() }, } diff --git a/crates/polars-plan/src/dsl/list.rs b/crates/polars-plan/src/dsl/list.rs index fb0c7a83b463..5ad098924b42 100644 --- a/crates/polars-plan/src/dsl/list.rs +++ b/crates/polars-plan/src/dsl/list.rs @@ -339,10 +339,6 @@ impl ListNameSpace { false, None, ) - .with_function_options(|mut options| { - options.flags |= FunctionFlags::INPUT_WILDCARD_EXPANSION; - options - }) } #[cfg(feature = "list_count")] /// Count how often the value produced by ``element`` occurs. @@ -356,10 +352,6 @@ impl ListNameSpace { false, None, ) - .with_function_options(|mut options| { - options.flags |= FunctionFlags::INPUT_WILDCARD_EXPANSION; - options - }) } #[cfg(feature = "list_sets")] From 346545e9d1ace94e313917c9d11a250e0317cdd0 Mon Sep 17 00:00:00 2001 From: siddharthv Date: Fri, 25 Oct 2024 13:14:09 +0530 Subject: [PATCH 2/3] pre commit --- crates/polars-plan/src/dsl/list.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/crates/polars-plan/src/dsl/list.rs b/crates/polars-plan/src/dsl/list.rs index 5ad098924b42..ceec55123fcd 100644 --- a/crates/polars-plan/src/dsl/list.rs +++ b/crates/polars-plan/src/dsl/list.rs @@ -332,26 +332,24 @@ impl ListNameSpace { pub fn contains>(self, other: E) -> Expr { let other = other.into(); - self.0 - .map_many_private( - FunctionExpr::ListExpr(ListFunction::Contains), - &[other], - false, - None, - ) + self.0.map_many_private( + FunctionExpr::ListExpr(ListFunction::Contains), + &[other], + false, + None, + ) } #[cfg(feature = "list_count")] /// Count how often the value produced by ``element`` occurs. pub fn count_matches>(self, element: E) -> Expr { let other = element.into(); - self.0 - .map_many_private( - FunctionExpr::ListExpr(ListFunction::CountMatches), - &[other], - false, - None, - ) + self.0.map_many_private( + FunctionExpr::ListExpr(ListFunction::CountMatches), + &[other], + false, + None, + ) } #[cfg(feature = "list_sets")] From fbc82a234908b773d80a12b2b8cc8deaff51623e Mon Sep 17 00:00:00 2001 From: siddharthv Date: Sat, 26 Oct 2024 08:21:55 +0530 Subject: [PATCH 3/3] Add tests --- .../functions/as_datatype/test_duration.py | 9 +++++++++ .../operations/namespaces/list/test_list.py | 20 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/py-polars/tests/unit/functions/as_datatype/test_duration.py b/py-polars/tests/unit/functions/as_datatype/test_duration.py index 8bef49e1f074..a3fc5dc658ef 100644 --- a/py-polars/tests/unit/functions/as_datatype/test_duration.py +++ b/py-polars/tests/unit/functions/as_datatype/test_duration.py @@ -181,3 +181,12 @@ def test_duration_time_unit_ms() -> None: result = pl.duration(milliseconds=4) expected = pl.duration(milliseconds=4, time_unit="us") assert_frame_equal(pl.select(result), pl.select(expected)) + + +def test_duration_wildcard_expansion() -> None: + # Test that wildcard expansions occurs correctly in pl.duration + # https://github.com/pola-rs/polars/issues/19007 + df = df = pl.DataFrame({"a": [1], "b": [2]}) + assert df.select(pl.duration(hours=pl.all()).name.keep()).to_dict( + as_series=False + ) == {"a": [timedelta(seconds=3600)], "b": [timedelta(seconds=7200)]} diff --git a/py-polars/tests/unit/operations/namespaces/list/test_list.py b/py-polars/tests/unit/operations/namespaces/list/test_list.py index dfe6adad08d0..75052bfe636f 100644 --- a/py-polars/tests/unit/operations/namespaces/list/test_list.py +++ b/py-polars/tests/unit/operations/namespaces/list/test_list.py @@ -246,6 +246,16 @@ def test_list_contains_invalid_datatype() -> None: df.select(pl.col("a").list.contains(2)) +def test_list_contains_wildcard_expansion() -> None: + # Test that wildcard expansions occurs correctly in list.contains + # https://github.com/pola-rs/polars/issues/18968 + df = pl.DataFrame({"a": [[1, 2]], "b": [[3, 4]]}) + assert df.select(pl.all().list.contains(3)).to_dict(as_series=False) == { + "a": [False], + "b": [True], + } + + def test_list_concat() -> None: df = pl.DataFrame({"a": [[1, 2], [1], [1, 2, 3]]}) @@ -686,6 +696,16 @@ def test_list_count_matches_boolean_nulls_9141() -> None: assert a.select(pl.col("a").list.count_matches(True))["a"].to_list() == [1] +def test_list_count_matches_wildcard_expansion() -> None: + # Test that wildcard expansions occurs correctly in list.count_match + # https://github.com/pola-rs/polars/issues/18968 + df = pl.DataFrame({"a": [[1, 2]], "b": [[3, 4]]}) + assert df.select(pl.all().list.count_matches(3)).to_dict(as_series=False) == { + "a": [0], + "b": [1], + } + + def test_list_gather_oob_10079() -> None: df = pl.DataFrame( {