Skip to content

Commit 43a54b5

Browse files
authored
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 <>
1 parent 49d4c07 commit 43a54b5

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

doc/source/whatsnew/v1.5.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Bug fixes
8888
- Bug in :meth:`DataFrame.to_hdf` raising ``AssertionError`` with boolean index (:issue:`48667`)
8989
- Bug in :func:`assert_index_equal` for extension arrays with non matching ``NA`` raising ``ValueError`` (:issue:`48608`)
9090
- Bug in :meth:`DataFrame.pivot_table` raising unexpected ``FutureWarning`` when setting datetime column as index (:issue:`48683`)
91+
- Bug in :meth:`DataFrame.sort_values` emitting unnecessary ``FutureWarning`` when called on :class:`DataFrame` with boolean sparse columns (:issue:`48784`)
9192
-
9293

9394
.. ---------------------------------------------------------------------------

pandas/core/sorting.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,9 @@ def lexsort_indexer(
344344
with warnings.catch_warnings():
345345
# TODO(2.0): unnecessary once deprecation is enforced
346346
# GH#45618 don't issue warning user can't do anything about
347-
warnings.filterwarnings("ignore", ".*SparseArray.*", category=FutureWarning)
347+
warnings.filterwarnings(
348+
"ignore", ".*(SparseArray|SparseDtype).*", category=FutureWarning
349+
)
348350

349351
cat = Categorical(k, ordered=True)
350352

pandas/tests/frame/methods/test_sort_values.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515

1616

1717
class TestDataFrameSortValues:
18-
def test_sort_values_sparse_no_warning(self):
18+
@pytest.mark.parametrize("dtype", [np.uint8, bool])
19+
def test_sort_values_sparse_no_warning(self, dtype):
1920
# GH#45618
2021
# TODO(2.0): test will be unnecessary
2122
ser = pd.Series(Categorical(["a", "b", "a"], categories=["a", "b", "c"]))
22-
df = pd.get_dummies(ser, sparse=True)
23+
df = pd.get_dummies(ser, dtype=dtype, sparse=True)
2324

2425
with tm.assert_produces_warning(None):
2526
# No warnings about constructing Index from SparseArray

0 commit comments

Comments
 (0)