Skip to content

Commit e2a0ca6

Browse files
MarcoGorellimeeseeksmachine
authored andcommitted
Backport PR pandas-dev#48785: BUG: still emitting unnecessary FutureWarning in DataFrame.sort_values with sparse columns
1 parent ff7280b commit e2a0ca6

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
@@ -86,6 +86,7 @@ Bug fixes
8686
- Bug in :meth:`Series.__getitem__` not falling back to positional for integer keys and boolean :class:`Index` (:issue:`48653`)
8787
- Bug in :meth:`DataFrame.to_hdf` raising ``AssertionError`` with boolean index (:issue:`48667`)
8888
- Bug in :meth:`DataFrame.pivot_table` raising unexpected ``FutureWarning`` when setting datetime column as index (:issue:`48683`)
89+
- Bug in :meth:`DataFrame.sort_values` emitting unnecessary ``FutureWarning`` when called on :class:`DataFrame` with boolean sparse columns (:issue:`48784`)
8990
-
9091

9192
.. ---------------------------------------------------------------------------

pandas/core/sorting.py

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

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

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)