Skip to content

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

Closed
wants to merge 2 commits into from

Conversation

scari
Copy link
Contributor

@scari scari commented May 23, 2017

I've been away from this issue for a long time. Just made this PR again at PyCon 2017. Sorry for a long absence.

Copy link
Contributor

@TomAugspurger TomAugspurger left a 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!

@@ -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)


Copy link
Contributor

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)

@@ -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
Copy link
Contributor

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)

Copy link
Contributor

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).

Copy link
Contributor Author

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.

@TomAugspurger TomAugspurger added the Resample resample method label May 23, 2017
@TomAugspurger TomAugspurger added this to the 0.21.0 milestone May 23, 2017

if not isinstance(offset, Tick): # and first.time() != last.time():
# GH12351
elif isinstance(offset, BusinessHour) or isinstance(offset, CustomBusinessHour):
Copy link
Contributor

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?

Copy link
Contributor

@TomAugspurger TomAugspurger May 23, 2017

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 :)

Copy link
Contributor Author

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.

@TomAugspurger
Copy link
Contributor

New test looks good, seems to have some style errors though:

pandas/tests/test_resample.py:2573:37: E128 continuation line under-indented for visual indent
pandas/tests/test_resample.py:2574:37: E128 continuation line under-indented for visual indent
pandas/tests/test_resample.py:2589:37: E128 continuation line under-indented for visual indent
pandas/tests/test_resample.py:2590:37: E128 continuation line under-indented for visual indent
pandas/tests/test_resample.py:2593:9: E303 too many blank lines (2)

Just need to add one more space, so that block lines up vertically. Also can remove the extra blank line on 2593.

@codecov
Copy link

codecov bot commented May 23, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@04356a8). Click here to learn what that means.
The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #16447   +/-   ##
=========================================
  Coverage          ?   90.42%           
=========================================
  Files             ?      161           
  Lines             ?    51025           
  Branches          ?        0           
=========================================
  Hits              ?    46138           
  Misses            ?     4887           
  Partials          ?        0
Flag Coverage Δ
#multiple 88.26% <50%> (?)
#single 40.17% <25%> (?)
Impacted Files Coverage Δ
pandas/core/resample.py 95.75% <50%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 04356a8...f355763. Read the comment docs.

@codecov
Copy link

codecov bot commented May 23, 2017

Codecov Report

Merging #16447 into master will decrease coverage by <.01%.
The diff coverage is 50%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 88.23% <50%> (-0.01%) ⬇️
#single 40.17% <25%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/resample.py 95.75% <50%> (-0.33%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 97ad3fb...6f03530. Read the comment docs.

@scari
Copy link
Contributor Author

scari commented May 23, 2017

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
Copy link
Contributor

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.

Copy link
Contributor Author

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')
Copy link
Contributor

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.

Copy link
Contributor

@jreback jreback left a 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.

@jreback
Copy link
Contributor

jreback commented Aug 17, 2017

if you want to try to generalize can have another look.

@jreback jreback removed this from the 0.21.0 milestone Aug 17, 2017
@jreback
Copy link
Contributor

jreback commented Sep 23, 2017

closing. I think this needs a bit more generalization. If you want to continue, pls ping.

@jreback jreback closed this Sep 23, 2017
@scari
Copy link
Contributor Author

scari commented Oct 10, 2017

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

@jreback
Copy link
Contributor

jreback commented Nov 12, 2017

can you rebase & move notes to 0.22.0

@jreback
Copy link
Contributor

jreback commented Dec 10, 2017

closing as stale, but if you'd like to keep working, ping and we can reopen

@jreback jreback closed this Dec 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resample resample method
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: resample by BusinessHour raises ValueError
3 participants