Skip to content

Commit

Permalink
Backport PR pandas-dev#48785: BUG: still emitting unnecessary FutureW…
Browse files Browse the repository at this point in the history
…arning in DataFrame.sort_values with sparse columns
  • Loading branch information
MarcoGorelli authored and meeseeksmachine committed Sep 27, 2022
1 parent ff7280b commit e2a0ca6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Bug fixes
- Bug in :meth:`Series.__getitem__` not falling back to positional for integer keys and boolean :class:`Index` (:issue:`48653`)
- Bug in :meth:`DataFrame.to_hdf` raising ``AssertionError`` with boolean index (:issue:`48667`)
- 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`)
-

.. ---------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,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)

Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/frame/methods/test_sort_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e2a0ca6

Please sign in to comment.