-
-
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
Multiindex scalar coords, fixes #1408 #1412
Closed
Closed
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4876ee8
Make IndexVariable.__getitem__ return an OrderedDict of variables
fujiisoup 800a7d9
Still error in test_groupby, since it requres .isel() and concat for …
fujiisoup 3fac440
Added Groupby._maybe_stack.
fujiisoup df96d8d
Added small docstring.
fujiisoup 6db36a8
starting sel()
fujiisoup 0af9da2
Remove DataArray._replace_index and make use of Dataset._replace_index.
fujiisoup cdd839d
Add whatsnew
fujiisoup 42f4f2e
Remove unecessary `flatten` call.
fujiisoup 185abd0
Restore Variable.__getitem__ to return a Variable even if a signle el…
fujiisoup File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -362,6 +362,22 @@ def _maybe_unstack(self, obj): | |
del obj.coords[dim] | ||
return obj | ||
|
||
def _maybe_stack(self, applied): | ||
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 method becomes necessary, because now we cannot do |
||
""" | ||
This constructs MultiIndex if 'applied' does not have self._group_dim. | ||
It may happen if a single item is selected from MultiIndex-ed array. | ||
""" | ||
if not hasattr(self._group, 'to_index'): | ||
return applied | ||
index = self._group.to_index() | ||
if not isinstance(index, pd.MultiIndex): | ||
return applied | ||
else: | ||
return [ds if self._group_dim in ds.coords | ||
else ds.expand_dims(index.names).stack( | ||
**{self._group.name: index.names}) | ||
for ds in applied] | ||
|
||
def fillna(self, value): | ||
"""Fill missing values in this object by group. | ||
|
||
|
@@ -528,6 +544,7 @@ def _combine(self, applied, shortcut=False): | |
"""Recombine the applied objects like the original.""" | ||
applied_example, applied = peek_at(applied) | ||
coord, dim, positions = self._infer_concat_args(applied_example) | ||
applied = self._maybe_stack(applied) | ||
if shortcut: | ||
combined = self._concat_shortcut(applied, dim, positions) | ||
else: | ||
|
@@ -619,6 +636,7 @@ def apply(self, func, **kwargs): | |
def _combine(self, applied): | ||
"""Recombine the applied objects like the original.""" | ||
applied_example, applied = peek_at(applied) | ||
applied = self._maybe_stack(applied) | ||
coord, dim, positions = self._infer_concat_args(applied_example) | ||
combined = concat(applied, dim) | ||
combined = _maybe_reorder(combined, dim, positions) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I removed this method and use
Dataset._replace_indexes
instead, to reduce duplicates.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.
If I remember well, we used duplicates to avoid using
_to_temp_dataset
and_from_temp_dataset
in__getitem__
. But now that_replace_indexes
has more logic implemented, maybe it is a good idea to reduce duplicates?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.
Thanks.
Yes, in
DataArray.__getitem__
and also inDataAarray.isel
,_to_temp_dataset
and_from_temp_dataset
are now being used.