Skip to content
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

swap_dims should support dimension names that are not existing variables #1855

Closed
shoyer opened this issue Jan 25, 2018 · 3 comments · Fixed by #3636
Closed

swap_dims should support dimension names that are not existing variables #1855

shoyer opened this issue Jan 25, 2018 · 3 comments · Fixed by #3636

Comments

@shoyer
Copy link
Member

shoyer commented Jan 25, 2018

Code Sample, a copy-pastable example if possible

input_ds = xarray.Dataset({'foo': ('x', [1, 2])}, {'x': [0, 1]})
input_ds.swap_dims({'x': 'z'})

Problem description

Currently this results in the error KeyError: 'z'

Expected Output

We now support dimensions without associated coordinate variables. So swap_dims() should be able to create new dimensions (e.g., z in this example) even if there isn't already a coordinate variable.

@dcherian
Copy link
Contributor

I think we already have this as ds.rename_dims?

@keewis
Copy link
Collaborator

keewis commented Dec 17, 2019

I think rename_dims does something different: it renames a dimension if the new name does not exist (if it exists, it does something strange, see #3438), while swap_dims creates a new dimension and moves the old dimension to coords (or data_vars?).

Edit: I don't have a strong opinion, though

@keewis
Copy link
Collaborator

keewis commented Dec 17, 2019

we should, however, clearly define the use cases of swap_dims and rename_dims. Right now, the docs are not really clear on the difference between them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants