Skip to content

BUG: resample with tz-aware: Values falls after last bin #15555

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 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pandas/tests/tseries/test_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -2670,6 +2670,11 @@ def test_resample_weekly_bug_1726(self):
# it works!
df.resample('W-MON', closed='left', label='left').first()

def test_resample_tz_aware_bug_15549(self):
index = pd.DatetimeIndex([1450137600000000000, 1474059600000000000], tz='UTC').tz_convert('America/Chicago')
Copy link
Contributor

Choose a reason for hiding this comment

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

this line is going to be too long for linting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

understood, I will change it

df = pd.DataFrame([1, 2], index=index)
df.resample('12h', closed='right', label='right').last().ffill()
Copy link
Contributor

Choose a reason for hiding this comment

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

result = df.resample(.......)
expected = ....
tm.assert_frame_equal(result, expected)

add a comment with the issue number as a comment (and not in the test name)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree, I will fix it. I just used the same notation as in the test above. thought it's a common thing


def test_resample_bms_2752(self):
# GH2753
foo = pd.Series(index=pd.bdate_range('20000101', '20000201'))
Expand Down
11 changes: 7 additions & 4 deletions pandas/tseries/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -1149,12 +1149,15 @@ def _get_time_bins(self, ax):
binner = labels = DatetimeIndex(
data=[], freq=self.freq, name=ax.name)
return binner, [], labels


tz = ax.tz
if tz:
ax = ax.tz_convert('UTC')

first, last = ax.min(), ax.max()
first, last = _get_range_edges(first, last, self.freq,
closed=self.closed,
base=self.base)
tz = ax.tz
# GH #12037
# use first/last directly instead of call replace() on them
# because replace() will swallow the nanosecond part
Expand All @@ -1163,8 +1166,8 @@ def _get_time_bins(self, ax):
binner = labels = DatetimeIndex(freq=self.freq,
start=first,
end=last,
tz=tz,
name=ax.name)
tz='UTC',
name=ax.name).tz_convert(tz)

# a little hack
trimmed = False
Expand Down