-
-
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
propagate indexes in to_dataset, from_dataset #3519
Merged
Merged
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
97e44a2
Propagate indexes in _to_dataset, _from_dataset
dcherian 1c9373f
Make Indexes immutable again.
dcherian 3a28951
Fix DataArrayGroupby._combine.
dcherian b902f97
Don't create indexes by default.
dcherian 10e1f4d
fix to_dataset_Splt
dcherian 433ba71
undo groupby change
dcherian 1bffa83
ccomment
dcherian bba1840
Update xarray/core/indexes.py
dcherian aefa5e3
Bad idea to deep copy indexes.
dcherian 747962d
Merge remote-tracking branch 'upstream/master' into indexes/dataarray
dcherian e97a1b2
Merge branch 'indexes/dataarray' of github.com:dcherian/xarray into i…
dcherian 6ae75c0
remove unnecessary copy_indexes calls.
dcherian 73e8e12
copy_indexes → propagate_indexes
dcherian d7cab03
more renaming.
dcherian 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 |
---|---|---|
|
@@ -5,11 +5,12 @@ | |
import pandas as pd | ||
|
||
from . import formatting | ||
from .utils import is_scalar | ||
from .variable import Variable | ||
|
||
|
||
class Indexes(collections.abc.Mapping): | ||
"""Immutable proxy for Dataset or DataArrary indexes.""" | ||
"""Mutable proxy for Dataset or DataArrary indexes.""" | ||
dcherian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
__slots__ = ("_indexes",) | ||
|
||
|
@@ -35,9 +36,6 @@ def __contains__(self, key): | |
def __getitem__(self, key): | ||
return self._indexes[key] | ||
|
||
def __delitem__(self, key): | ||
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. undoes my previous change. I think I understand the indexes model better now. We only use |
||
del self._indexes[key] | ||
|
||
def __repr__(self): | ||
return formatting.indexes_repr(self) | ||
|
||
|
@@ -100,3 +98,24 @@ def roll_index(index: pd.Index, count: int, axis: int = 0) -> pd.Index: | |
return index[-count:].append(index[:-count]) | ||
else: | ||
return index[:] | ||
|
||
|
||
def copy_indexes( | ||
dcherian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
indexes: Optional[Dict[Hashable, pd.Index]], | ||
deep: bool = True, | ||
exclude: Optional[Any] = None, | ||
) -> Optional[Dict[Hashable, pd.Index]]: | ||
if exclude is None: | ||
exclude = () | ||
|
||
if is_scalar(exclude): | ||
exclude = (exclude,) | ||
|
||
if indexes is not None: | ||
new_indexes = { | ||
k: v.copy(deep=deep) for k, v in indexes.items() if k not in exclude | ||
} | ||
else: | ||
new_indexes = None # type: ignore | ||
|
||
return new_indexes |
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
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 realize this isn't part of this PR, so maybe for another day; does calling
_from_vars_and_coord_names
do anything different from calling_construct_direct
?