Skip to content

Confusing error (or lack thereof) when coordinate and variable share the same name #631

@anntzer

Description

@anntzer

It probably makes sense to prevent dataset to have variables sharing the names of coordinates (what would dataset.varname return?) but currently

Dataset({"a": DataArray(np.zeros((3, 4)), dims=["a", "b"],
                        coords={"a": list("xyz"), "b": list("xyzt")})})

fails with ValueError: an index variable must be defined with 1-dimensional data, and

Dataset({"a": DataArray(np.zeros(3), coords={"a": list("xyz")})})

actually creates an empty dataset using [0, 0, 0] as values for the a coordinate instead of x y z:

<xray.Dataset>
Dimensions:  (a: 3)
Coordinates:
  * a        (a) float64 0.0 0.0 0.0
Data variables:
    *empty*

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