From 20d5291ebb20073e8df062508635ff57dbb6d6d3 Mon Sep 17 00:00:00 2001 From: cherith <315844584+Cherith1222@users.noreply.github.com> Date: Mon, 19 Oct 2026 02:18:47 +0800 Subject: [PATCH 1/2] test(units): expect the symbol C to stay coulomb Importing the CF unit registry currently makes C mean degree Celsius, so a thermal velocity built from electron-volts no longer converts to km/s. --- cf_xarray/tests/test_units.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cf_xarray/tests/test_units.py b/cf_xarray/tests/test_units.py index 36c677cd..0a94ba7a 100644 --- a/cf_xarray/tests/test_units.py +++ b/cf_xarray/tests/test_units.py @@ -4,6 +4,7 @@ Copyright (c) 2017 MetPy Developers. """ +import numpy as np import pytest pytest.importorskip("pint") @@ -90,7 +91,14 @@ def test_udunits_format(units, expected): @pytest.mark.parametrize( "alias", - [ureg("Celsius"), ureg("degC"), ureg("C"), ureg("deg_C"), ureg("degrees_Celsius")], + [ureg("Celsius"), ureg("degC"), ureg("deg_C"), ureg("degrees_Celsius")], ) def test_temperature_aliases(alias): assert alias == ureg("celsius") + + +def test_coulomb_symbol_survives_cf_units(): + assert ureg("C") == ureg("coulomb") + speed = np.sqrt(100 * ureg.eV / ureg.m_e).to("km/s") + assert speed.units == ureg("km/s") + assert speed.magnitude == pytest.approx(4193.828809546234) From 5aa83c062074d9bdf9fcff000725dbc9461528dc Mon Sep 17 00:00:00 2001 From: cherith <315844584+Cherith1222@users.noreply.github.com> Date: Mon, 19 Oct 2026 02:20:13 +0800 Subject: [PATCH 2/2] fix(units): stop aliasing C to degree Celsius UDUNITS uses C for coulomb. degC, Celsius, deg_C, and degrees_Celsius still name degree Celsius. --- cf_xarray/units.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cf_xarray/units.py b/cf_xarray/units.py index 7f0fb281..63de43c2 100644 --- a/cf_xarray/units.py +++ b/cf_xarray/units.py @@ -92,7 +92,7 @@ def short_formatter(unit, registry, **options): units.define("year = 365.25 * day = yr") # Define commonly encountered units not defined by pint -units.define("@alias degC = C = deg_C = Celsius = degrees_Celsius") +units.define("@alias degC = deg_C = Celsius = degrees_Celsius") units.define("@alias degK = deg_K") units.define("@alias day = d") units.define("@alias hour = h") # Not the Planck constant...