Description
This arose as part of #3352. Xarray has important-to-understand name-matching rules for whether or not a coordinate array is a dimension coordinate or a non-dimension coordinate. To my knowledge, this is not in the documentation anywhere.
This is what I had, but we decided to remove it since it was overly complicated for a list of key terms; maybe it'll be helpful going forward:
Name matching rules: Xarray follows simple but important-to-understand name matching rules for dimensions and coordinates. Let
arr
be an array with an existing dimensionx
and assigned new coordinatesnew_coords
. Ifnew_coords
is a list-like for e.g.[1, 2, 3]
then they must be assigned a name that matches an existing dimension. For example, ifarr.assign_coords({'x': [1, 2, 3]}).
However, if
new_coords
is a one-dimensionalDataArray
, then the rules are slightly more complex. In this case, if bothnew_coords
's name and only dimension match any dimension name inarr.dims
, it is assigned as a dimension coordinate toarr
. Ifnew_coords
's name matches a name inarr.dims
but its own dimension name does not, it is assigned as a non-dimension coordinate with namenew_coords.dims[0]
toarr
. Otherwise, an exception is raised.