Skip to content

Commit 11d7455

Browse files
phoflnoatamir
authored andcommitted
REG: Fix regression in assert_frame_equal for categorical and check_like (pandas-dev#48987)
1 parent ea21483 commit 11d7455

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

doc/source/whatsnew/v1.5.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Fixed regressions
7979
- Fixed performance regression in :func:`factorize` when ``na_sentinel`` is not ``None`` and ``sort=False`` (:issue:`48620`)
8080
- Fixed regression causing an ``AttributeError`` during warning emitted if the provided table name in :meth:`DataFrame.to_sql` and the table name actually used in the database do not match (:issue:`48733`)
8181
- Fixed regression in :func:`to_datetime` when ``arg`` was a date string with nanosecond and ``format`` contained ``%f`` would raise a ``ValueError`` (:issue:`48767`)
82+
- Fixed regression in :func:`assert_frame_equal` raising for :class:`MultiIndex` with :class:`Categorical` and ``check_like=True`` (:issue:`48975`)
8283
- Fixed regression in :meth:`DataFrame.fillna` replacing wrong values for ``datetime64[ns]`` dtype and ``inplace=True`` (:issue:`48863`)
8384
- Fixed :meth:`.DataFrameGroupBy.size` not returning a Series when ``axis=1`` (:issue:`48738`)
8485
- Fixed Regression in :meth:`DataFrameGroupBy.apply` when user defined function is called on an empty dataframe (:issue:`47985`)

pandas/core/indexes/api.py

+3
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ def safe_sort_index(index: Index) -> Index:
190190
except TypeError:
191191
pass
192192
else:
193+
if isinstance(array_sorted, MultiIndex):
194+
return array_sorted
195+
193196
array_sorted = cast(np.ndarray, array_sorted)
194197
if isinstance(index, MultiIndex):
195198
index = MultiIndex.from_tuples(array_sorted, names=index.names)

pandas/tests/util/test_assert_frame_equal.py

+23
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,26 @@ def test_assert_frame_equal_checking_allow_dups_flag():
343343

344344
with pytest.raises(AssertionError, match="allows_duplicate_labels"):
345345
tm.assert_frame_equal(left, right, check_flags=True)
346+
347+
348+
def test_assert_frame_equal_check_like_categorical_midx():
349+
# GH#48975
350+
left = DataFrame(
351+
[[1], [2], [3]],
352+
index=pd.MultiIndex.from_arrays(
353+
[
354+
pd.Categorical(["a", "b", "c"]),
355+
pd.Categorical(["a", "b", "c"]),
356+
]
357+
),
358+
)
359+
right = DataFrame(
360+
[[3], [2], [1]],
361+
index=pd.MultiIndex.from_arrays(
362+
[
363+
pd.Categorical(["c", "b", "a"]),
364+
pd.Categorical(["c", "b", "a"]),
365+
]
366+
),
367+
)
368+
tm.assert_frame_equal(left, right, check_like=True)

0 commit comments

Comments
 (0)