From fd4cbe37d1d1115d5f641b8df2aaf7fce924d716 Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Sun, 30 Jun 2019 22:16:20 -0500 Subject: [PATCH 1/4] CLN: True option in Series.groupby.nth(dropna=) --- doc/source/whatsnew/v0.25.0.rst | 1 + pandas/core/groupby/groupby.py | 21 +++++---------------- pandas/tests/groupby/test_nth.py | 8 ++------ 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index e42752cca9043..918970445708c 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -640,6 +640,7 @@ Removal of prior version deprecations/changes - Removed the previously deprecated ``raise_on_error`` keyword argument in :meth:`DataFrame.where` and :meth:`DataFrame.mask` (:issue:`17744`) - Removed the previously deprecated ``ordered`` and ``categories`` keyword arguments in ``astype`` (:issue:`17742`) - Removed the previously deprecated ``cdate_range`` (:issue:`17691`) +- Removed the previously deprecated ``True`` option for the ``dropan`` keyword argument in :func:`SeriesGroupBy.nth` (:issue:`17493`) .. _whatsnew_0250.performance: diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 202d4fb15f971..f83d7d04edc1a 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -1741,22 +1741,11 @@ def nth(self, "dropna option with a list of nth values is not supported") if dropna not in ['any', 'all']: - if isinstance(self._selected_obj, Series) and dropna is True: - warnings.warn("the dropna={dropna} keyword is deprecated," - "use dropna='all' instead. " - "For a Series groupby, dropna must be " - "either None, 'any' or 'all'.".format( - dropna=dropna), - FutureWarning, - stacklevel=2) - dropna = 'all' - else: - # Note: when agg-ing picker doesn't raise this, - # just returns NaN - raise ValueError("For a DataFrame groupby, dropna must be " - "either None, 'any' or 'all', " - "(was passed {dropna}).".format( - dropna=dropna)) + # Note: when agg-ing picker doesn't raise this, just returns NaN + raise ValueError("For a DataFrame groupby, dropna must be " + "either None, 'any' or 'all', " + "(was passed {dropna}).".format( + dropna=dropna)) # old behaviour, but with all and any support for DataFrames. # modified in GH 7559 to have better perf diff --git a/pandas/tests/groupby/test_nth.py b/pandas/tests/groupby/test_nth.py index b174fb0e0b6f9..21017ceb715be 100644 --- a/pandas/tests/groupby/test_nth.py +++ b/pandas/tests/groupby/test_nth.py @@ -3,8 +3,7 @@ import pandas as pd from pandas import DataFrame, Index, MultiIndex, Series, Timestamp, isna -from pandas.util.testing import ( - assert_frame_equal, assert_produces_warning, assert_series_equal) +from pandas.util.testing import assert_frame_equal, assert_series_equal def test_first_last_nth(df): @@ -171,10 +170,7 @@ def test_nth(): # doc example df = DataFrame([[1, np.nan], [1, 4], [5, 6]], columns=['A', 'B']) g = df.groupby('A') - # PR 17493, related to issue 11038 - # test Series.nth with True for dropna produces FutureWarning - with assert_produces_warning(FutureWarning): - result = g.B.nth(0, dropna=True) + result = g.B.nth(0, dropna='all') expected = g.B.first() assert_series_equal(result, expected) From 5334f057300b0677334bdeadec918f71134aa609 Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Mon, 1 Jul 2019 09:20:50 -0700 Subject: [PATCH 2/4] Fix whatsnew note --- doc/source/whatsnew/v0.25.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 76a78bb9d5351..93b74a86dd0d5 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -644,7 +644,7 @@ Removal of prior version deprecations/changes - Removed the previously deprecated ``raise_on_error`` keyword argument in :meth:`DataFrame.where` and :meth:`DataFrame.mask` (:issue:`17744`) - Removed the previously deprecated ``ordered`` and ``categories`` keyword arguments in ``astype`` (:issue:`17742`) - Removed the previously deprecated ``cdate_range`` (:issue:`17691`) -- Removed the previously deprecated ``True`` option for the ``dropan`` keyword argument in :func:`SeriesGroupBy.nth` (:issue:`17493`) +- Removed the previously deprecated ``True`` option for the ``dropna`` keyword argument in :func:`SeriesGroupBy.nth` (:issue:`17493`) .. _whatsnew_0250.performance: From 77fd5c4746a8eda46194e63753152e89376cd0e6 Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Mon, 1 Jul 2019 12:01:40 -0700 Subject: [PATCH 3/4] Remove unused import --- pandas/core/groupby/groupby.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index f83d7d04edc1a..925f006de92b6 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -13,7 +13,6 @@ class providing the base-class of operations. from functools import partial, wraps import types from typing import FrozenSet, List, Optional, Tuple, Type, Union -import warnings import numpy as np From 5a9b5a937d77c8484bbbaf95f36ebf7fa71d4dfd Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Mon, 1 Jul 2019 14:00:06 -0700 Subject: [PATCH 4/4] Add test for new behavior --- pandas/tests/groupby/test_nth.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/tests/groupby/test_nth.py b/pandas/tests/groupby/test_nth.py index 21017ceb715be..deb0f48b9cea2 100644 --- a/pandas/tests/groupby/test_nth.py +++ b/pandas/tests/groupby/test_nth.py @@ -167,6 +167,9 @@ def test_nth(): result = s.groupby(g, sort=False).nth(0, dropna='all') assert_series_equal(result, expected) + with pytest.raises(ValueError, match='For a DataFrame groupby'): + s.groupby(g, sort=False).nth(0, dropna=True) + # doc example df = DataFrame([[1, np.nan], [1, 4], [5, 6]], columns=['A', 'B']) g = df.groupby('A')