Skip to content

Commit

Permalink
fix[python]: dispatch logical type arithmetic to series (#4929)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 22, 2022
1 parent 289fb00 commit 770a089
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions py-polars/polars/internals/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,11 @@ def __le__(self, other: Any) -> Series:
def _arithmetic(self, other: Any, op_s: str, op_ffi: str) -> Series:
if isinstance(other, Series):
return wrap_s(getattr(self._s, op_s)(other._s))
# we recurse and the if statement above will
# ensure we return early
if isinstance(other, (date, datetime, timedelta, str)):
other = Series("", [other])
return self._arithmetic(other, op_s, op_ffi)
if isinstance(other, float) and not self.is_float():
_s = sequence_to_pyseries("", [other])
if "rhs" in op_ffi:
Expand Down
6 changes: 6 additions & 0 deletions py-polars/tests/unit/test_arithmetic.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import date

import polars as pl


Expand All @@ -11,3 +13,7 @@ def test_sqrt_neg_inf() -> None:
assert str(out["sqrt"].to_list()) == str(
[float("NaN"), float("NaN"), 0.0, 3.0, float("Inf")]
)


def test_arithmetic_with_logical_on_series_4920() -> None:
assert (pl.Series([date(2022, 6, 3)]) - date(2022, 1, 1)).dtype == pl.Duration("ms")

0 comments on commit 770a089

Please sign in to comment.