-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Series.resample fails on NaT index #39229
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 5 commits
93d1503
211b6a6
16236a0
43bf26f
f70b178
3a47781
b7fc830
9ea6b0c
252cc29
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 |
---|---|---|
|
@@ -454,7 +454,8 @@ def _wrap_result(self, result): | |
|
||
if isinstance(result, ABCSeries) and result.empty: | ||
obj = self.obj | ||
result.index = _asfreq_compat(obj.index, freq=self.freq) | ||
# When index is all NaT, result is empty but index is not | ||
result.index = _asfreq_compat(obj.index[:0], freq=self.freq) | ||
result.name = getattr(obj, "name", None) | ||
|
||
return result | ||
|
@@ -1653,10 +1654,17 @@ def _get_period_bins(self, ax: PeriodIndex): | |
nat_count = np.sum(memb._isnan) | ||
memb = memb[~memb._isnan] | ||
|
||
# if index contains no valid (non-NaT) values, return empty index | ||
if not len(memb): | ||
binner = labels = PeriodIndex(data=[], freq=self.freq, name=ax.name) | ||
return binner, [], labels | ||
if len(ax) == 0: | ||
# if index is empty, return empty bins | ||
data = [] | ||
bins = np.array([], dtype=np.int64) | ||
else: | ||
# if index is all NaT, return a single bin | ||
data = [NaT] | ||
bins = np.array([len(ax)]) | ||
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. wait why do we have NaT in an index? e.g. why don't we have 0 bins? 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. Below this is the logic for when there are
The added logic agrees with this in the case there are all NaT. 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. i c. can you unify this logic (maybe to a function)? |
||
binner = labels = PeriodIndex(data=data, freq=self.freq, name=ax.name) | ||
return binner, bins, labels | ||
|
||
freq_mult = self.freq.n | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.