Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(python): Update some Series dunder method type signatures #17053

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions py-polars/polars/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,32 +596,32 @@ def __repr__(self) -> str:
def __len__(self) -> int:
return self.len()

def __and__(self, other: Series) -> Self:
def __and__(self, other: Any) -> Self:
if not isinstance(other, Series):
other = Series([other])
return self._from_pyseries(self._s.bitand(other._s))

def __rand__(self, other: Series) -> Series:
def __rand__(self, other: Any) -> Series:
if not isinstance(other, Series):
other = Series([other])
return other & self

def __or__(self, other: Series) -> Self:
def __or__(self, other: Any) -> Self:
if not isinstance(other, Series):
other = Series([other])
return self._from_pyseries(self._s.bitor(other._s))

def __ror__(self, other: Series) -> Series:
def __ror__(self, other: Any) -> Series:
if not isinstance(other, Series):
other = Series([other])
return other | self

def __xor__(self, other: Series) -> Self:
def __xor__(self, other: Any) -> Self:
if not isinstance(other, Series):
other = Series([other])
return self._from_pyseries(self._s.bitxor(other._s))

def __rxor__(self, other: Series) -> Series:
def __rxor__(self, other: Any) -> Series:
if not isinstance(other, Series):
other = Series([other])
return other ^ self
Expand Down
12 changes: 3 additions & 9 deletions py-polars/tests/unit/series/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,21 +277,15 @@ def test_bitwise_ops() -> None:
# Note that the type annotations only allow Series to be passed in, but there is
# specific code to deal with non-Series inputs.
assert_series_equal(
(
True & a # type: ignore[operator]
),
(True & a),
pl.Series([True, False, True]),
)
assert_series_equal(
(
True | a # type: ignore[operator]
),
(True | a),
pl.Series([True, True, True]),
)
assert_series_equal(
(
True ^ a # type: ignore[operator]
),
(True ^ a),
pl.Series([False, True, False]),
)

Expand Down