Skip to content

Commit

Permalink
ENH: Add "Celsius" alias (#336)
Browse files Browse the repository at this point in the history
On some instance of E-OBS dataset, the "units" is Celsius instead of the standard "celsius".
  • Loading branch information
bzah authored May 3, 2022
1 parent 2c3801d commit f24c1c3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,6 @@ dmypy.json

# Pyre type checker
.pyre/

# Pycharm config
.idea
8 changes: 8 additions & 0 deletions cf_xarray/tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,11 @@ def test_udunits_format(units, expected):
u = ureg.parse_units(units)

assert f"{u:cf}" == expected


@pytest.mark.parametrize(
"alias",
[ureg("Celsius"), ureg("degC"), ureg("C"), ureg("deg_C"), ureg("degrees_Celsius")],
)
def test_temperature_aliases(alias):
assert alias == ureg("celsius")
2 changes: 1 addition & 1 deletion cf_xarray/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def repl(m):
units.define("year = 365.25 * day = yr")

# Define commonly encountered units not defined by pint
units.define("@alias degC = C = deg_C = degrees_Celsius")
units.define("@alias degC = C = 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...
Expand Down

0 comments on commit f24c1c3

Please sign in to comment.