Skip to content

Commit

Permalink
test: handle empty sequences to _to_selector and test empty c()
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Aug 26, 2024
1 parent e225604 commit c5b8e3a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 2 additions & 0 deletions ibis/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,5 +720,7 @@ def _to_selector(
raise exc.IbisInputError(
f"Cannot compose {obj.__class__.__name__} with other selectors"
)
elif not obj:
return none()
else:
return any_of(*obj)
17 changes: 10 additions & 7 deletions ibis/tests/expr/test_selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,19 +531,22 @@ def test_methods(penguins):
assert [col.get_name() for col in bound] == penguins.columns


def test_none_selector(penguins):
assert not s.none().expand(penguins)
assert not s.none().expand_names(penguins)
@pytest.mark.parametrize("sel", [s.none(), s.c(), []])
def test_none_selector(penguins, sel):
sel = s._to_selector(sel)

assert list((s.none() | s.c("year")).expand_names(penguins)) == ["year"]
assert not sel.expand(penguins)
assert not sel.expand_names(penguins)

assert list((sel | s.c("year")).expand_names(penguins)) == ["year"]

with pytest.raises(exc.IbisError):
penguins.select(s.none())
penguins.select(sel)

with pytest.raises(exc.IbisError):
penguins.select(s.none() & s.c("year"))
penguins.select(sel & s.c("year"))

assert penguins.select(s.none() | s.c("year")).equals(penguins.select("year"))
assert penguins.select(sel | s.c("year")).equals(penguins.select("year"))


def test_invalid_composition():
Expand Down

0 comments on commit c5b8e3a

Please sign in to comment.