-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: resample by BusinessHour raises ValueError #16447
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
Conversation
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.
Just a couple style things, and then one question about CustomBusinessHour. Thanks!
pandas/tests/test_resample.py
Outdated
@@ -2564,6 +2564,22 @@ def test_upsample_daily_business_daily(self): | |||
expected = ts.asfreq('H', how='s').reindex(exp_rng) | |||
assert_series_equal(result, expected) | |||
|
|||
|
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.
May need to remove this like (try flake8 pandas/tests/test_resample.py
)
pandas/tests/test_resample.py
Outdated
@@ -2564,6 +2564,22 @@ def test_upsample_daily_business_daily(self): | |||
expected = ts.asfreq('H', how='s').reindex(exp_rng) | |||
assert_series_equal(result, expected) | |||
|
|||
|
|||
# GH12351 |
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.
This comment can go just below the def test_
expected_ts = Series(1, index=expected_rng) | ||
|
||
assert_series_equal(result, expected_ts) | ||
|
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.
Could you add a test against a CustomBusinessHour
(I've never used one, but can help figure it out if you need).
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.
I just added it. Please take a look if it's okay.
pandas/core/resample.py
Outdated
|
||
if not isinstance(offset, Tick): # and first.time() != last.time(): | ||
# GH12351 | ||
elif isinstance(offset, BusinessHour) or isinstance(offset, CustomBusinessHour): |
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.
this is pretty hacky (well it was a hack). anything more general to do here?
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.
The special casing of BusinessHour, or the two isinstance checks? The two checks could be replaced with
elif issubclass(type(offset), BusinessHourMixin):
...
but that still feels a bit hacky :)
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.
I replaced it with @TomAugspurger suggested.
New test looks good, seems to have some style errors though:
Just need to add one more space, so that block lines up vertically. Also can remove the extra blank line on 2593. |
Codecov Report
@@ Coverage Diff @@
## master #16447 +/- ##
=========================================
Coverage ? 90.42%
=========================================
Files ? 161
Lines ? 51025
Branches ? 0
=========================================
Hits ? 46138
Misses ? 4887
Partials ? 0
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #16447 +/- ##
==========================================
- Coverage 90.4% 90.4% -0.01%
==========================================
Files 161 161
Lines 51033 51035 +2
==========================================
Hits 46136 46136
- Misses 4897 4899 +2
Continue to review full report at Codecov.
|
Thanks, @TomAugspurger I just cleaned up you mention. ;) |
@@ -1271,8 +1272,11 @@ 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) | |||
|
|||
if not isinstance(offset, Tick): # and first.time() != last.time(): | |||
# GH12351 |
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.
not what I meant. This is not a general fix at all. This is the same as before. The question is what kind of offset needs to do this kind of rollback / normalization.
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.
got your point. so do we need to generalize the edges detection here?
# GH12351 | ||
rng = pd.date_range(start='2017-05-18 00:00:00', | ||
end='2017-05-19 23:00:00', | ||
freq='H') |
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.
these are asfreq tests, NOT resample tests.
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.
need some tests from the original issue.
if you want to try to generalize can have another look. |
closing. I think this needs a bit more generalization. If you want to continue, pls ping. |
I'd like to continue for this Oct. I have some time to do now. Where can I start with? re-open this issue? Would you guide me? @jreback |
can you rebase & move notes to 0.22.0 |
closing as stale, but if you'd like to keep working, ping and we can reopen |
git diff upstream/master --name-only -- '*.py' | flake8 --diff
I've been away from this issue for a long time. Just made this PR again at PyCon 2017. Sorry for a long absence.