Skip to content

Roundtrip serialization of coordinate variables with spaces in their names #1689

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

Closed
shoyer opened this issue Nov 3, 2017 · 6 comments
Closed

Comments

@shoyer
Copy link
Member

shoyer commented Nov 3, 2017

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 shoyer changed the title Roundtripping coordinate variables with spaces in their names Roundtrip serialization of coordinate variables with spaces in their names Nov 4, 2017
@fmaussion
Copy link
Member

I would be in favour of issuing a warning only and discourage using spaces in variable names altogether.

@shoyer
Copy link
Member Author

shoyer commented Nov 8, 2017

I would be in favour of issuing a warning only and discourage using spaces in variable names altogether.

Even if we eventually implement this in some form, adding the warning would certainly be a good place to start.

@stale
Copy link

stale bot commented Oct 9, 2019

In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity

If this issue remains relevant, please comment here or remove the stale label; otherwise it will be marked as closed automatically

@stale stale bot added the stale label Oct 9, 2019
@crusaderky
Copy link
Contributor

Still valid in xarray 0.13, netcdf4-1.4.3.2

@stale stale bot removed the stale label Oct 10, 2019
@kmuehlbauer
Copy link
Contributor

Current state of affairs:

xr.open_dataset(xr.Dataset(coords={'name with spaces': 1}).to_netcdf())
SerializationWarning: coordinate 'name with spaces' has a space in its name, which means it cannot be marked as a coordinate on disk and will be saved as a data variable instead
  xr.open_dataset(xr.Dataset(coords={'name with spaces': 1}).to_netcdf())

Shall we close here or are there any actions which should be taken?

@kmuehlbauer
Copy link
Contributor

Please reopen, if still relevant.

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

No branches or pull requests

4 participants