From 43a54b5b9460ee4c768c1a9c792794925e6e0e37 Mon Sep 17 00:00:00 2001 From: Marco Edward Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Tue, 27 Sep 2022 11:05:19 +0100 Subject: [PATCH] BUG: still emitting unnecessary FutureWarning in DataFrame.sort_values with sparse columns (#48785) * BUG: still emitting unnecessary FutureWarning in DataFrame.sort_values with sparse columns * make whatsnew consistent Co-authored-by: MarcoGorelli <> --- doc/source/whatsnew/v1.5.1.rst | 1 + pandas/core/sorting.py | 4 +++- pandas/tests/frame/methods/test_sort_values.py | 5 +++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v1.5.1.rst b/doc/source/whatsnew/v1.5.1.rst index ef41b749c89e6..852166cbfaa7f 100644 --- a/doc/source/whatsnew/v1.5.1.rst +++ b/doc/source/whatsnew/v1.5.1.rst @@ -88,6 +88,7 @@ Bug fixes - Bug in :meth:`DataFrame.to_hdf` raising ``AssertionError`` with boolean index (:issue:`48667`) - Bug in :func:`assert_index_equal` for extension arrays with non matching ``NA`` raising ``ValueError`` (:issue:`48608`) - Bug in :meth:`DataFrame.pivot_table` raising unexpected ``FutureWarning`` when setting datetime column as index (:issue:`48683`) +- Bug in :meth:`DataFrame.sort_values` emitting unnecessary ``FutureWarning`` when called on :class:`DataFrame` with boolean sparse columns (:issue:`48784`) - .. --------------------------------------------------------------------------- diff --git a/pandas/core/sorting.py b/pandas/core/sorting.py index 2b386164028b7..58eef2a39b37a 100644 --- a/pandas/core/sorting.py +++ b/pandas/core/sorting.py @@ -344,7 +344,9 @@ def lexsort_indexer( with warnings.catch_warnings(): # TODO(2.0): unnecessary once deprecation is enforced # GH#45618 don't issue warning user can't do anything about - warnings.filterwarnings("ignore", ".*SparseArray.*", category=FutureWarning) + warnings.filterwarnings( + "ignore", ".*(SparseArray|SparseDtype).*", category=FutureWarning + ) cat = Categorical(k, ordered=True) diff --git a/pandas/tests/frame/methods/test_sort_values.py b/pandas/tests/frame/methods/test_sort_values.py index 9f3fcb1db546d..51b590263f893 100644 --- a/pandas/tests/frame/methods/test_sort_values.py +++ b/pandas/tests/frame/methods/test_sort_values.py @@ -15,11 +15,12 @@ class TestDataFrameSortValues: - def test_sort_values_sparse_no_warning(self): + @pytest.mark.parametrize("dtype", [np.uint8, bool]) + def test_sort_values_sparse_no_warning(self, dtype): # GH#45618 # TODO(2.0): test will be unnecessary ser = pd.Series(Categorical(["a", "b", "a"], categories=["a", "b", "c"])) - df = pd.get_dummies(ser, sparse=True) + df = pd.get_dummies(ser, dtype=dtype, sparse=True) with tm.assert_produces_warning(None): # No warnings about constructing Index from SparseArray