Skip to content

Commit

Permalink
Fix alignment with join="override" when some dims are unindexed (#3839)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian authored Mar 13, 2020
1 parent 650a981 commit 7f4f027
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ New Features
Bug fixes
~~~~~~~~~

- Fix alignment with ``join="override"`` when some dimensions are unindexed. (:issue:`3681`).
By `Deepak Cherian <https://github.com/dcherian>`_.
- Fix :py:meth:`Dataset.swap_dims` and :py:meth:`DataArray.swap_dims` producing
index with name reflecting the previous dimension name instead of the new one
(:issue:`3748`, :pull:`3752`). By `Joseph K Aicher
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _override_indexes(objects, all_indexes, exclude):
objects = list(objects)
for idx, obj in enumerate(objects[1:]):
new_indexes = {}
for dim in obj.dims:
for dim in obj.indexes:
if dim not in exclude:
new_indexes[dim] = all_indexes[dim][0]
objects[idx + 1] = obj._overwrite_indexes(new_indexes)
Expand Down
7 changes: 7 additions & 0 deletions xarray/tests/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ def test_concat_join_kwarg(self):
actual = concat([ds1, ds2], join=join, dim="x")
assert_equal(actual, expected[join])

# regression test for #3681
actual = concat([ds1.drop("x"), ds2.drop("x")], join="override", dim="y")
expected = Dataset(
{"a": (("x", "y"), np.array([0, 0], ndmin=2))}, coords={"y": [0, 0.0001]}
)
assert_identical(actual, expected)

def test_concat_promote_shape(self):
# mixed dims within variables
objs = [Dataset({}, {"x": 0}), Dataset({"x": [1]})]
Expand Down

0 comments on commit 7f4f027

Please sign in to comment.