Skip to content

Commit

Permalink
raise on right-hand selectors ops
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Jun 2, 2024
1 parent 7c83032 commit 19d3bae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions narwhals/_pandas_like/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
10 changes: 10 additions & 0 deletions tests/selectors_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

0 comments on commit 19d3bae

Please sign in to comment.