Skip to content

Commit 01d3810

Browse files
authored
Update resample.py
Update to solve :- BUG: groupby then resample on column gives incorrect results if the index is out of order pandas-dev#59350
1 parent 9c8c685 commit 01d3810

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pandas/core/resample.py

+18
Original file line numberDiff line numberDiff line change
@@ -1617,6 +1617,24 @@ class DatetimeIndexResampler(Resampler):
16171617
def _resampler_for_grouping(self) -> type[DatetimeIndexResamplerGroupby]:
16181618
return DatetimeIndexResamplerGroupby
16191619

1620+
def _get_resampler_for_grouping(self, groupby, how, fill_method, limit, kind):
1621+
"""
1622+
Return a resampler for groupby object.
1623+
"""
1624+
self.groupby = groupby
1625+
self._on = getattr(groupby, 'on', None)
1626+
if self._on is not None:
1627+
groupby._selected_obj = groupby._selected_obj.reset_index(drop=True).set_index(self._on)
1628+
return self._get_resampler(how, fill_method, limit, kind)
1629+
1630+
def _get_resampler(self, how, fill_method, limit, kind):
1631+
"""
1632+
Return a resampler for non-groupby object.
1633+
"""
1634+
if self._on is not None:
1635+
self._selected_obj = self._selected_obj.reset_index(drop=True).set_index(self._on)
1636+
return super()._get_resampler(how, fill_method, limit, kind)
1637+
16201638
def _get_binner_for_time(self):
16211639
# this is how we are actually creating the bins
16221640
if isinstance(self.ax, PeriodIndex):

0 commit comments

Comments
 (0)