Skip to content

Commit

Permalink
sel: propagate multi-index vars attrs/encoding
Browse files Browse the repository at this point in the history
Related to pydata#1366
  • Loading branch information
benbovy committed Sep 9, 2021
1 parent a6bce37 commit ad17931
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1178,8 +1178,16 @@ def _overwrite_indexes(
new_coord_names = self._coord_names.copy()
new_indexes = dict(self.xindexes)

for name, var in variables.items():
old_var = self._variables.get(name)
if old_var is not None:
# propagate attrs and encoding
# TODO: needs a test
var.attrs = {**old_var.attrs, **var.attrs}
var.encoding = {**old_var.encoding, **var.encoding}
new_variables[name] = var

for name in indexes:
new_variables[name] = variables[name]
new_indexes[name] = indexes[name]

for name in drop_variables:
Expand Down Expand Up @@ -2346,6 +2354,8 @@ def isel(
indexes.pop(var_name, None)
continue
if indexes and var_name in indexes:
# TODO benbovy - flexible indexes: this won't be always desirable
# (e.g., 1-d out-of-core coordinate, "meta"-index, etc.)
if var_value.ndim == 1:
indexes[var_name] = var_value._to_xindex()
else:
Expand Down

0 comments on commit ad17931

Please sign in to comment.