Skip to content

Commit edbac36

Browse files
authored
DEPR: categorical.mode (#49238)
1 parent 6c46013 commit edbac36

File tree

3 files changed

+5
-34
lines changed

3 files changed

+5
-34
lines changed

pandas/core/arrays/categorical.py

-23
Original file line numberDiff line numberDiff line change
@@ -2353,29 +2353,6 @@ def max(self, *, skipna: bool = True, **kwargs):
23532353
pointer = self._codes.max()
23542354
return self._wrap_reduction_result(None, pointer)
23552355

2356-
def mode(self, dropna: bool = True) -> Categorical:
2357-
"""
2358-
Returns the mode(s) of the Categorical.
2359-
2360-
Always returns `Categorical` even if only one value.
2361-
2362-
Parameters
2363-
----------
2364-
dropna : bool, default True
2365-
Don't consider counts of NaN/NaT.
2366-
2367-
Returns
2368-
-------
2369-
modes : `Categorical` (sorted)
2370-
"""
2371-
warn(
2372-
"Categorical.mode is deprecated and will be removed in a future version. "
2373-
"Use Series.mode instead.",
2374-
FutureWarning,
2375-
stacklevel=find_stack_level(),
2376-
)
2377-
return self._mode(dropna=dropna)
2378-
23792356
def _mode(self, dropna: bool = True) -> Categorical:
23802357
codes = self._codes
23812358
mask = None

pandas/tests/arrays/categorical/test_analytics.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,8 @@ def test_numpy_min_max_axis_equals_none(self, method, expected):
158158
],
159159
)
160160
def test_mode(self, values, categories, exp_mode):
161-
s = Categorical(values, categories=categories, ordered=True)
162-
msg = "Use Series.mode instead"
163-
with tm.assert_produces_warning(FutureWarning, match=msg):
164-
res = s.mode()
161+
cat = Categorical(values, categories=categories, ordered=True)
162+
res = Series(cat).mode()._values
165163
exp = Categorical(exp_mode, categories=categories, ordered=True)
166164
tm.assert_categorical_equal(res, exp)
167165

pandas/tests/test_algos.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -2296,21 +2296,17 @@ def test_uint64_overflow(self):
22962296
def test_categorical(self):
22972297
c = Categorical([1, 2])
22982298
exp = c
2299-
msg = "Categorical.mode is deprecated"
2300-
with tm.assert_produces_warning(FutureWarning, match=msg):
2301-
res = c.mode()
2299+
res = Series(c).mode()._values
23022300
tm.assert_categorical_equal(res, exp)
23032301

23042302
c = Categorical([1, "a", "a"])
23052303
exp = Categorical(["a"], categories=[1, "a"])
2306-
with tm.assert_produces_warning(FutureWarning, match=msg):
2307-
res = c.mode()
2304+
res = Series(c).mode()._values
23082305
tm.assert_categorical_equal(res, exp)
23092306

23102307
c = Categorical([1, 1, 2, 3, 3])
23112308
exp = Categorical([1, 3], categories=[1, 2, 3])
2312-
with tm.assert_produces_warning(FutureWarning, match=msg):
2313-
res = c.mode()
2309+
res = Series(c).mode()._values
23142310
tm.assert_categorical_equal(res, exp)
23152311

23162312
def test_index(self):

0 commit comments

Comments
 (0)