Skip to content
/ xarray Public
forked from pydata/xarray

Commit

Permalink
convert to variable to avoid the merge / assign_coords issue
Browse files Browse the repository at this point in the history
relevant issue: pydata#3483
  • Loading branch information
keewis committed Dec 4, 2019
1 parent cd155fe commit 2a1df47
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions xarray/tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,13 @@ def attach_units(obj, units):
def convert_units(obj, to):
if isinstance(obj, xr.Dataset):
data_vars = {
name: convert_units(array, to) for name, array in obj.data_vars.items()
name: convert_units(array, to).variable
for name, array in obj.data_vars.items()
}
coords = {
name: convert_units(array, to).variable
for name, array in obj.coords.items()
}
coords = {name: convert_units(array, to) for name, array in obj.coords.items()}

new_obj = xr.Dataset(data_vars=data_vars, coords=coords, attrs=obj.attrs)
elif isinstance(obj, xr.DataArray):
Expand All @@ -219,7 +223,7 @@ def convert_units(obj, to):
data = convert_units(obj.data, {None: new_units})

coords = {
name: (array.dims, convert_units(array.data, to))
name: (array.dims, convert_units(array.data, to).variable)
for name, array in obj.coords.items()
if name != obj.name
}
Expand Down

0 comments on commit 2a1df47

Please sign in to comment.