Skip to content

Commit

Permalink
fix(rust,python): Allow selectors inside frame-level .filter() (pol…
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdlineluser authored Apr 4, 2024
1 parent 02f4d7f commit 31df06d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/polars-plan/src/logical_plan/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ impl LogicalPlanBuilder {
let predicate = if has_expr(&predicate, |e| match e {
Expr::Column(name) => is_regex_projection(name),
Expr::Wildcard
| Expr::Selector(_)
| Expr::RenameAlias { .. }
| Expr::Columns(_)
| Expr::DtypeColumn(_)
Expand Down
10 changes: 10 additions & 0 deletions py-polars/tests/unit/operations/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

import polars as pl
import polars.selectors as cs
from polars import PolarsDataType
from polars.testing import assert_frame_equal, assert_series_equal

Expand Down Expand Up @@ -242,6 +243,15 @@ def test_filter_logical_type_13194() -> None:
assert_frame_equal(df, expected_df)


def test_filter_horizontal_selector_15428() -> None:
df = pl.DataFrame({"a": [1, 2, 3]})

df = df.filter(pl.all_horizontal((cs.by_name("^.*$") & cs.integer()) <= 2))
expected_df = pl.DataFrame({"a": [1, 2]})

assert_frame_equal(df, expected_df)


@pytest.mark.slow()
@pytest.mark.parametrize(
"dtype", [pl.Boolean, pl.Int8, pl.Int16, pl.Int32, pl.Int64, pl.String]
Expand Down

0 comments on commit 31df06d

Please sign in to comment.