diff --git a/narwhals/_pandas_like/selectors.py b/narwhals/_pandas_like/selectors.py index b28f320f5..91036b9bc 100644 --- a/narwhals/_pandas_like/selectors.py +++ b/narwhals/_pandas_like/selectors.py @@ -2,6 +2,7 @@ from typing import TYPE_CHECKING from typing import Any +from typing import NoReturn from narwhals import dtypes from narwhals._pandas_like.expr import PandasExpr @@ -147,3 +148,12 @@ def call(df: PandasDataFrame) -> list[PandasSeries]: def __invert__(self) -> PandasSelector: return PandasSelectorNamespace(self._implementation).all() - self + + def __rsub__(self, other: Any) -> NoReturn: + raise NotImplementedError + + def __rand__(self, other: Any) -> NoReturn: + raise NotImplementedError + + def __ror__(self, other: Any) -> NoReturn: + raise NotImplementedError diff --git a/tests/selectors_test.py b/tests/selectors_test.py index ccf1b43e5..286944028 100644 --- a/tests/selectors_test.py +++ b/tests/selectors_test.py @@ -87,3 +87,13 @@ def test_set_ops( df = nw.from_native(constructor(data)) result = df.select(selector).columns assert sorted(result) == expected + + +def test_set_ops_invalid() -> None: + df = nw.from_native(pd.DataFrame(data)) + with pytest.raises(NotImplementedError): + df.select(1 - numeric()) + with pytest.raises(NotImplementedError): + df.select(1 | numeric()) + with pytest.raises(NotImplementedError): + df.select(1 & numeric())