Skip to content

Commit 74d98a0

Browse files
authored
Merge branch 'master' into switch-to-platformdirs
2 parents 844bba7 + 67303b8 commit 74d98a0

4 files changed

Lines changed: 21 additions & 2 deletions

File tree

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Pint Changelog
3333
- Add `dim_sort` function to _formatter_helpers.
3434
- Add `dim_order` and `default_sort_func` properties to FullFormatter.
3535
(PR #1926, fixes Issue #1841)
36+
- Minimum version requirement added for typing_extensions>=4.0.0.
37+
(PR #1996)
3638
- Documented packages using pint.
3739
(PR #1960)
3840
- Fixed bug causing operations between arrays of quantity scalars and quantity holding
@@ -46,6 +48,8 @@ Pint Changelog
4648
(PR #1949)
4749
- Fix unhandled TypeError when auto_reduce_dimensions=True and non_int_type=Decimal
4850
(PR #1853)
51+
- Creating prefixed offset units now raises an error.
52+
(PR #1998)
4953
- Improved error message in `get_dimensionality()` when non existent units are passed.
5054
(PR #1874, Issue #1716)
5155

pint/facets/plain/registry.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@
6060
UnitLike,
6161
)
6262
from ...compat import Self, TypeAlias, deprecated
63-
from ...errors import DimensionalityError, RedefinitionError, UndefinedUnitError
63+
from ...errors import (
64+
DimensionalityError,
65+
OffsetUnitCalculusError,
66+
RedefinitionError,
67+
UndefinedUnitError,
68+
)
6469
from ...pint_eval import build_eval_tree
6570
from ...util import (
6671
ParserHelper,
@@ -666,6 +671,11 @@ def get_name(self, name_or_alias: str, case_sensitive: bool | None = None) -> st
666671
)
667672

668673
if prefix:
674+
if not self._units[unit_name].is_multiplicative:
675+
raise OffsetUnitCalculusError(
676+
"Prefixing a unit requires multiplying the unit."
677+
)
678+
669679
name = prefix + unit_name
670680
symbol = self.get_symbol(name, case_sensitive)
671681
prefix_def = self._prefixes[prefix]

pint/testsuite/test_unit.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,3 +1043,8 @@ def test_alias(self):
10431043
# Define against unknown name
10441044
with pytest.raises(KeyError):
10451045
ureg.define("@alias notexist = something")
1046+
1047+
def test_prefix_offset_units(self):
1048+
ureg = UnitRegistry()
1049+
with pytest.raises(errors.OffsetUnitCalculusError):
1050+
ureg.parse_units("kilodegree_Celsius")

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
platformdirs>=2.1.0
2-
typing_extensions
2+
typing_extensions>=4.0.0
33
flexcache>=0.3
44
flexparser>=0.3

0 commit comments

Comments
 (0)