Skip to content

Commit

Permalink
add error for prefixed non multi units
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgsavage committed May 27, 2024
1 parent 9972e60 commit 11a9c6d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pint/facets/plain/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
UnitLike,
)
from ...compat import Self, TypeAlias, deprecated
from ...errors import DimensionalityError, RedefinitionError, UndefinedUnitError
from ...errors import DimensionalityError, RedefinitionError, UndefinedUnitError, OffsetUnitCalculusError
from ...pint_eval import build_eval_tree
from ...util import (
ParserHelper,
Expand Down Expand Up @@ -664,6 +664,9 @@ def get_name(self, name_or_alias: str, case_sensitive: bool | None = None) -> st
)

if prefix:
if not self._units[unit_name].is_multiplicative:
raise OffsetUnitCalculusError("Prefixing a unit requires multiplying the unit.")

name = prefix + unit_name
symbol = self.get_symbol(name, case_sensitive)
prefix_def = self._prefixes[prefix]
Expand Down

0 comments on commit 11a9c6d

Please sign in to comment.