From e470b850ca5b52b5a196bb7a0dea4819b29eba04 Mon Sep 17 00:00:00 2001 From: phofl Date: Sat, 16 Jan 2021 03:16:05 +0100 Subject: [PATCH 1/2] BUG: assert_frame_equal raising TypeError with check_like and mixed dtype in Index or columns --- pandas/_testing/asserters.py | 6 +++--- pandas/tests/util/test_assert_frame_equal.py | 6 ++++++ pandas/tests/util/test_assert_index_equal.py | 6 ++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index 69e17199c9a90..b20cc0897ec18 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -29,7 +29,7 @@ Series, TimedeltaIndex, ) -from pandas.core.algorithms import take_1d +from pandas.core.algorithms import safe_sort, take_1d from pandas.core.arrays import ( DatetimeArray, ExtensionArray, @@ -344,8 +344,8 @@ def _get_ilevel_values(index, level): # If order doesn't matter then sort the index entries if not check_order: - left = left.sort_values() - right = right.sort_values() + left = Index(safe_sort(left)) + right = Index(safe_sort(right)) # MultiIndex special comparison for little-friendly error messages if left.nlevels > 1: diff --git a/pandas/tests/util/test_assert_frame_equal.py b/pandas/tests/util/test_assert_frame_equal.py index bb721afda2b8b..a594751808532 100644 --- a/pandas/tests/util/test_assert_frame_equal.py +++ b/pandas/tests/util/test_assert_frame_equal.py @@ -299,3 +299,9 @@ def test_allows_duplicate_labels(): with pytest.raises(AssertionError, match=" Date: Sat, 16 Jan 2021 03:15:18 +0100 Subject: [PATCH 2/2] BUG: assert_frame_equal raising TypeError with check_like and mixed dtype in Index or columns --- doc/source/whatsnew/v1.2.1.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.2.1.rst b/doc/source/whatsnew/v1.2.1.rst index 55fddb8b732e2..d9c2980d43473 100644 --- a/doc/source/whatsnew/v1.2.1.rst +++ b/doc/source/whatsnew/v1.2.1.rst @@ -30,7 +30,8 @@ Fixed regressions - Fixed regression that raised ``AttributeError`` with PyArrow versions [0.16.0, 1.0.0) (:issue:`38801`) - Fixed regression in :meth:`DataFrame.groupby` when aggregating an :class:`ExtensionDType` that could fail for non-numeric values (:issue:`38980`) - Fixed regression in :meth:`DataFrame.loc.__setitem__` raising ``KeyError`` with :class:`MultiIndex` and list-like columns indexer enlarging :class:`DataFrame` (:issue:`39147`) -- +- Fixed regression in :func:`pandas.testing.assert_frame_equal` raising ``TypeError`` with ``check_like=True`` when :class:`Index` or columns have mixed dtype (:issue:`39168`) + .. --------------------------------------------------------------------------- @@ -41,7 +42,7 @@ Bug fixes - Bug in :meth:`read_csv` with ``float_precision="high"`` caused segfault or wrong parsing of long exponent strings. This resulted in a regression in some cases as the default for ``float_precision`` was changed in pandas 1.2.0 (:issue:`38753`) - Bug in :func:`read_csv` not closing an opened file handle when a ``csv.Error`` or ``UnicodeDecodeError`` occurred while initializing (:issue:`39024`) -- +- Bug in :func:`pandas.testing.assert_index_equal` raising ``TypeError`` with ``check_order=False`` when :class:`Index` has mixed dtype (:issue:`39168`) .. ---------------------------------------------------------------------------