Skip to content

Commit 83a15af

Browse files
committed
ENH: Added functionality in resample to resolve #10530
Added tests for updated resample function Changed if-statement to be lower-bound inclusive Undid previous change to if statement Fixed typo in resample.py Fixed typo in _get_time_bins Updated _resample_timestamp function Updated condition in if-statement Updated exceptions raised in resample Moved test case into proper file Fixed typo in test case Updated tests for resampling fix ENH: Updated code for fixing #10530 Removed extraneous print statements from tests Moved code for fix to _get_time_delta_bins function Updated tests for resample TimeDeltaIndex with base Updated code for resample TimeDeltaIndex with base Removed print statements from test case Removed print statement in tests Added note to what's new Removed extra whitespace Removed addtional whitespace Removed whitespace Removed whitespace in resample.py Removed more whitespace in resample.py Removed more whitespace Fixed syntax in what's new
1 parent 25be2f2 commit 83a15af

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

doc/source/whatsnew/v0.17.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ Other enhancements
9494

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

97+
- Added functionality to use ``base`` when resampling a ``TimeDeltaIndex`` (:issue:`10530`)
98+
9799
- ``DatetimeIndex`` can be instantiated using strings contains ``NaT`` (:issue:`7599`)
98100
- The string parsing of ``to_datetime``, ``Timestamp`` and ``DatetimeIndex`` has been made consistent. (:issue:`7599`)
99101

pandas/tseries/resample.py

+4
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ def _get_time_delta_bins(self, ax):
238238
end_stamps = labels + 1
239239
bins = ax.searchsorted(end_stamps, side='left')
240240

241+
# Addresses GH #10530
242+
if self.base > 0:
243+
labels += type(self.freq)(self.base)
244+
241245
return binner, bins, labels
242246

243247
def _get_time_period_bins(self, ax):

pandas/tseries/tests/test_resample.py

+14
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from pandas.core.groupby import DataError
1313
from pandas.tseries.index import date_range
14+
from pandas.tseries.tdi import timedelta_range
1415
from pandas.tseries.offsets import Minute, BDay
1516
from pandas.tseries.period import period_range, PeriodIndex, Period
1617
from pandas.tseries.resample import DatetimeIndex, TimeGrouper
@@ -627,6 +628,19 @@ def test_resample_base(self):
627628
freq='5min')
628629
self.assertTrue(resampled.index.equals(exp_rng))
629630

631+
def test_resample_base_with_timedeltaindex(self):
632+
rng = timedelta_range(start = '0s', periods = 25, freq = 's')
633+
ts = Series(np.random.randn(len(rng)), index = rng)
634+
635+
with_base = ts.resample('2s', base = 5)
636+
without_base = ts.resample('2s')
637+
638+
exp_without_base = timedelta_range(start = '0s', end = '25s', freq = '2s')
639+
exp_with_base = timedelta_range(start = '5s', end = '29s', freq = '2s')
640+
641+
self.assertTrue(without_base.index.equals(exp_without_base))
642+
self.assertTrue(with_base.index.equals(exp_with_base))
643+
630644
def test_resample_daily_anchored(self):
631645
rng = date_range('1/1/2000 0:00:00', periods=10000, freq='T')
632646
ts = Series(np.random.randn(len(rng)), index=rng)

0 commit comments

Comments
 (0)