-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: resample by BusinessHour raises ValueError #13364
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,8 @@ | |
from pandas.tseries.frequencies import to_offset, is_subperiod, is_superperiod | ||
from pandas.tseries.index import DatetimeIndex, date_range | ||
from pandas.tseries.tdi import TimedeltaIndex | ||
from pandas.tseries.offsets import DateOffset, Tick, Day, _delta_to_nanoseconds | ||
from pandas.tseries.offsets import (DateOffset, Tick, Day, BusinessHour, | ||
_delta_to_nanoseconds) | ||
from pandas.tseries.period import PeriodIndex, period_range | ||
import pandas.core.common as com | ||
import pandas.core.algorithms as algos | ||
|
@@ -1213,8 +1214,13 @@ def _get_range_edges(first, last, offset, closed='left', base=0): | |
if (is_day and day_nanos % offset.nanos == 0) or not is_day: | ||
return _adjust_dates_anchored(first, last, offset, | ||
closed=closed, base=base) | ||
elif isinstance(offset, BusinessHour): | ||
# GH12351 - normalize BH freq leads ValueError | ||
first = Timestamp(offset.rollback(first)) | ||
last = Timestamp(offset.rollforward(last + offset)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't |
||
return first, last | ||
|
||
if not isinstance(offset, Tick): # and first.time() != last.time(): | ||
else: # and first.time() != last.time(): | ||
# hack! | ||
first = first.normalize() | ||
last = last.normalize() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2297,6 +2297,17 @@ def test_upsample_daily_business_daily(self): | |
expected = ts.asfreq('H', how='s').reindex(exp_rng) | ||
assert_series_equal(result, expected) | ||
|
||
def test_resample_hourly_business_hourly(self): | ||
ts = pd.Series(index=pd.date_range(start='2016-06-01 03:00:00', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add the issue number here as a comment |
||
end='2016-06-03 23:00:00', | ||
freq='H')) | ||
expected = pd.Series(index=pd.date_range(start='2016-05-31 17:00:00', | ||
end='2016-06-06 09:00:00', | ||
freq='BH')) | ||
|
||
result = ts.resample('BH').mean() | ||
assert_series_equal(result, expected) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure this is right. shouldn't the result have BH freq? |
||
|
||
def test_resample_irregular_sparse(self): | ||
dr = date_range(start='1/1/2012', freq='5min', periods=1000) | ||
s = Series(np.array(100), index=dr) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can u check
CustomBusinessHour
can be supported by the same logic?