Skip to content

Commit 354ffd9

Browse files
committed
BUG: Fix for resampler for grouping kwarg bug #13235
Fix for incorrect passing of kwargs to helper function when calling groupby().resample(..) with label keyword.
1 parent 8e2f70b commit 354ffd9

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

doc/source/whatsnew/v0.18.2.txt

+1
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,4 @@ Bug Fixes
177177
- Bug in ``Peirod`` and ``Series`` or ``Index`` comparison raises ``TypeError`` (:issue:`13200`)
178178
- Bug in ``pd.set_eng_float_format()`` that would prevent NaN's from formatting (:issue:`11981`)
179179
- Bug in ``groupby`` where ``apply`` returns different result depending on whether first result is ``None`` or not (:issue:`12824`)
180+
- Bug in ``groupby(..).resample(..)`` where the ``label`` keyword causes an error (:issue:`13235`)

pandas/tseries/resample.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -914,8 +914,7 @@ def get_resampler_for_grouping(groupby, rule, how=None, fill_method=None,
914914
return _maybe_process_deprecations(r,
915915
how=how,
916916
fill_method=fill_method,
917-
limit=limit,
918-
**kwargs)
917+
limit=limit)
919918

920919

921920
class TimeGrouper(Grouper):

pandas/tseries/tests/test_resample.py

+20
Original file line numberDiff line numberDiff line change
@@ -1732,6 +1732,26 @@ def test_resample_timegrouper(self):
17321732
result = df.groupby(pd.Grouper(freq='M', key='A')).count()
17331733
assert_frame_equal(result, expected)
17341734

1735+
def test_resample_groupby_with_label(self):
1736+
# GH 13235
1737+
index = date_range('2000-01-01', freq='2D', periods=5)
1738+
df = DataFrame(index=index,
1739+
data={'col0': [0, 0, 1, 1, 2], 'col1': [1, 1, 1, 1, 1]}
1740+
)
1741+
result = df.groupby('col0').resample('1W', label='left').sum()
1742+
1743+
mi = [np.array([0, 0, 1, 2]),
1744+
pd.to_datetime(np.array(['1999-12-26', '2000-01-02',
1745+
'2000-01-02', '2000-01-02'])
1746+
)
1747+
]
1748+
mindex = pd.MultiIndex.from_arrays(mi, names=['col0', None])
1749+
expected = DataFrame(data={'col0': [0, 0, 2, 2], 'col1': [1, 1, 2, 1]},
1750+
index=mindex
1751+
)
1752+
1753+
assert_frame_equal(result, expected)
1754+
17351755
def test_resample_nunique(self):
17361756

17371757
# GH 12352

0 commit comments

Comments
 (0)