Skip to content

Commit

Permalink
fix(python): selectors by_name and by_dtype should allow empty list a…
Browse files Browse the repository at this point in the history
…s input (pola-rs#11024)

Co-authored-by: Antonio Caballero <antonio.caballero@concirrus.com>
  • Loading branch information
2 people authored and r-brink committed Jan 15, 2024
1 parent 1797ee4 commit cbdf0de
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions py-polars/polars/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ def by_dtype(
raise TypeError(msg)

return _selector_proxy_(
F.col(*all_dtypes), name="by_dtype", parameters={"dtypes": all_dtypes}
F.col(all_dtypes), name="by_dtype", parameters={"dtypes": all_dtypes}
)


Expand Down Expand Up @@ -661,7 +661,7 @@ def by_name(*names: str | Collection[str]) -> SelectorType:
TypeError(f"Invalid name: {nm!r}")

return _selector_proxy_(
F.col(*all_names), name="by_name", parameters={"*names": all_names}
F.col(all_names), name="by_name", parameters={"*names": all_names}
)


Expand Down
4 changes: 4 additions & 0 deletions py-polars/tests/unit/test_selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def test_selector_by_dtype(df: pl.DataFrame) -> None:
"fgg": pl.Boolean,
"qqR": pl.String,
}
assert df.select(cs.by_dtype()).schema == {}
assert df.select(cs.by_dtype([])).schema == {}


def test_selector_by_name(df: pl.DataFrame) -> None:
Expand All @@ -75,6 +77,8 @@ def test_selector_by_name(df: pl.DataFrame) -> None:
"JJK",
"qqR",
]
assert df.select(cs.by_name()).columns == []
assert df.select(cs.by_name([])).columns == []


def test_selector_contains(df: pl.DataFrame) -> None:
Expand Down

0 comments on commit cbdf0de

Please sign in to comment.