Skip to content

Commit

Permalink
Merge branch 'master' into switch-to-platformdirs
Browse files Browse the repository at this point in the history
  • Loading branch information
hgrecco committed Jul 28, 2024
2 parents 844bba7 + 67303b8 commit 74d98a0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Pint Changelog
- Add `dim_sort` function to _formatter_helpers.
- Add `dim_order` and `default_sort_func` properties to FullFormatter.
(PR #1926, fixes Issue #1841)
- Minimum version requirement added for typing_extensions>=4.0.0.
(PR #1996)
- Documented packages using pint.
(PR #1960)
- Fixed bug causing operations between arrays of quantity scalars and quantity holding
Expand All @@ -46,6 +48,8 @@ Pint Changelog
(PR #1949)
- Fix unhandled TypeError when auto_reduce_dimensions=True and non_int_type=Decimal
(PR #1853)
- Creating prefixed offset units now raises an error.
(PR #1998)
- Improved error message in `get_dimensionality()` when non existent units are passed.
(PR #1874, Issue #1716)

Expand Down
12 changes: 11 additions & 1 deletion pint/facets/plain/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@
UnitLike,
)
from ...compat import Self, TypeAlias, deprecated
from ...errors import DimensionalityError, RedefinitionError, UndefinedUnitError
from ...errors import (
DimensionalityError,
OffsetUnitCalculusError,
RedefinitionError,
UndefinedUnitError,
)
from ...pint_eval import build_eval_tree
from ...util import (
ParserHelper,
Expand Down Expand Up @@ -666,6 +671,11 @@ 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
5 changes: 5 additions & 0 deletions pint/testsuite/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,3 +1043,8 @@ def test_alias(self):
# Define against unknown name
with pytest.raises(KeyError):
ureg.define("@alias notexist = something")

def test_prefix_offset_units(self):
ureg = UnitRegistry()
with pytest.raises(errors.OffsetUnitCalculusError):
ureg.parse_units("kilodegree_Celsius")
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platformdirs>=2.1.0
typing_extensions
typing_extensions>=4.0.0
flexcache>=0.3
flexparser>=0.3

0 comments on commit 74d98a0

Please sign in to comment.