Skip to content

Commit d69f021

Browse files
committed
Preserve coordinate metadata when overriding alignment indexes
1 parent 960d99a commit d69f021

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

‎doc/whats-new.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ Deprecations
192192

193193
Bug Fixes
194194
~~~~~~~~~
195+
- :py:func:`align` with ``join="override"`` now preserves each object's
196+
coordinate attributes and encoding instead of inheriting metadata from the
197+
first object (:issue:`6860`).
195198
- :py:meth:`Dataset.query` now resolves coordinates in datasets with no data
196199
variables (:issue:`6449`).
197200
By `Liang, Jingyi <https://github.com/LJimmy007>`_.

‎xarray/structure/alignment.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,13 +541,17 @@ def override_indexes(self) -> None:
541541
new_indexes = {}
542542
new_variables = {}
543543
matching_indexes = self.objects_matching_indexes[i + 1]
544+
matching_index_vars = self.objects_matching_index_vars[i + 1]
544545

545546
for key, aligned_idx in self.aligned_indexes.items():
546547
obj_idx = matching_indexes.get(key)
547548
if obj_idx is not None:
548549
for name, var in self.aligned_index_vars[key].items():
550+
original_var = matching_index_vars[key][name]
549551
new_indexes[name] = aligned_idx
550552
new_variables[name] = var.copy(deep=self.copy)
553+
new_variables[name].attrs = original_var.attrs
554+
new_variables[name].encoding = original_var.encoding
551555

552556
objects[i + 1] = obj._overwrite_indexes(new_indexes, new_variables)
553557

0 commit comments

Comments
 (0)