Skip to content

Commit

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

print(out)
if len(out) == 0 and not "~" in spec:
out = {"dimensionless": 1}.items()
# out: unit_name, unit_exponent

if "~" in spec:
Expand Down
4 changes: 3 additions & 1 deletion pint/delegates/formatter/_format_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ def join_mu(joint_fstring: str, mstr: str, ustr: str) -> str:
This avoids that `3 and `1 / m` becomes `3 1 / m`
"""
if ustr == "":
return mstr
if ustr.startswith("1 / "):
return joint_fstring.format(mstr, ustr[2:])
return joint_fstring.format(mstr, ustr)
Expand Down Expand Up @@ -211,7 +213,7 @@ def formatter(
neg_terms.append(power_fmt.format(key, fun(value)))

if not pos_terms and not neg_terms:
return "dimensionless"
return ""

if not as_ratio:
# Show as Product: positive * negative terms ** -1
Expand Down
5 changes: 3 additions & 2 deletions pint/testsuite/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -1264,5 +1264,6 @@ def test_issue2007():
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:L}" == '1\\ dimensionless'
assert f"{q:Lx}" == '\\SI[]{1}{}'
assert f"{q:~P}" == '1'

0 comments on commit 8d0439a

Please sign in to comment.