Skip to content

Commit

Permalink
Due to lack of support for the '%' as a unit within pint,
Browse files Browse the repository at this point in the history
this update converts '%' units to 'percent' units within the
MetPy xarray accessor.

Fixes Unidata#1038.
  • Loading branch information
zbruick committed Jun 11, 2019
1 parent 0a4086e commit 0adc8e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions metpy/tests/test_xarray.py
Expand Up @@ -84,6 +84,14 @@ def test_units(test_var):
assert test_var.metpy.units == units('kelvin')


def test_units_percent():
"""Test that '%' is converted to 'percent'."""
test_var_percent = xr.open_dataset(
get_test_data('irma_gfs_example.nc',
as_file_obj=False))['Relative_humidity_isobaric']
assert test_var_percent.metpy.units == units('percent')


def test_convert_units(test_var):
"""Test in-place conversion of units."""
test_var.metpy.convert_units('degC')
Expand Down
5 changes: 4 additions & 1 deletion metpy/xarray.py
Expand Up @@ -34,7 +34,10 @@ def __init__(self, data_array):

@property
def units(self):
return units(self._units)
if self._units != '%':
return units(self._units)
else:
return units('percent')

@property
def unit_array(self):
Expand Down

0 comments on commit 0adc8e4

Please sign in to comment.