Skip to content

Commit 7f4f027

Browse files
authored
Fix alignment with join="override" when some dims are unindexed (pydata#3839)
1 parent 650a981 commit 7f4f027

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/whats-new.rst

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ New Features
5555
Bug fixes
5656
~~~~~~~~~
5757

58+
- Fix alignment with ``join="override"`` when some dimensions are unindexed. (:issue:`3681`).
59+
By `Deepak Cherian <https://github.com/dcherian>`_.
5860
- Fix :py:meth:`Dataset.swap_dims` and :py:meth:`DataArray.swap_dims` producing
5961
index with name reflecting the previous dimension name instead of the new one
6062
(:issue:`3748`, :pull:`3752`). By `Joseph K Aicher

xarray/core/alignment.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def _override_indexes(objects, all_indexes, exclude):
5050
objects = list(objects)
5151
for idx, obj in enumerate(objects[1:]):
5252
new_indexes = {}
53-
for dim in obj.dims:
53+
for dim in obj.indexes:
5454
if dim not in exclude:
5555
new_indexes[dim] = all_indexes[dim][0]
5656
objects[idx + 1] = obj._overwrite_indexes(new_indexes)

xarray/tests/test_concat.py

+7
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ def test_concat_join_kwarg(self):
250250
actual = concat([ds1, ds2], join=join, dim="x")
251251
assert_equal(actual, expected[join])
252252

253+
# regression test for #3681
254+
actual = concat([ds1.drop("x"), ds2.drop("x")], join="override", dim="y")
255+
expected = Dataset(
256+
{"a": (("x", "y"), np.array([0, 0], ndmin=2))}, coords={"y": [0, 0.0001]}
257+
)
258+
assert_identical(actual, expected)
259+
253260
def test_concat_promote_shape(self):
254261
# mixed dims within variables
255262
objs = [Dataset({}, {"x": 0}), Dataset({"x": [1]})]

0 commit comments

Comments
 (0)