From 1281c1b624ac0924c97b506939677c796e21af3c Mon Sep 17 00:00:00 2001 From: DWesl <22566757+DWesl@users.noreply.github.com> Date: Wed, 20 May 2026 18:00:43 -0400 Subject: [PATCH 1/6] BUG: UDUnits-style powers must not be followed by a letter 'm2 s-2' is fine, 'm2s-2' is not. I think most places strongly discourage the second. --- src/metpy/units.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/metpy/units.py b/src/metpy/units.py index f98d6f18f93..fd36e73830e 100644 --- a/src/metpy/units.py +++ b/src/metpy/units.py @@ -55,8 +55,7 @@ def _fix_udunits_div(string): # Fix UDUNITS-style powers, percent signs, and ill-defined units -_UDUNIT_POWER = re.compile(r'(?<=[A-Za-z\)])(?![A-Za-z\)])' - r'(? Date: Thu, 21 May 2026 08:53:56 -0400 Subject: [PATCH 2/6] FIX,BUG: Re-Include the redundant parts of the regex --- src/metpy/units.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/metpy/units.py b/src/metpy/units.py index fd36e73830e..d935af958a3 100644 --- a/src/metpy/units.py +++ b/src/metpy/units.py @@ -55,7 +55,8 @@ def _fix_udunits_div(string): # Fix UDUNITS-style powers, percent signs, and ill-defined units -_UDUNIT_POWER = re.compile(r'(?<=[A-Za-z\)])(? Date: Thu, 21 May 2026 09:12:21 -0400 Subject: [PATCH 3/6] FIX,BUG: Also allow UDUnits powers followed by close-paren --- src/metpy/units.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/metpy/units.py b/src/metpy/units.py index d935af958a3..c5e21ea73ac 100644 --- a/src/metpy/units.py +++ b/src/metpy/units.py @@ -56,7 +56,7 @@ def _fix_udunits_div(string): # Fix UDUNITS-style powers, percent signs, and ill-defined units _UDUNIT_POWER = re.compile(r'(?<=[A-Za-z\)])(?![A-Za-z\)])' - r'(? Date: Tue, 26 May 2026 20:58:40 -0400 Subject: [PATCH 4/6] TST: Add tests for UDUnits power conversions leaving chemicals Feet of water expressed as feet_H2O is the usual unit this would apply to. --- tests/units/test_units.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/units/test_units.py b/tests/units/test_units.py index 59eb452f38b..acd89694a2a 100644 --- a/tests/units/test_units.py +++ b/tests/units/test_units.py @@ -10,7 +10,7 @@ from metpy.testing import (assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_nan) -from metpy.units import (check_units, concatenate, is_quantity, +from metpy.units import (UndefinedUnitError, check_units, concatenate, is_quantity, pandas_dataframe_to_unit_arrays, units) @@ -231,9 +231,18 @@ def test_percent_units(): marks=pytest.mark.xfail(reason='hgrecco/pint#1485') ), ('(J kg-1)(m s-1)(-1)', units.m ** 3 / units.s ** 3), - ('/s', units.s ** -1) + ('/s', units.s ** -1), + ('feet_H2O', units.kg / units.m / units.s ** 2) ) ) def test_udunits_power_syntax(unit_str, pint_unit): """Test that UDUNITS style powers are properly parsed and interpreted.""" assert units(unit_str).to_base_units().units == pint_unit + +def test_unsupported_udunits_power_fails(): + """Test that removing the spaces between factors causes parsing to fail. + + UDUnits does not support this either. + """ + with pytest.raises(UndefinedUnitError): + assert units('m2s-2').to_base_units.units == units.m ** 2 / units.s ** 2 From 706f12549e8eb78a65f9681fb475e1a6d56018d7 Mon Sep 17 00:00:00 2001 From: DWesl <22566757+DWesl@users.noreply.github.com> Date: Wed, 27 May 2026 09:14:17 -0400 Subject: [PATCH 5/6] STY: Fix style issues. Wrap import line in different place and put two lines before new test function. --- tests/units/test_units.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/units/test_units.py b/tests/units/test_units.py index acd89694a2a..5970a9d8a0b 100644 --- a/tests/units/test_units.py +++ b/tests/units/test_units.py @@ -10,8 +10,8 @@ from metpy.testing import (assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_nan) -from metpy.units import (UndefinedUnitError, check_units, concatenate, is_quantity, - pandas_dataframe_to_unit_arrays, units) +from metpy.units import (UndefinedUnitError, check_units, concatenate, + is_quantity, pandas_dataframe_to_unit_arrays, units) def test_concatenate(): @@ -239,6 +239,7 @@ def test_udunits_power_syntax(unit_str, pint_unit): """Test that UDUNITS style powers are properly parsed and interpreted.""" assert units(unit_str).to_base_units().units == pint_unit + def test_unsupported_udunits_power_fails(): """Test that removing the spaces between factors causes parsing to fail. From 43c36695d96718f1138913254c8a2bf86b7709c6 Mon Sep 17 00:00:00 2001 From: DWesl <22566757+DWesl@users.noreply.github.com> Date: Thu, 28 May 2026 06:15:27 -0400 Subject: [PATCH 6/6] STY: Adjust import order --- tests/units/test_units.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/units/test_units.py b/tests/units/test_units.py index 5970a9d8a0b..5ea0feb3512 100644 --- a/tests/units/test_units.py +++ b/tests/units/test_units.py @@ -10,8 +10,8 @@ from metpy.testing import (assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_nan) -from metpy.units import (UndefinedUnitError, check_units, concatenate, - is_quantity, pandas_dataframe_to_unit_arrays, units) +from metpy.units import (check_units, concatenate, is_quantity, + pandas_dataframe_to_unit_arrays, UndefinedUnitError, units) def test_concatenate():