Skip to content

REGR: Fix comparison broadcasting over array of Intervals #35938

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

Merged
merged 9 commits into from
Aug 31, 2020
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.1.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Fixed regressions
~~~~~~~~~~~~~~~~~
- Regression in :meth:`DatetimeIndex.intersection` incorrectly raising ``AssertionError`` when intersecting against a list (:issue:`35876`)
- Performance regression for :meth:`RangeIndex.format` (:issue:`35712`)
- Regression in :meth:`DataFrame.replace` where a ``TypeError`` would be raised when attempting to replace elements of type :class:`Interval` (:issue:`35931`)
-


Expand Down
1 change: 0 additions & 1 deletion pandas/_libs/interval.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ cdef class Interval(IntervalMixin):
True
"""
_typ = "interval"
__array_priority__ = 1000

cdef readonly object left
"""
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/frame/methods/test_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -1581,3 +1581,10 @@ def test_replace_with_compiled_regex(self):
result = df.replace({regex: "z"}, regex=True)
expected = pd.DataFrame(["z", "b", "c"])
tm.assert_frame_equal(result, expected)

def test_replace_intervals(self):
# https://github.com/pandas-dev/pandas/issues/35931
df = pd.DataFrame({"a": [pd.Interval(0, 1), pd.Interval(0, 1)]})
result = df.replace({"a": {pd.Interval(0, 1): "x"}})
expected = pd.DataFrame({"a": ["x", "x"]})
tm.assert_frame_equal(result, expected)
12 changes: 12 additions & 0 deletions pandas/tests/scalar/interval/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,15 @@ def test_numeric_interval_add_timedelta_raises(interval, delta):

with pytest.raises((TypeError, ValueError), match=msg):
delta + interval


@pytest.mark.xfail(reason="https://github.com/pandas-dev/pandas/pull/35938")
def test_timdelta_add_timestamp_interval():
delta = np.timedelta64(0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here or follow-up we should get the full complement of add/sub with dt64/td64/pytimedelta/Tick/...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well parametrize over a few timedelta types here

expected = Interval(Timestamp("2020-01-01"), Timestamp("2020-02-01"))

result = delta + expected
assert result == expected

result = expected + delta
assert result == expected