-
-
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
The Dataset.rename_dims creates a new dimension without coordinates #6867
Comments
Hi @ZhaJiMan, this topic has been brought up several times recently (see, e.g., #4825, #6607, #6704). I can't tell much about your latitude / longitude case without a more detailed example, but looking at your simple case the result is the one I would expect, i.e., Note that with version 2022.6.0, the renamed = ds.rename_dims(space='label'))
renamed
# <xarray.Dataset>
# Dimensions: (label: 3)
# Coordinates:
# * space (label) <U1 'a' 'b' 'c'
# Dimensions without coordinates: label
# Data variables:
# x (label) int64 1 2 3
renamed.sel(space="a")
# <xarray.Dataset>
# Dimensions: ()
# Coordinates:
# space <U1 'a'
# Data variables:
# x int64 1 Given that we can now use non-dimension coordinates for data selection, we should probably remove the "Dimensions without coordinates: label" in the repr for such case, as it becomes rather confusing. We should probably change that line to something like "Dimensions without index" or "Dimensions without indexed coordinates" or address that in the indexes repr section (#6795). |
Thanks for detailed explanation and informing of changes in recent versions. Although this behaviour still confuses me a lot, I'll take some time reading those mentioned issues. |
What is your issue?
The documentation says
Dataset.rename_dims
will returns a new object with renamed dimensions only. In my work I am intended to rename the longitude and latitude dimensions:ds = ds.rename_dims(longitude='lon', latitude='lat')
. But it turned out that a new dimensionlon
was created with values from 0 to its length minus 1. Is this result the expected behaviour ofrename_dims
, or I misused this method?A simple case below:
The information of
ds
in repl isBut after
ds = ds.rename_dims(space='label')
space
became a non-coordinate dimension, andlabel
was created as a new dimension without coordinates.Environment:
numpy : 1.22.3
pandas : 1.4.2
xarray : 2022.3.0
The text was updated successfully, but these errors were encountered: