Skip to content

Commit 820218d

Browse files
Backport PR #36118: REGR: ensure closed attribute of IntervalIndex is preserved in pickle roundtrip (#36119)
Co-authored-by: Joris Van den Bossche <[email protected]>
1 parent 8d057b2 commit 820218d

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

doc/source/whatsnew/v1.1.2.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ Fixed regressions
1818
- Fix regression in updating a column inplace (e.g. using ``df['col'].fillna(.., inplace=True)``) (:issue:`35731`)
1919
- Performance regression for :meth:`RangeIndex.format` (:issue:`35712`)
2020
- Regression in :meth:`DataFrame.replace` where a ``TypeError`` would be raised when attempting to replace elements of type :class:`Interval` (:issue:`35931`)
21+
- Fix regression in pickle roundtrip of the ``closed`` attribute of :class:`IntervalIndex` (:issue:`35658`)
2122
- Fixed regression in :meth:`DataFrameGroupBy.agg` where a ``ValueError: buffer source array is read-only`` would be raised when the underlying array is read-only (:issue:`36014`)
22-
23+
-
2324

2425
.. ---------------------------------------------------------------------------
2526

pandas/core/indexes/interval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def func(intvidx_self, other, sort=False):
190190
class IntervalIndex(IntervalMixin, ExtensionIndex):
191191
_typ = "intervalindex"
192192
_comparables = ["name"]
193-
_attributes = ["name"]
193+
_attributes = ["name", "closed"]
194194

195195
# we would like our indexing holder to defer to us
196196
_defer_to_indexing = True

pandas/tests/indexes/interval/test_interval.py

+7
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,13 @@ def test_get_value_non_scalar_errors(self, key):
874874
with tm.assert_produces_warning(FutureWarning):
875875
idx.get_value(s, key)
876876

877+
@pytest.mark.parametrize("closed", ["left", "right", "both"])
878+
def test_pickle_round_trip_closed(self, closed):
879+
# https://github.com/pandas-dev/pandas/issues/35658
880+
idx = IntervalIndex.from_tuples([(1, 2), (2, 3)], closed=closed)
881+
result = tm.round_trip_pickle(idx)
882+
tm.assert_index_equal(result, idx)
883+
877884

878885
def test_dir():
879886
# GH#27571 dir(interval_index) should not raise

0 commit comments

Comments
 (0)