Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concat now handles non-dim coordinates only present in one dataset #3769

Merged
merged 3 commits into from
Feb 23, 2020

Conversation

dcherian
Copy link
Contributor

  • Tests added
  • Passes isort -rc . && black . && mypy . && flake8
  • Fully documented, including whats-new.rst for all changes and api.rst for new API
da1 = xr.DataArray([1, 2, 3], dims="x", coords={"x": [1, 2, 3], "y": 1})
da2 = xr.DataArray([4, 5, 6], dims="x", coords={"x": [4, 5, 6]})
xr.concat([da1, da2], dim="x")

This use case is quite common since you can get da1 from something like bigger_da1.sel(y=1)

On master this raises an uninformative KeyError because 'y' is not present in all datasets. This is because coords="different" by default which means that we are checking for equality. However coords='different'(and the equality check) is meaningless when the variable is only present in one of the objects to be concatenated.

This PR skips equality checking when a variable is only present in one dataset and raises a nicer error message when it is present in more than one but not all datasets.

@dcherian dcherian requested a review from TomNicholas February 13, 2020 15:55
Copy link
Member

@TomNicholas TomNicholas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like these kind of small changes for common sticking points, they make user experience considerably smoother!

xarray/tests/test_concat.py Show resolved Hide resolved
xarray/tests/test_combine.py Outdated Show resolved Hide resolved
@dcherian
Copy link
Contributor Author

Thanks for the review @TomNicholas

@dcherian dcherian merged commit 3ef75ae into pydata:master Feb 23, 2020
@dcherian dcherian deleted the concat-single-nondim-coord branch February 23, 2020 20:48
dcherian added a commit to johnomotani/xarray that referenced this pull request Feb 24, 2020
…under

* upstream/master: (71 commits)
  Optimize isel for lazy array equality checking (pydata#3588)
  pin msgpack (pydata#3793)
  concat now handles non-dim coordinates only present in one dataset (pydata#3769)
  Add new h5netcdf backend phony_dims kwarg (pydata#3753)
  always use dask_array_type for isinstance calls (pydata#3787)
  allow formatting the diff of ndarray attributes (pydata#3728)
  Pint support for variables (pydata#3706)
  Format issue template comment as md comment (pydata#3790)
  Avoid running test_open_mfdataset_list_attr without dask (pydata#3780)
  remove seaborn.apionly compatibility (pydata#3749)
  Python 3.8 CI (pydata#3727)
  PKG: Explicitly add setuptools dependency (pydata#3628)
  update whats-new
  Typo in Universal Functions section (pydata#3663)
  Release v0.15.0
  fix setup.cfg
  Documentation fixes (pydata#3732)
  Remove extra && in PR template (pydata#3730)
  Remove garbage text inserted in DASK_LICENSE (pydata#3729)
  Avoid unsafe use of pip (pydata#3726)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants