-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
When I have a bad dimension in an xarray I get this error:
ValueError: different number of dimensions on data and dims: 2 vs 3
Expected Output
what I would like to see is
ValueError: different number of dimensions on data and dims: 2 vs 3 for variable Foo
The improvement I am asking for is here:
xarray/xarray/core/dataarray.py
Lines 368 to 371 in c8dac58
data = _check_data_shape(data, coords, dims) | |
data = as_compatible_data(data) | |
coords, dims = _infer_coords_and_dims(data.shape, coords, dims) | |
variable = Variable(dims, data, attrs, encoding, fastpath=True) |
What I claim would be an improvement would be something like this:
data = _check_data_shape(data, coords, dims)
data = as_compatible_data(data)
try:
coords, dims = _infer_coords_and_dims(data.shape, coords, dims)
except Exception as e:
if name:
raise Exception("Error finding coordinates and dims for variable %s: %s"%(name, e)
else:
raise e
variable = Variable(dims, data, attrs, encoding, fastpath=True)
I'm not an expert on python exception handling, so this is probably wrong.
Problem Description
The programmer cannot tell what variable causes the shape and dimension issue.
Output of xr.show_versions()
xarray: 0.13.0
pandas: 0.25.2
numpy: 1.17.3
scipy: 1.3.1
netCDF4: 1.5.2
pydap: None
h5netcdf: None
h5py: 2.10.0
Nio: None
zarr: None
cftime: 1.0.3.4
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: 1.2.1
dask: None
distributed: None
matplotlib: 3.1.1
cartopy: None
seaborn: 0.9.0
numbagg: None
setuptools: 41.2.0
pip: 19.3.1
conda: None
pytest: 5.2.0
IPython: 7.8.0
sphinx: None