Skip to content

custom "coordinates" attribute #3351

@dcherian

Description

@dcherian

This set of lines prevents users from writing files with a handcrafted coordinates attribute. This is useful when not all non-dimensional coordinates in a Dataset are appropriate for every data variable in a dataset.

# These coordinates are saved according to CF conventions
for var_name, coord_names in variable_coordinates.items():
attrs = variables[var_name].attrs
if "coordinates" in attrs:
raise ValueError(
"cannot serialize coordinates because variable "
"%s already has an attribute 'coordinates'" % var_name
)
attrs["coordinates"] = " ".join(map(str, coord_names))

It seems to me like we should only automatically set "coordinates" when "coordinates" not in attrs. We could raise a warning saying that setting attrs["coordinates"] prevents full roundtripping of Datasets.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions