-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
!I fix for BUG: resample with tz-aware: Values falls after last bin #15549 #18337
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 30 commits
68a02aa
47b99ac
04ce929
a43bb19
44fc3f2
2a1d24c
d28ff98
7c770c0
effa650
aa8c0af
2db6576
2744ad3
fb4d405
93842d0
fc795c6
514fe24
777a12a
037c9dc
d5ac67e
61e84d6
e049112
e252b20
1888355
f4ed7c0
9b18f4b
5b035f0
0ec3bd0
b523915
a1b59c4
8cd36c9
aec765f
2e77f72
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 |
---|---|---|
|
@@ -1141,6 +1141,16 @@ def _get_time_bins(self, ax): | |
tz=tz, | ||
name=ax.name) | ||
|
||
# GH 15549 | ||
# In edge case of tz-aware resapmling binner last index can be | ||
# less than the last variable in data object. | ||
# This leads to `Values falls after last bin` error | ||
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. this last sentence is not relevant; you are fixing this! |
||
if len(binner) > 1 and binner[-1] < last: | ||
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. can you add a comment here on what is going on. |
||
extra_date_range = pd.date_range(binner[-1], last + self.freq, | ||
freq=self.freq, tz=tz, | ||
name=ax.name) | ||
binner = labels = binner.append(extra_date_range[1:]) | ||
|
||
# a little hack | ||
trimmed = False | ||
if (len(binner) > 2 and binner[-2] == last and | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2719,6 +2719,34 @@ def test_resample_weekly_bug_1726(self): | |
# it works! | ||
df.resample('W-MON', closed='left', label='left').first() | ||
|
||
def test_resample_tz_aware(self): | ||
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. be more explicit in the test name |
||
# GH 15549 | ||
index = pd.DatetimeIndex([1457537600000000000, 1458059600000000000], | ||
tz='UTC').tz_convert('America/Chicago') | ||
df = pd.DataFrame([1, 2], index=index) | ||
res_df = df.resample('12h', closed='right', | ||
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. call this result |
||
label='right').last().ffill() | ||
|
||
expected_index_values = ['2016-03-09 12:00:00-06:00', | ||
'2016-03-10 00:00:00-06:00', | ||
'2016-03-10 12:00:00-06:00', | ||
'2016-03-11 00:00:00-06:00', | ||
'2016-03-11 12:00:00-06:00', | ||
'2016-03-12 00:00:00-06:00', | ||
'2016-03-12 12:00:00-06:00', | ||
'2016-03-13 00:00:00-06:00', | ||
'2016-03-13 13:00:00-05:00', | ||
'2016-03-14 01:00:00-05:00', | ||
'2016-03-14 13:00:00-05:00', | ||
'2016-03-15 01:00:00-05:00', | ||
'2016-03-15 13:00:00-05:00'] | ||
index = pd.DatetimeIndex(expected_index_values, | ||
tz='UTC').tz_convert('America/Chicago') | ||
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. call this expected |
||
expected_df = pd.DataFrame([1.0, 1.0, 1.0, 1.0, 1.0, | ||
1.0, 1.0, 1.0, 1.0, 1.0, | ||
1.0, 1.0, 2.0], index=index) | ||
assert_frame_equal(res_df, expected_df) | ||
|
||
def test_resample_bms_2752(self): | ||
# GH2753 | ||
foo = Series(index=pd.bdate_range('20000101', '20000201')) | ||
|
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.
say DST 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.
sp on frequency