Open jfpiolle opened 5 days ago
I think there is a bug when renaming axis dimensions and variables.
loading a file having the following coordinates:
import xarray as xr ds = xr.open_dataset('model_test.nc') print(ds.coords) Coordinates: * longitude (longitude) float32 -180.0 -179.5 -179.0 ... 178.5 179.0 179.5 * latitude (latitude) float32 -78.0 -77.5 -77.0 -76.5 ... 79.0 79.5 80.0 time datetime64[ns] ...
I want to rename these axes as lat and lon (for the sake of consistency between different datasets):
lat
lon
ds = ds.rename_vars({'longitude': 'lon', 'latitude': 'lat'}).swap_dims({'longitude': 'lon', 'latitude': 'lat'}) print(ds.coords)
which returns:
Coordinates: * lon (lon) float32 -180.0 -179.5 -179.0 -178.5 ... 178.5 179.0 179.5 * lat (lat) float32 -78.0 -77.5 -77.0 -76.5 -76.0 ... 78.5 79.0 79.5 80.0 time datetime64[ns] ...
so far, everything is fine. Now I want to do a shallow copy of this dataset:
ds2 = ds.copy(deep=False) print(ds2.coords)
which prints:
Coordinates: * lon (longitude) float32 -180.0 -179.5 -179.0 ... 178.5 179.0 179.5 * lat (latitude) float32 -78.0 -77.5 -77.0 -76.5 ... 78.5 79.0 79.5 80.0 time datetime64[ns] ...
the lat / lon dimensions are now renamed as in the initial version (latitude/longitude)!
latitude
longitude
I attached below the input file I used.
test_model.nc.gz
I was expecting to have the dim and coord names as the dataset I copied.
No response
Does a simple rename work for you instead of rename_vars + swap_dims? swap_dims is a bit broken at the moment.
rename
rename_vars + swap_dims
Possibly a dupe of https://github.com/pydata/xarray/issues/8646
What happened?
I think there is a bug when renaming axis dimensions and variables.
loading a file having the following coordinates:
I want to rename these axes as
lat
andlon
(for the sake of consistency between different datasets):which returns:
so far, everything is fine. Now I want to do a shallow copy of this dataset:
which prints:
the
lat
/lon
dimensions are now renamed as in the initial version (latitude
/longitude
)!I attached below the input file I used.
test_model.nc.gz
What did you expect to happen?
I was expecting to have the dim and coord names as the dataset I copied.
Minimal Complete Verifiable Example
No response
MVCE confirmation
Relevant log output
No response
Anything else we need to know?
No response
Environment