From 6e420fecc45b05b7d298aac0509f969306145621 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 15 Jun 2024 09:52:24 +0100 Subject: [PATCH] format --- .../formatter/_compound_unit_helpers.py | 8 +++++++- pint/testsuite/test_issues.py | 20 ++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) 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"