Skip to content

Commit

Permalink
Fix 349 (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-chambers authored Mar 1, 2024
1 parent e900f24 commit 1d49530
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dascore/proc/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
def _update_attrs_coord_units(patch: dc.Patch, data_units, coords):
"""Update attributes with new units."""
attrs = patch.attrs
data_units = data_units or attrs.get("data_units")
# set data units
attrs = attrs.update(data_units=data_units, coords=coords.to_summary_dict())
return attrs
Expand Down Expand Up @@ -46,6 +45,8 @@ def set_units(
>>> patch_with_units = patch.set_units("km/ms")
>>> # set the units of the distance coordinate
>>> patch_feet = patch.set_units(distance='feet')
>>> # remove data units
>>> patch_removed_units = patch_with_units.set_units(None)
"""
new_coords = patch.coords.set_units(**kwargs)
new_attrs = _update_attrs_coord_units(patch, data_units, new_coords)
Expand Down
14 changes: 14 additions & 0 deletions tests/test_proc/test_proc_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ def test_set_data_and_coord_units(self, random_patch):
assert get_quantity(out.attrs.data_units) == get_quantity("m/s")
assert get_quantity(out.attrs.distance_units) == get_quantity("ft")

def test_remove_units(self, random_patch):
"""Ensure set coords can remove units."""
patch = random_patch.set_units("m", distance="m")
# ensure data units can be removed
new_none = patch.set_units(None)
assert new_none.attrs.data_units is None
new_empty_str = patch.set_units("")
assert new_empty_str.attrs.data_units is None
# ensure coord units can be removed
new_dist_none = random_patch.set_units(distance=None)
assert new_dist_none.get_coord("distance").units is None
new_dist_empty = random_patch.set_units(distance="")
assert new_dist_empty.get_coord("distance").units is None


class TestConvertUnits:
"""Tests for converting from one unit to another."""
Expand Down

0 comments on commit 1d49530

Please sign in to comment.