|
2 | 2 | import pandas as pd
|
3 | 3 | from pandas import DataFrame, MultiIndex, Index, Series, isna
|
4 | 4 | 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) |
6 | 9 |
|
7 | 10 | from .common import MixIn
|
8 | 11 |
|
@@ -168,13 +171,6 @@ def test_nth(self):
|
168 | 171 | result = s.groupby(g, sort=False).nth(0, dropna='all')
|
169 | 172 | assert_series_equal(result, expected)
|
170 | 173 |
|
171 |
| - # doc example |
172 |
| - df = DataFrame([[1, np.nan], [1, 4], [5, 6]], columns=['A', 'B']) |
173 |
| - g = df.groupby('A') |
174 |
| - result = g.B.nth(0, dropna=True) |
175 |
| - expected = g.B.first() |
176 |
| - assert_series_equal(result, expected) |
177 |
| - |
178 | 174 | # test multiple nth values
|
179 | 175 | df = DataFrame([[1, np.nan], [1, 3], [1, 4], [5, 6], [5, 7]],
|
180 | 176 | columns=['A', 'B'])
|
@@ -232,6 +228,17 @@ def test_nth_multi_index_as_expected(self):
|
232 | 228 | names=['A', 'B']))
|
233 | 229 | assert_frame_equal(result, expected)
|
234 | 230 |
|
| 231 | + def test_nth_dropna(self): |
| 232 | + # PR XXXXX, related to issue 16442 |
| 233 | + # test nth with True for dropna produces DeprecationWarning |
| 234 | + # old doc example |
| 235 | + df = DataFrame([[1, np.nan], [1, 4], [5, 6]], columns=['A', 'B']) |
| 236 | + g = df.groupby('A') |
| 237 | + with assert_produces_warning(FutureWarning): |
| 238 | + result = g.B.nth(0, dropna=True) |
| 239 | + expected = g.B.first() |
| 240 | + assert_series_equal(result, expected) |
| 241 | + |
235 | 242 |
|
236 | 243 | def test_nth_empty():
|
237 | 244 | # GH 16064
|
|
0 commit comments