Skip to content

DEPR: categorical.mode #49238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2353,29 +2353,6 @@ def max(self, *, skipna: bool = True, **kwargs):
pointer = self._codes.max()
return self._wrap_reduction_result(None, pointer)

def mode(self, dropna: bool = True) -> Categorical:
"""
Returns the mode(s) of the Categorical.

Always returns `Categorical` even if only one value.

Parameters
----------
dropna : bool, default True
Don't consider counts of NaN/NaT.

Returns
-------
modes : `Categorical` (sorted)
"""
warn(
"Categorical.mode is deprecated and will be removed in a future version. "
"Use Series.mode instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
return self._mode(dropna=dropna)

def _mode(self, dropna: bool = True) -> Categorical:
codes = self._codes
mask = None
Expand Down
6 changes: 2 additions & 4 deletions pandas/tests/arrays/categorical/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,8 @@ def test_numpy_min_max_axis_equals_none(self, method, expected):
],
)
def test_mode(self, values, categories, exp_mode):
s = Categorical(values, categories=categories, ordered=True)
msg = "Use Series.mode instead"
with tm.assert_produces_warning(FutureWarning, match=msg):
res = s.mode()
cat = Categorical(values, categories=categories, ordered=True)
res = Series(cat).mode()._values
exp = Categorical(exp_mode, categories=categories, ordered=True)
tm.assert_categorical_equal(res, exp)

Expand Down
10 changes: 3 additions & 7 deletions pandas/tests/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -2296,21 +2296,17 @@ def test_uint64_overflow(self):
def test_categorical(self):
c = Categorical([1, 2])
exp = c
msg = "Categorical.mode is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
res = c.mode()
res = Series(c).mode()._values
tm.assert_categorical_equal(res, exp)

c = Categorical([1, "a", "a"])
exp = Categorical(["a"], categories=[1, "a"])
with tm.assert_produces_warning(FutureWarning, match=msg):
res = c.mode()
res = Series(c).mode()._values
tm.assert_categorical_equal(res, exp)

c = Categorical([1, 1, 2, 3, 3])
exp = Categorical([1, 3], categories=[1, 2, 3])
with tm.assert_produces_warning(FutureWarning, match=msg):
res = c.mode()
res = Series(c).mode()._values
tm.assert_categorical_equal(res, exp)

def test_index(self):
Expand Down