Skip to content

Wrong list of coordinate when a singleton coordinate exists #6196

Open
@lanougue

Description

@lanougue

What happened?

Here is some simple code:

a = xr.DataArray(np.arange(5), dims='x', coords={'x':np.arange(5)})
a = a.assign_coords({'y':1})

Now calling a['x'] or a['x'].coords shows y as a coordinate of x, which is unexpected for me

What did you expect to happen?

I expect that a singleton coordinate of a dataset not to be a coordinate of other coordinates present in the dataset

Minimal Complete Verifiable Example

import xarray as xr
import numpy as np
a = xr.DataArray(np.arange(5), dims='x', coords={'x':np.arange(5)})
a = a.assign_coords({'y':1})
print(a['x'].coords)

returns

Coordinates:
  * x        (x) int64 0 1 2 3 4
    y        int64 1

Relevant log output

No response

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS

commit: None
python: 3.8.12 | packaged by conda-forge | (default, Oct 12 2021, 21:57:06)
[GCC 9.4.0]
python-bits: 64
OS: Linux
OS-release: 3.12.53-60.30-default
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.12.1
libnetcdf: 4.8.1

xarray: 0.19.0
pandas: 1.3.5
numpy: 1.20.3
scipy: 1.6.3
netCDF4: 1.5.8
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.5.1.1
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: 2021.10.0
distributed: 2021.10.0
matplotlib: 3.2.2
cartopy: None
seaborn: None
numbagg: None
pint: None
setuptools: 60.5.0
pip: 21.3.1
conda: None
pytest: None
IPython: 7.31.0
sphinx: None

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