Skip to content

Commit

Permalink
Backport PR #54945 on branch 2.1.x (REGR: MultiIndex.append raising f…
Browse files Browse the repository at this point in the history
…or overlapping IntervalIndex levels) (#54968)

Backport PR #54945: REGR: MultiIndex.append raising for overlapping IntervalIndex levels

Co-authored-by: Luke Manley <lukemanley@gmail.com>
  • Loading branch information
meeseeksmachine and lukemanley committed Sep 2, 2023
1 parent 84e8609 commit 44285e1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.1.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Fixed regressions
- Fixed regression in :func:`read_csv` when ``delim_whitespace`` is True (:issue:`54918`, :issue:`54931`)
- Fixed regression in :meth:`.GroupBy.get_group` raising for ``axis=1`` (:issue:`54858`)
- Fixed regression in :meth:`DataFrame.__setitem__` raising ``AssertionError`` when setting a :class:`Series` with a partial :class:`MultiIndex` (:issue:`54875`)
- Fixed regression in :meth:`MultiIndex.append` raising when appending overlapping :class:`IntervalIndex` levels (:issue:`54934`)
- Fixed regression in :meth:`Series.drop_duplicates` for PyArrow strings (:issue:`54904`)
- Fixed regression in :meth:`Series.value_counts` raising for numeric data if ``bins`` was specified (:issue:`54857`)
- Fixed regression when comparing a :class:`Series` with ``datetime64`` dtype with ``None`` (:issue:`54870`)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2950,7 +2950,7 @@ def recode_for_categories(
return codes

indexer = coerce_indexer_dtype(
new_categories.get_indexer(old_categories), new_categories
new_categories.get_indexer_for(old_categories), new_categories
)
new_codes = take_nd(indexer, codes, fill_value=-1)
return new_codes
Expand Down
22 changes: 22 additions & 0 deletions pandas/tests/indexes/multi/test_reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,28 @@ def test_append_names_dont_match():
tm.assert_index_equal(result, expected)


def test_append_overlapping_interval_levels():
# GH 54934
ivl1 = pd.IntervalIndex.from_breaks([0.0, 1.0, 2.0])
ivl2 = pd.IntervalIndex.from_breaks([0.5, 1.5, 2.5])
mi1 = MultiIndex.from_product([ivl1, ivl1])
mi2 = MultiIndex.from_product([ivl2, ivl2])
result = mi1.append(mi2)
expected = MultiIndex.from_tuples(
[
(pd.Interval(0.0, 1.0), pd.Interval(0.0, 1.0)),
(pd.Interval(0.0, 1.0), pd.Interval(1.0, 2.0)),
(pd.Interval(1.0, 2.0), pd.Interval(0.0, 1.0)),
(pd.Interval(1.0, 2.0), pd.Interval(1.0, 2.0)),
(pd.Interval(0.5, 1.5), pd.Interval(0.5, 1.5)),
(pd.Interval(0.5, 1.5), pd.Interval(1.5, 2.5)),
(pd.Interval(1.5, 2.5), pd.Interval(0.5, 1.5)),
(pd.Interval(1.5, 2.5), pd.Interval(1.5, 2.5)),
]
)
tm.assert_index_equal(result, expected)


def test_repeat():
reps = 2
numbers = [1, 2, 3]
Expand Down

0 comments on commit 44285e1

Please sign in to comment.