Skip to content

Commit 54f4514

Browse files
mroeschkejreback
authored andcommitted
CLN: True option in Series.groupby.nth(dropna=) (#27168)
1 parent 58b1732 commit 54f4514

File tree

3 files changed

+11
-23
lines changed

3 files changed

+11
-23
lines changed

doc/source/whatsnew/v0.25.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ Removal of prior version deprecations/changes
644644
- Removed the previously deprecated ``raise_on_error`` keyword argument in :meth:`DataFrame.where` and :meth:`DataFrame.mask` (:issue:`17744`)
645645
- Removed the previously deprecated ``ordered`` and ``categories`` keyword arguments in ``astype`` (:issue:`17742`)
646646
- Removed the previously deprecated ``cdate_range`` (:issue:`17691`)
647+
- Removed the previously deprecated ``True`` option for the ``dropna`` keyword argument in :func:`SeriesGroupBy.nth` (:issue:`17493`)
647648

648649
.. _whatsnew_0250.performance:
649650

pandas/core/groupby/groupby.py

+5-17
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class providing the base-class of operations.
1313
from functools import partial, wraps
1414
import types
1515
from typing import FrozenSet, List, Optional, Tuple, Type, Union
16-
import warnings
1716

1817
import numpy as np
1918

@@ -1741,22 +1740,11 @@ def nth(self,
17411740
"dropna option with a list of nth values is not supported")
17421741

17431742
if dropna not in ['any', 'all']:
1744-
if isinstance(self._selected_obj, Series) and dropna is True:
1745-
warnings.warn("the dropna={dropna} keyword is deprecated,"
1746-
"use dropna='all' instead. "
1747-
"For a Series groupby, dropna must be "
1748-
"either None, 'any' or 'all'.".format(
1749-
dropna=dropna),
1750-
FutureWarning,
1751-
stacklevel=2)
1752-
dropna = 'all'
1753-
else:
1754-
# Note: when agg-ing picker doesn't raise this,
1755-
# just returns NaN
1756-
raise ValueError("For a DataFrame groupby, dropna must be "
1757-
"either None, 'any' or 'all', "
1758-
"(was passed {dropna}).".format(
1759-
dropna=dropna))
1743+
# Note: when agg-ing picker doesn't raise this, just returns NaN
1744+
raise ValueError("For a DataFrame groupby, dropna must be "
1745+
"either None, 'any' or 'all', "
1746+
"(was passed {dropna}).".format(
1747+
dropna=dropna))
17601748

17611749
# old behaviour, but with all and any support for DataFrames.
17621750
# modified in GH 7559 to have better perf

pandas/tests/groupby/test_nth.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
import pandas as pd
55
from pandas import DataFrame, Index, MultiIndex, Series, Timestamp, isna
6-
from pandas.util.testing import (
7-
assert_frame_equal, assert_produces_warning, assert_series_equal)
6+
from pandas.util.testing import assert_frame_equal, assert_series_equal
87

98

109
def test_first_last_nth(df):
@@ -168,13 +167,13 @@ def test_nth():
168167
result = s.groupby(g, sort=False).nth(0, dropna='all')
169168
assert_series_equal(result, expected)
170169

170+
with pytest.raises(ValueError, match='For a DataFrame groupby'):
171+
s.groupby(g, sort=False).nth(0, dropna=True)
172+
171173
# doc example
172174
df = DataFrame([[1, np.nan], [1, 4], [5, 6]], columns=['A', 'B'])
173175
g = df.groupby('A')
174-
# PR 17493, related to issue 11038
175-
# test Series.nth with True for dropna produces FutureWarning
176-
with assert_produces_warning(FutureWarning):
177-
result = g.B.nth(0, dropna=True)
176+
result = g.B.nth(0, dropna='all')
178177
expected = g.B.first()
179178
assert_series_equal(result, expected)
180179

0 commit comments

Comments
 (0)