pydata / pydata/xarray

xr.concat error behaviour differs based on input DataArray ordering

Open
#7,763 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-combine
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

What happened?

When using xr.concat without specifying the coords argument and with input DataArrays of differing dimensions, where one is missing a dimension that is present in the others, the behaviour of the function will depend on the order and number of the arrays in the input list. The expected behaviour is that a ValueError prompting the use of coords='minimal' will be raised, however this error is not raised when either:

  • There are only two DataArrays in the provided list; or
  • The DataArray with the missing dimension is first in the list.

In these instances, the xr.concat function acts as if coords='minimal' has been specified and broadcasts the smaller DataArray without erroring.

What did you expect to happen?

The raising of errors when using xr.concat should be consistent and not depend on the ordering or number of inputs.

Minimal Complete Verifiable Example
a = xr.DataArray([[1,2,3],[4,5,6]], coords=[('first', [10, 20]), ('second', ['a', 'b', 'c'])])
b = xr.DataArray([[10,20,30],[40,50,60]], coords=[('first', [30, 40]), ('second', ['a', 'b', 'c'])])
c = xr.DataArray([100, 200], coords=[('first', [10, 20])])

xr.concat([a, b, c], dim='first')  # Errors as expected
xr.concat([b, a, c], dim='first')  # Errors as expected
xr.concat([c, a, b], dim='first')  # Does not error
xr.concat([a, c], dim='first')     # Does not error
xr.concat([c, a], dim='first')     # Does not error
MVCE confirmation
  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.
Relevant log output

No response

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS

commit: None
python: 3.10.11 (main, Apr 5 2023, 14:15:10) [GCC 9.4.0]
python-bits: 64
OS: Linux
OS-release: 5.15.90.1-microsoft-standard-WSL2
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: None
libnetcdf: None

xarray: 2023.4.0
pandas: 2.0.0
numpy: 1.24.2
scipy: None
netCDF4: None
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: None
nc_time_axis: None
PseudoNetCDF: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: 65.3.0
pip: 22.2.2
conda: None
pytest: None
mypy: None
IPython: 8.12.0
sphinx: None

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the xr.concat entry point and reproduce the provided minimal example with each input ordering and list length. Trace how differing dimensions are handled when coords is omitted, then add regression coverage showing that all listed cases consistently raise the expected ValueError prompting coords='minimal'.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.