Skip to content
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

Except all errors when checking for valid unit #424

Merged
merged 5 commits into from Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions documentation/changelog.rst
Expand Up @@ -22,6 +22,14 @@ Infrastructure / Support
* Allow to filter data by source using a tuple instead of a list [see `PR #421 <http://www.github.com/FlexMeasures/flexmeasures/pull/421>`_]


v0.9.4 | April 28, 2022
===========================

Bugfixes
--------
* Support checking validity of custom units (i.e. non-SI, non-currency units) [see `PR #424 <http://www.github.com/FlexMeasures/flexmeasures/pull/424>`_]


v0.9.3 | April 15, 2022
===========================

Expand Down
1 change: 1 addition & 0 deletions flexmeasures/utils/tests/test_unit_utils.py
Expand Up @@ -151,6 +151,7 @@ def test_units_are_convertible():
("°C", False),
("", False),
("not-a-unit", False),
("#", False),
],
)
def test_is_power_unit(unit: str, power_unit: bool):
Expand Down
6 changes: 3 additions & 3 deletions flexmeasures/utils/unit_utils.py
Expand Up @@ -78,9 +78,9 @@ def is_valid_unit(unit: str) -> bool:
"""Return True if the pint library can work with this unit identifier."""
try:
ur.Quantity(unit)
except ValueError:
return False
except pint.errors.UndefinedUnitError:
except Exception: # noqa B902
# in practice, we encountered pint.errors.UndefinedUnitError, ValueError and AttributeError,
# but since there may be more, here we simply catch them all
return False
return True

Expand Down