Skip to content

Commit c5058c2

Browse files
committed
DEPR: Add warning for True for dropna of SeriesGroupBy.nth
1 parent fdbc6b8 commit c5058c2

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pandas/core/groupby.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
compress_group_index, get_flattened_iterator,
5656
decons_obs_group_ids, get_indexer_dict)
5757
from pandas.util._decorators import (cache_readonly, Substitution,
58-
Appender, make_signature)
58+
Appender, make_signature, deprecate_kwarg)
5959
from pandas.io.formats.printing import pprint_thing
6060
from pandas.util._validators import validate_kwargs
6161

@@ -1296,6 +1296,8 @@ def backfill(self, limit=None):
12961296

12971297
@Substitution(name='groupby')
12981298
@Appender(_doc_template)
1299+
@deprecate_kwarg(old_arg_name='dropna', new_arg_name='dropna',
1300+
mapping={True: None})
12991301
def nth(self, n, dropna=None):
13001302
"""
13011303
Take the nth row from each group if n is an int, or a subset of rows

pandas/tests/groupby/test_nth.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
import pandas as pd
33
from pandas import DataFrame, MultiIndex, Index, Series, isna
44
from pandas.compat import lrange
5-
from pandas.util.testing import assert_frame_equal, assert_series_equal
5+
from pandas.util.testing import (
6+
assert_frame_equal,
7+
assert_produces_warning,
8+
assert_series_equal)
69

710
from .common import MixIn
811

@@ -232,6 +235,13 @@ def test_nth_multi_index_as_expected(self):
232235
names=['A', 'B']))
233236
assert_frame_equal(result, expected)
234237

238+
def test_nth_dropna(self):
239+
# PR XXXXX, related to issue 16442
240+
# test nth with True for dropna produces DeprecationWarning
241+
df = DataFrame([[1],[1,2]], columns=['1st', '2nd'])
242+
group = df.groupby('1st')['2nd']
243+
with assert_produces_warning(DeprecationWarning):
244+
group.nth(0, dropna=True)
235245

236246
def test_nth_empty():
237247
# GH 16064

0 commit comments

Comments
 (0)