diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index 1a32498d53c23..1c00c18a24717 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -149,6 +149,7 @@ Other enhancements - ``Series/DataFrame.asfreq()`` have gained a ``fill_value`` parameter, to fill missing values (:issue:`3715`). - ``Series/DataFrame.resample.asfreq`` have gained a ``fill_value`` parameter, to fill missing values during resampling (:issue:`3715`). - ``pandas.tools.hashing`` has gained a ``hash_tuples`` routine, and ``hash_pandas_object`` has gained the ability to hash a ``MultiIndex`` (:issue:`15224`) +- ``groupby(..).resample()`` is now able to use the ``on`` argument. (:issue:`15021`) .. _ISO 8601 duration: https://en.wikipedia.org/wiki/ISO_8601#Durations diff --git a/pandas/core/groupby.py b/pandas/core/groupby.py index 99220232114ce..9cdbcf5d07402 100644 --- a/pandas/core/groupby.py +++ b/pandas/core/groupby.py @@ -1140,13 +1140,13 @@ def ohlc(self): @Substitution(name='groupby') @Appender(_doc_template) - def resample(self, rule, *args, **kwargs): + def resample(self, rule, on=None, *args, **kwargs): """ Provide resampling when using a TimeGrouper Return a new grouper with our resampler appended """ from pandas.tseries.resample import get_resampler_for_grouping - return get_resampler_for_grouping(self, rule, *args, **kwargs) + return get_resampler_for_grouping(self, rule, key=on, *args, **kwargs) @Substitution(name='groupby') @Appender(_doc_template) diff --git a/pandas/tseries/tests/test_resample.py b/pandas/tseries/tests/test_resample.py index 56953541265a6..193dec44c0d7e 100755 --- a/pandas/tseries/tests/test_resample.py +++ b/pandas/tseries/tests/test_resample.py @@ -217,6 +217,20 @@ def test_groupby_resample_api(self): lambda x: x.resample('1D').ffill())[['val']] assert_frame_equal(result, expected) + def test_grouby_resample_on_api(self): + + # GH 15021 + # .groupby(...).resample(on=...) results in an unexpected + # keyword warning. + df = pd.DataFrame({'key': ['A', 'B'] * 5, + 'dates': pd.date_range('2016-01-01', periods=10), + 'values': np.random.randn(10)}) + + expected = df.set_index('dates').groupby('key').resample('D').mean() + + result = df.groupby('key').resample('D', on='dates').mean() + assert_frame_equal(result, expected) + def test_plot_api(self): tm._skip_if_no_mpl()