xarray icon indicating copy to clipboard operation
xarray copied to clipboard

Roundtrip serialization of coordinate variables with spaces in their names

Open shoyer opened this issue 6 years ago • 5 comments

If coordinates have spaces in their names, they get restored from netCDF files as data variables instead:

>>> xarray.open_dataset(xarray.Dataset(coords={'name with spaces': 1}).to_netcdf())
<xarray.Dataset>
Dimensions:           ()
Data variables:
    name with spaces  int32 1

This happens because the CF convention is to indicate coordinates as a space separated string, e.g., coordinates='latitude longitude'.

Even though these aren't CF compliant variable names (which cannot have strings) It would be nice to have an ad-hoc convention for xarray that allows us to serialize/deserialize coordinates in all/most cases. Maybe we could use escape characters for spaces (e.g., coordinates='name\ with\ spaces') or quote names if they have spaces (e.g., coordinates='"name\ with\ spaces"'?

At the very least, we should issue a warning in these cases.

shoyer avatar Nov 03 '17 16:11 shoyer