Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgsavage committed Jun 15, 2024
1 parent 6a1938e commit 6e420fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
8 changes: 7 additions & 1 deletion pint/delegates/formatter/_compound_unit_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,15 @@ def prepare_compount_unit(
out = unit._units.items()
else:
out = unit

# out: unit_name, unit_exponent

if len(out) == 0:
if "~" in spec:
return ([], [])
else:
return ([("dimensionless", 1)], [])

if "~" in spec:
if registry is None:
raise ValueError(
Expand Down
20 changes: 13 additions & 7 deletions pint/testsuite/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -1260,10 +1260,16 @@ def test_issue1772(given, expected):
def test_issue2007():
ureg = UnitRegistry()
q = ureg.Quantity(1, "")
assert f"{q:P}" == '1 dimensionless'
assert f"{q:C}" == '1 dimensionless'
assert f"{q:D}" == '1 dimensionless'
assert f"{q:H}" == '1 dimensionless'
# assert f"{q:L}" == '1\\ dimensionless'
assert f"{q:Lx}" == '\\SI[]{1}{}'
assert f"{q:~P}" == '1'
assert f"{q:P}" == "1 dimensionless"
assert f"{q:C}" == "1 dimensionless"
assert f"{q:D}" == "1 dimensionless"
assert f"{q:H}" == "1 dimensionless"

assert f"{q:L}" == "1\\ \\mathrm{dimensionless}"
# L returned '1\\ dimensionless' in pint 0.23

assert f"{q:Lx}" == "\\SI[]{1}{}"
assert f"{q:~P}" == "1"
assert f"{q:~C}" == "1"
assert f"{q:~D}" == "1"
assert f"{q:~H}" == "1"

0 comments on commit 6e420fe

Please sign in to comment.