Skip to content

ENH: Added functionality in resample to resolve #10530 #10543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.17.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ Other enhancements

- Enable `read_hdf` to be used without specifying a key when the HDF file contains a single dataset (:issue:`10443`)

- Added functionality to use ``base`` when resampling a ``TimeDeltaIndex`` (:issue:`10530`)

- ``DatetimeIndex`` can be instantiated using strings contains ``NaT`` (:issue:`7599`)
- The string parsing of ``to_datetime``, ``Timestamp`` and ``DatetimeIndex`` has been made consistent. (:issue:`7599`)

Expand Down
4 changes: 4 additions & 0 deletions pandas/tseries/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ def _get_time_delta_bins(self, ax):
end_stamps = labels + 1
bins = ax.searchsorted(end_stamps, side='left')

# Addresses GH #10530
if self.base > 0:
labels += type(self.freq)(self.base)

return binner, bins, labels

def _get_time_period_bins(self, ax):
Expand Down
14 changes: 14 additions & 0 deletions pandas/tseries/tests/test_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from pandas.core.groupby import DataError
from pandas.tseries.index import date_range
from pandas.tseries.tdi import timedelta_range
from pandas.tseries.offsets import Minute, BDay
from pandas.tseries.period import period_range, PeriodIndex, Period
from pandas.tseries.resample import DatetimeIndex, TimeGrouper
Expand Down Expand Up @@ -627,6 +628,19 @@ def test_resample_base(self):
freq='5min')
self.assertTrue(resampled.index.equals(exp_rng))

def test_resample_base_with_timedeltaindex(self):
rng = timedelta_range(start = '0s', periods = 25, freq = 's')
ts = Series(np.random.randn(len(rng)), index = rng)

with_base = ts.resample('2s', base = 5)
without_base = ts.resample('2s')

exp_without_base = timedelta_range(start = '0s', end = '25s', freq = '2s')
exp_with_base = timedelta_range(start = '5s', end = '29s', freq = '2s')

self.assertTrue(without_base.index.equals(exp_without_base))
self.assertTrue(with_base.index.equals(exp_with_base))

def test_resample_daily_anchored(self):
rng = date_range('1/1/2000 0:00:00', periods=10000, freq='T')
ts = Series(np.random.randn(len(rng)), index=rng)
Expand Down