Request error handling in dataarray construction
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
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: https://github.com/pydata/xarray/blob/c8dac5866d2c54ee6b262b5060a701e0be1e40cb/xarray/core/dataarray.py#L368-L371
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in xarray/core/dataarray.py at the linked dataarray construction code around lines 368-371. Reproduce construction with mismatched data dimensions and dims, then verify that the resulting ValueError identifies the variable name when one is provided. Done means the existing dimension error remains informative and includes the variable context.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100