Skip to content

CLN: Resample time bin cruft #24347

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 1 commit into from
Dec 19, 2018
Merged
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
30 changes: 3 additions & 27 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,6 @@ def _get_time_bins(self, ax):
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 @@ -1402,29 +1401,11 @@ def _get_time_bins(self, ax):
binner = labels = date_range(freq=self.freq,
start=first,
end=last,
tz=tz,
tz=ax.tz,
name=ax.name,
ambiguous='infer',
nonexistent='shift')

# GH 15549
# In edge case of tz-aware resapmling binner last index can be
# less than the last variable in data object, this happens because of
# DST time change
if len(binner) > 1 and binner[-1] < last:
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
self.closed == 'right'):

binner = binner[:-1]
trimmed = True

ax_values = ax.asi8
binner, bin_edges = self._adjust_bin_edges(binner, ax_values)

Expand All @@ -1436,13 +1417,8 @@ def _get_time_bins(self, ax):
labels = binner
if self.label == 'right':
labels = labels[1:]
elif not trimmed:
labels = labels[:-1]
else:
if self.label == 'right':
labels = labels[1:]
elif not trimmed:
labels = labels[:-1]
elif self.label == 'right':
labels = labels[1:]

if ax.hasnans:
binner = binner.insert(0, NaT)
Expand Down