Help deciphering code for swap_dims in dataset.py #7510
Unanswered
DanielAdriaansen
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I was working on some code dealing with dimension names. Here is a toy example:
In this case, I know that
y0
=y1
, and so I want to simply "swap"y1
, withy0
everywhere. Something like:ds.swap_dims({'y1':'y0'}).drop_vars(['y1'])
So to start, using 2023.1.0, I tried this:
So instead, I tried this:
If I look at
dataset.py", line 3559, in swap_dims
, I see this code:If I simply comment out that second if block, then
ds.swap_dims()
works for my case. I was hoping someone could help me understand the situation or case that the second if block here:is trying to catch or handle? I don't understand what the
ValueError
is trying to tell me nor do I follow the if statement. I'd like to try and improve the code so that my case ofds.swap_dims()
works but don't want to simply remove code because presumably it's designed to catch something I am not thinking of.On the other hand, I am aware there seems to be a push toward deprecating
swap_dims()
(#2838), but I would argue that there is a case for each:swap_dims
--> swap one existing dimension with another existing dimensionrename_dims
--> rename an existing dimension with a new name that does not already existThanks in advance for any help!
Beta Was this translation helpful? Give feedback.
All reactions