diff --git a/doc/source/whatsnew/v2.3.2.rst b/doc/source/whatsnew/v2.3.2.rst deleted file mode 100644 index 53a8d28687518..0000000000000 --- a/doc/source/whatsnew/v2.3.2.rst +++ /dev/null @@ -1,34 +0,0 @@ -.. _whatsnew_232: - -What's new in 2.3.2 (August XX, 2025) -------------------------------------- - -These are the changes in pandas 2.3.2. See :ref:`release` for a full changelog -including other versions of pandas. - -{{ header }} - -.. --------------------------------------------------------------------------- -.. _whatsnew_232.string_fixes: - -Improvements and fixes for the StringDtype -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Most changes in this release are related to :class:`StringDtype` which will -become the default string dtype in pandas 3.0. See -:ref:`whatsnew_230.upcoming_changes` for more details. - -.. _whatsnew_232.string_fixes.bugs: - -Bug fixes -^^^^^^^^^ -- Fix :meth:`~DataFrame.to_json` with ``orient="table"`` to correctly use the - "string" type in the JSON Table Schema for :class:`StringDtype` columns - (:issue:`61889`) -- Boolean operations (``|``, ``&``, ``^``) with bool-dtype objects on the left and :class:`StringDtype` objects on the right now cast the string to bool, with a deprecation warning (:issue:`60234`) - -.. --------------------------------------------------------------------------- -.. _whatsnew_232.contributors: - -Contributors -~~~~~~~~~~~~ diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index daa5187cdb636..0f1f6e9e5612d 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -495,8 +495,15 @@ def assert_categorical_equal( lc, rc = left.categories, right.categories assert_index_equal(lc, rc, obj=f"{obj}.categories", exact=exact) assert_index_equal( - left.categories.take(left.codes), - right.categories.take(right.codes), + Index( + [left.categories[code] if code >= 0 else np.nan for code in left.codes] + ), + Index( + [ + right.categories[code] if code >= 0 else np.nan + for code in right.codes + ] + ), obj=f"{obj}.values", exact=exact, ) diff --git a/pandas/tests/util/test_assert_categorical_equal.py b/pandas/tests/util/test_assert_categorical_equal.py index c171564574708..213ab50159115 100644 --- a/pandas/tests/util/test_assert_categorical_equal.py +++ b/pandas/tests/util/test_assert_categorical_equal.py @@ -1,3 +1,4 @@ +import numpy as np import pytest from pandas import Categorical @@ -86,3 +87,15 @@ def test_categorical_equal_object_override(obj): with pytest.raises(AssertionError, match=msg): tm.assert_categorical_equal(c1, c2, obj=obj) + + +def test_categorical_equal_with_nans_and_different_order(): + # GH#62008 + values = ["B", np.nan, "D"] + categories_left = ["B", "D"] + categories_right = categories_left[::-1] + + left = Categorical(values, categories=categories_left) + right = Categorical(values, categories=categories_right) + + tm.assert_categorical_equal(left, right, check_category_order=False)