-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
CFTimeIndex Resampling #2593
CFTimeIndex Resampling #2593
Changes from 66 commits
daa3a71
f9f3347
0950505
89f418a
39c9d11
073b8e0
193c4c4
2c97738
9993ed9
f01745c
ffbf265
e64fedb
2850dd5
770b778
181e82c
5a41ee2
6b948c5
97c0948
63d25ab
05af869
85f1a84
2e8ced3
4317c69
e7deeb2
f9ac1a1
8505ca9
a495c2d
ad65ef0
5775e11
e1902fe
f82500c
80914e0
1b3f41a
bc95f55
9fa4d51
5227480
77bb2aa
be2e657
a18161d
9582fbf
5737546
3268fc4
6f38935
e7986c5
c64265f
71f98db
ec4e460
47b0eaa
f2ecaf6
cd266c2
41783cb
5435910
35b40fb
814a04d
2a9402e
505a0fa
9fbb016
0820c3b
89bc708
31ccebf
8ac6f76
8dbee52
afad30d
1381dab
6074548
1010264
6c4b609
59f1f94
db62a96
6edb45a
f7f2c38
ef68960
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 |
---|---|---|
|
@@ -258,12 +258,8 @@ def __init__(self, obj, group, squeeze=False, grouper=None, bins=None, | |
if not index.is_monotonic: | ||
# TODO: sort instead of raising an error | ||
raise ValueError('index must be monotonic for resampling') | ||
s = pd.Series(np.arange(index.size), index) | ||
first_items = s.groupby(grouper).first() | ||
_apply_loffset(grouper, first_items) | ||
full_index = first_items.index | ||
if first_items.isnull().any(): | ||
first_items = first_items.dropna() | ||
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. It would be nice if 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. |
||
full_index, first_items = self._get_index_and_items( | ||
index, grouper) | ||
sbins = first_items.values.astype(np.int64) | ||
group_indices = ([slice(i, j) | ||
for i, j in zip(sbins[:-1], sbins[1:])] + | ||
|
@@ -310,6 +306,27 @@ def __len__(self): | |
def __iter__(self): | ||
return zip(self._unique_coord.values, self._iter_grouped()) | ||
|
||
def _get_index_and_items(self, index, grouper): | ||
from .resample_cftime import CFTimeGrouper | ||
s = pd.Series(np.arange(index.size), index) | ||
if isinstance(grouper, CFTimeGrouper): | ||
first_items = grouper.first_items(index) | ||
full_index = first_items.index | ||
if first_items.isnull().any(): | ||
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. if you merge in master against, you could switch this block back to using 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. Done. |
||
index_dict = dict(zip(np.arange(first_items.size), | ||
first_items.index.values)) | ||
first_items.index = np.arange(first_items.size) | ||
first_items = first_items.dropna() | ||
first_items.index = [index_dict[i] for i in | ||
first_items.index.values] | ||
else: | ||
first_items = s.groupby(grouper).first() | ||
_apply_loffset(grouper, first_items) | ||
full_index = first_items.index | ||
if first_items.isnull().any(): | ||
first_items = first_items.dropna() | ||
return full_index, first_items | ||
|
||
def _iter_grouped(self): | ||
"""Iterate over each element in this group""" | ||
for indices in self._group_indices: | ||
|
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.
The example below is not super-relevant now. Maybe delete:
as well as the line that calls
resample
at the end of the code block?