Skip to content

Commit f24c1c3

Browse files
authored
ENH: Add "Celsius" alias (#336)
On some instance of E-OBS dataset, the "units" is Celsius instead of the standard "celsius".
1 parent 2c3801d commit f24c1c3

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,6 @@ dmypy.json
130130

131131
# Pyre type checker
132132
.pyre/
133+
134+
# Pycharm config
135+
.idea

cf_xarray/tests/test_units.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,11 @@ def test_udunits_format(units, expected):
7373
u = ureg.parse_units(units)
7474

7575
assert f"{u:cf}" == expected
76+
77+
78+
@pytest.mark.parametrize(
79+
"alias",
80+
[ureg("Celsius"), ureg("degC"), ureg("C"), ureg("deg_C"), ureg("degrees_Celsius")],
81+
)
82+
def test_temperature_aliases(alias):
83+
assert alias == ureg("celsius")

cf_xarray/units.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def repl(m):
9191
units.define("year = 365.25 * day = yr")
9292

9393
# Define commonly encountered units not defined by pint
94-
units.define("@alias degC = C = deg_C = degrees_Celsius")
94+
units.define("@alias degC = C = deg_C = Celsius = degrees_Celsius")
9595
units.define("@alias degK = deg_K")
9696
units.define("@alias day = d")
9797
units.define("@alias hour = h") # Not the Planck constant...

0 commit comments

Comments
 (0)