From c5b8e3ab8c180f7b4253d3d315b1c7828b94556e Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Mon, 26 Aug 2024 11:04:57 -0400 Subject: [PATCH] test: handle empty sequences to `_to_selector` and test empty `c()` --- ibis/selectors.py | 2 ++ ibis/tests/expr/test_selectors.py | 17 ++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ibis/selectors.py b/ibis/selectors.py index 8d5b516c0e8f..14d80ed0f4cb 100644 --- a/ibis/selectors.py +++ b/ibis/selectors.py @@ -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) diff --git a/ibis/tests/expr/test_selectors.py b/ibis/tests/expr/test_selectors.py index 5c53f46bb9ae..c254ab3f8886 100644 --- a/ibis/tests/expr/test_selectors.py +++ b/ibis/tests/expr/test_selectors.py @@ -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():