Skip to content

BUG: resample with TimedeltaIndex, fenceposts are off #22488

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

Merged
merged 2 commits into from
Sep 5, 2018

Conversation

discort
Copy link
Contributor

@discort discort commented Aug 23, 2018

# GH 13022
index = pd.timedelta_range('00:00:00', '00:10:00', freq='5T')
df = DataFrame(data=[[1, 3], [-5, 10], [0, 0]], index=index)
result = df.resample('1T').asfreq()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, could you construct the expected frame and use tm.assert_frame_equal?

@mroeschke
Copy link
Member

mroeschke commented Aug 23, 2018

Could you also add a downsampling test case as noted here:

#13022 (comment)

@mroeschke mroeschke added Timedelta Timedelta data type Resample resample method labels Aug 23, 2018
@discort
Copy link
Contributor Author

discort commented Aug 24, 2018

@mroeschke

There is test TestTimedeltaIndex.test_asfreq that exactly reproduces mentioned comment and it's passing.

@codecov
Copy link

codecov bot commented Aug 29, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@a5fe9cf). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #22488   +/-   ##
=========================================
  Coverage          ?   92.04%           
=========================================
  Files             ?      169           
  Lines             ?    50782           
  Branches          ?        0           
=========================================
  Hits              ?    46741           
  Misses            ?     4041           
  Partials          ?        0
Flag Coverage Δ
#multiple 90.45% <ø> (?)
#single 42.3% <ø> (?)
Impacted Files Coverage Δ
pandas/core/resample.py 96.27% <ø> (ø)

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 a5fe9cf...bd8f31a. Read the comment docs.

else:
new_index = self.create_index(obj.index[0], obj.index[-1],
freq=freq)
new_index = self.create_index(obj.index[0], obj.index[-1], freq=freq)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mroeschke

The case noted here is covered by this test. However, it used to produce the incorrect index so tests were passing (which is incorrect). Here is the old expected index for TDI:

In [1]: obj.index.take(np.arange(0, len(obj.index), 2))
Out[1]: TimedeltaIndex(['1 days', '3 days', '5 days', '7 days', '9 days'], dtype='timedelta64[ns]', freq='2D')

def test_resample_as_freq_with_subperiod(self):
# GH 13022
index = timedelta_range('00:00:00', '00:10:00', freq='5T')
df = DataFrame(data={'value': [1, 5, 10]}, index=index)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add the other example in the OP here as well (or is it too duplicative)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jreback

The other example is duplicative of TestTimedeltaIndex.test_asfreq test. Should I add it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, no that is fine

@@ -1156,16 +1156,6 @@ def _get_binner_for_time(self):

def _adjust_binner_for_upsample(self, binner):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment here (and maybe refresh the comment in same method for DTI resampling)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jreback

Could you please clarify how I should refresh the comment for DTI? What should be instead of adjust our binner when upsampling?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment on why we are NOT adjusting anything here for TDI (e.g. just returning it directly). basically explain why DTI but not TDI needs adjustment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a reminder: here is why we adjust a binner #10885

@mroeschke
Copy link
Member

Travis flagged a linting error: pandas/tests/test_resample.py:29:1: F401 'pandas.tseries.frequencies.to_offset' imported but unused

@jreback jreback added this to the 0.24.0 milestone Sep 4, 2018
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.

pls rebase and tiny comment

binner = binner[1:]
else:
binner = binner[:-1]
# Just returning binner directly, GH 13022
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a bit more text here, e.g. the reason why this is true

@discort
Copy link
Contributor Author

discort commented Sep 4, 2018

@jreback

@pep8speaks
Copy link

Hello @discort! Thanks for updating the PR.

@jreback jreback merged commit f82c10a into pandas-dev:master Sep 5, 2018
@jreback
Copy link
Contributor

jreback commented Sep 5, 2018

thanks @discort

rhysparry added a commit to rhysparry/pandas that referenced this pull request Sep 5, 2018
* master:
  DOC: Update link and description of the Spyder IDE in Ecosystem docs (pandas-dev#22136)
  BUG: resample with TimedeltaIndex, fenceposts are off (pandas-dev#22488)
  Use dispatch_to_series where possible (pandas-dev#22572)
  BLD: Fix openpyxl to 2.5.5 (pandas-dev#22601)
aeltanawy pushed a commit to aeltanawy/pandas that referenced this pull request Sep 20, 2018
Sup3rGeo pushed a commit to Sup3rGeo/pandas that referenced this pull request Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resample resample method Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: resample with TimedeltaIndex, fenceposts are off
4 participants