From 86283f3a09c30893193f3a57a6810b7a59282caf Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 13 Jan 2025 21:00:03 -0500 Subject: [PATCH 1/2] DOC: Whatsnew for sorting mode result --- doc/source/whatsnew/v2.3.0.rst | 2 +- pandas/tests/reshape/test_pivot.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/source/whatsnew/v2.3.0.rst b/doc/source/whatsnew/v2.3.0.rst index 9e0e095eb4de8..98410e483aae3 100644 --- a/doc/source/whatsnew/v2.3.0.rst +++ b/doc/source/whatsnew/v2.3.0.rst @@ -95,7 +95,7 @@ Timezones Numeric ^^^^^^^ -- +- Enabled :class:`Series.mode` and :class:`DataFrame.mode` with ``dropna=False`` to sort the result for all dtypes in the presence of NA values; previously only certain dtypes would sort (:issue:`60702`) - Conversion diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 374d236c8ff39..f0b43fdc5fae4 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -9,8 +9,6 @@ import numpy as np import pytest -from pandas._config import using_string_dtype - from pandas.compat.numpy import np_version_gte1p25 import pandas as pd @@ -2670,10 +2668,10 @@ def test_pivot_columns_not_given(self): # this still fails because columns=None gets passed down to unstack as level=None # while at that point None was converted to NaN - @pytest.mark.xfail( - using_string_dtype(), reason="TODO(infer_string) None is cast to NaN" - ) - def test_pivot_columns_is_none(self): + # @pytest.mark.xfail( + # using_string_dtype(), reason="TODO(infer_string) None is cast to NaN" + # ) + def test_pivot_columns_is_none(self, using_infer_string): # GH#48293 df = DataFrame({None: [1], "b": 2, "c": 3}) result = df.pivot(columns=None) @@ -2686,6 +2684,8 @@ def test_pivot_columns_is_none(self): result = df.pivot(columns=None, index="b", values="c") expected = DataFrame({1: 3}, index=Index([2], name="b")) + if using_infer_string: + expected.columns.name = np.nan tm.assert_frame_equal(result, expected) def test_pivot_index_is_none(self, using_infer_string): From d0051692d1c0c3c482d1406053d1eae958216959 Mon Sep 17 00:00:00 2001 From: richard Date: Tue, 21 Jan 2025 20:37:57 -0500 Subject: [PATCH 2/2] Reverts --- pandas/tests/reshape/test_pivot.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index f0b43fdc5fae4..374d236c8ff39 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -9,6 +9,8 @@ import numpy as np import pytest +from pandas._config import using_string_dtype + from pandas.compat.numpy import np_version_gte1p25 import pandas as pd @@ -2668,10 +2670,10 @@ def test_pivot_columns_not_given(self): # this still fails because columns=None gets passed down to unstack as level=None # while at that point None was converted to NaN - # @pytest.mark.xfail( - # using_string_dtype(), reason="TODO(infer_string) None is cast to NaN" - # ) - def test_pivot_columns_is_none(self, using_infer_string): + @pytest.mark.xfail( + using_string_dtype(), reason="TODO(infer_string) None is cast to NaN" + ) + def test_pivot_columns_is_none(self): # GH#48293 df = DataFrame({None: [1], "b": 2, "c": 3}) result = df.pivot(columns=None) @@ -2684,8 +2686,6 @@ def test_pivot_columns_is_none(self, using_infer_string): result = df.pivot(columns=None, index="b", values="c") expected = DataFrame({1: 3}, index=Index([2], name="b")) - if using_infer_string: - expected.columns.name = np.nan tm.assert_frame_equal(result, expected) def test_pivot_index_is_none(self, using_infer_string):