Skip to content

parse_units instead of parse_expression #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 1, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pint_xarray/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def _decide_units(units, registry, unit_attribute):
raise ValueError("no units given")
elif units is None:
# TODO option to read and decode units according to CF conventions (see MetPy)?
units = registry.parse_expression(unit_attribute).units
units = registry.parse_units(unit_attribute)
elif isinstance(units, Unit):
# TODO do we have to check what happens if someone passes a Unit instance
# without creating a unit registry?
Expand Down
7 changes: 7 additions & 0 deletions pint_xarray/tests/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,10 @@ def test_strip_unit_attributes(self, obj, expected):
assert (
filter_none_values(conversion.extract_unit_attributes(actual)) == expected
)


class TestParsing:
def test_parse_integer_inverse(self):
da = DataArray([10], attrs={'units': 'm^-1'})
result = da.pint.quantify()
assert result.pint.units == pint.Unit('1 / meter')