-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
The documentation states:
coords...
...
Additionally, it is possible to define a coord whose name does not match the dimension name, or a coord based on multiple dimensions, with one of the following notations:
- mapping {coord name: DataArray}
- mapping {coord name: Variable}
- mapping {coord name: (dimension name, array-like)}
- mapping {coord name: (tuple of dimension names, array-like)}
dims (hashable or sequence of hashable, optional) – Name(s) of the data dimension(s). Must be either a hashable (only for 1D data) or a sequence of hashables with length equal to the number of dimensions. If this argument is omitted, dimension names are taken from coords (if possible) and otherwise default to ['dim_0', ... 'dim_n'].
Which seems to be no longer the case.
MCVE Code Sample
da = xr.DataArray(np.zeros((2, 2)), coords={'x': [1, 2], 'y': [1, 2]})
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-22-0d63eed9a72f> in <module>
----> 1 da = xr.DataArray(np.zeros((2, 2)), coords={'x': [1, 2], 'y': [1, 2]})
/scratch/local/lib/python3.8/site-packages/xarray/core/dataarray.py in __init__(self, data, coords, dims, name, attrs, encoding, indexes, fastpath)
366 data = _check_data_shape(data, coords, dims)
367 data = as_compatible_data(data)
--> 368 coords, dims = _infer_coords_and_dims(data.shape, coords, dims)
369 variable = Variable(dims, data, attrs, encoding, fastpath=True)
370
/scratch/local/lib/python3.8/site-packages/xarray/core/dataarray.py in _infer_coords_and_dims(shape, coords, dims)
105 if utils.is_dict_like(coords):
106 # deprecated in GH993, removed in GH1539
--> 107 raise ValueError(
108 "inferring DataArray dimensions from "
109 "dictionary like ``coords`` is no longer "
ValueError: inferring DataArray dimensions from dictionary like ``coords`` is no longer supported. Use an explicit list of ``dims`` instead.
Expected Output
An update of the documentation to correctly specify the current behavior. (I'll propose a PR later today)
Problem Description
A mismatch between API specification and it's behavior seems like a problem to me :)
Output of xr.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.8.1 (default, Feb 11 2020, 12:54:25)
[GCC 5.4.0 20160609]
python-bits: 64
OS: Linux
OS-release: 4.15.0-88-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_IE.UTF-8
LOCALE: en_IE.UTF-8
libhdf5: 1.10.4
libnetcdf: 4.6.3
xarray: 0.14.1
pandas: 0.25.3
numpy: 1.18.0
scipy: 1.4.1
netCDF4: 1.5.3
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.0.4.2
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: 3.1.2
cartopy: None
seaborn: None
numbagg: None
setuptools: 45.2.0
pip: 20.0.2
conda: None
pytest: None
IPython: 7.11.1
sphinx: 2.3.1