diff --git a/pint/delegates/formatter/_compound_unit_helpers.py b/pint/delegates/formatter/_compound_unit_helpers.py index 01e71d896..d6970b12e 100644 --- a/pint/delegates/formatter/_compound_unit_helpers.py +++ b/pint/delegates/formatter/_compound_unit_helpers.py @@ -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( diff --git a/pint/testsuite/test_issues.py b/pint/testsuite/test_issues.py index eb286d6c7..2fcc1f22c 100644 --- a/pint/testsuite/test_issues.py +++ b/pint/testsuite/test_issues.py @@ -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' \ No newline at end of file + 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"