Skip to content

Commit

Permalink
Allow selection with Series in col() (#1602)
Browse files Browse the repository at this point in the history
  • Loading branch information
markfairbanks committed Oct 26, 2021
1 parent e1a60a9 commit 4509e76
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions py-polars/polars/lazy/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ def col(
╰───────────┴─────╯
"""
if isinstance(name, pl.Series):
name = name.to_list()

if isclass(name) and issubclass(name, DataType): # type: ignore
name = [name] # type: ignore
Expand Down
7 changes: 7 additions & 0 deletions py-polars/tests/test_lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,13 @@ def test_exclude_selection():
assert df.select([pl.exclude("a")]).columns == ["b", "c"]


def test_col_series_selection():
df = pl.DataFrame({"a": [1], "b": [1], "c": [1]}).lazy()
srs = pl.Series(["b", "c"])

assert df.select(pl.col(srs)).columns == ["b", "c"]


def test_literal_projection():
df = pl.DataFrame({"a": [1, 2]})
assert df.select([True]).dtypes == [pl.Boolean]
Expand Down

0 comments on commit 4509e76

Please sign in to comment.