-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add rename_vars and rename_dims #3045
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
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
65e3769
Added rename_coords and rename_dims
jukent 4eaeaf5
Removed white space from blank lines
jukent 69c074e
Changed rename_coords to rename_vars
jukent 7cd26ce
Changed rename_coords to rename_vars in "See Also" or rename fx
jukent bc6d90b
Fixed renaming dimension indexing
jukent babf193
Added testing for rename_vars and rename_dims
jukent e74330b
Merge branch 'master' of github.com:jukent/xarray
jukent 588f9c8
Testing and fx for renaming vars and dims
jukent 7505883
Met pep8 standards
jukent 9215908
Undid autopep8 for lines w noqa
jukent 8753345
Update xarray/tests/test_dataset.py
jukent b790160
Cleaned up helper fxs and added actual_2 test
jukent 50242b3
Merge branch 'master' of github.com:jukent/xarray
jukent ae0deb1
Update xarray/core/dataset.py
jukent cf28dde
Update xarray/core/dataset.py
jukent a73390d
deleted misc file
jukent a0d4ca1
Update xarray/core/dataset.py
jukent 6ffdc4c
fixed conflicts
jukent 1494237
Merge branch 'master' of github.com:jukent/xarray
jukent bdfd181
_rename_var_dims_helper undefined test
jukent a77820c
Use separate rename_dims and rename_vars dictionaries
jukent c19ddb3
Fixed documentation and added inplace back
jukent ef5cc66
removing changes from rename
jukent 1a08c51
removed test set up to fail (will add back)
jukent 97c4e85
fixed coord vs variable in test rename_
jukent 4e2bc76
Merge branch 'master' into master
jukent caad102
Moved rename_var to under new fx/methods
jukent 09c801a
Update whats-new.rst
dcherian f4e1479
use pytest.raises to test for ValueError
jukent c97ff0d
did not assign failed
jukent b3232ad
pep8 compliance
jukent 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -2163,6 +2163,40 @@ def test_rename_inplace(self): | |
# check virtual variables | ||
assert_array_equal(data['t.dayofyear'], [1, 2, 3]) | ||
|
||
def test_rename_dims(self): | ||
original = Dataset( | ||
{'x': ('x', [0, 1, 2]), 'y': ('x', [10, 11, 12]), 'z': 42}) | ||
expected = Dataset( | ||
{'x': ('x_new', [0, 1, 2]), 'y': ('x_new', [10, 11, 12]), 'z': 42}) | ||
expected = expected.set_coords('x') | ||
dims_dict = {'x': 'x_new'} | ||
actual = original.rename_dims(dims_dict) | ||
assert_identical(expected, actual) | ||
dcherian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
actual_2 = original.rename_dims(**dims_dict) | ||
assert_identical(expected, actual_2) | ||
|
||
# Test to raise ValueError | ||
dims_dict_bad = {'x_bad': 'x_new'} | ||
with pytest.raises(ValueError): | ||
original.rename_dims(dims_dict_bad) | ||
|
||
def test_rename_vars(self): | ||
original = Dataset( | ||
{'x': ('x', [0, 1, 2]), 'y': ('x', [10, 11, 12]), 'z': 42}) | ||
expected = Dataset( | ||
{'x_new': ('x', [0, 1, 2]), 'y': ('x', [10, 11, 12]), 'z': 42}) | ||
expected = expected.set_coords('x_new') | ||
name_dict = {'x': 'x_new'} | ||
actual = original.rename_vars(name_dict) | ||
dcherian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert_identical(expected, actual) | ||
dcherian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
actual_2 = original.rename_vars(**name_dict) | ||
assert_identical(expected, actual_2) | ||
|
||
# Test to raise ValueError | ||
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. For future reference, try to leave out redundant comments like this that literally describe how code works. If it would be just as clear to read the code directly, it's best to let code stand on its own. |
||
names_dict_bad = {'x_bad': 'x_new'} | ||
with pytest.raises(ValueError): | ||
original.rename_vars(names_dict_bad) | ||
|
||
def test_swap_dims(self): | ||
original = Dataset({'x': [1, 2, 3], 'y': ('x', list('abc')), 'z': 42}) | ||
expected = Dataset({'z': 42}, | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.