Skip to content

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

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 3 commits into from
Sep 2, 2023
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
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 @@ -17,6 +17,7 @@ Fixed regressions
- Fixed regression in :func:`read_csv` when ``usecols`` is given and ``dtypes`` is a dict for ``engine="python"`` (:issue:`54868`)
- 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 @@ -2948,7 +2948,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