Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pint parses "celsius" but not "Celsius" #1081

Closed
dopplershift opened this issue Apr 17, 2020 · 4 comments
Closed

Pint parses "celsius" but not "Celsius" #1081

dopplershift opened this issue Apr 17, 2020 · 4 comments

Comments

@dopplershift
Copy link
Contributor

So this works:

from pint import UnitRegistry
ureg = UnitRegistry()
ureg.parse_units('celsius')

but the following:

from pint import UnitRegistry
ureg = UnitRegistry()
ureg.parse_units('Celsius')

gives:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/rmay/miniconda3/envs/py38/lib/python3.8/site-packages/pint/registry.py", line 1065, in parse_units
    units = self._parse_units(input_string, as_delta)
  File "/Users/rmay/miniconda3/envs/py38/lib/python3.8/site-packages/pint/registry.py", line 1264, in _parse_units
    return super()._parse_units(input_string, as_delta)
  File "/Users/rmay/miniconda3/envs/py38/lib/python3.8/site-packages/pint/registry.py", line 1093, in _parse_units
    cname = self.get_name(name)
  File "/Users/rmay/miniconda3/envs/py38/lib/python3.8/site-packages/pint/registry.py", line 626, in get_name
    raise UndefinedUnitError(name_or_alias)
pint.errors.UndefinedUnitError: 'Celsius' is not defined in the unit registry

that seems wrong. At the very least I would expect "Celsius" to be the one that works if only one of them works.

@rsignell-usgs
Copy link

rsignell-usgs commented Apr 17, 2020

Hmm, very interesting.

From udunits, the following are allowed:
degree_Celsius, ℃, celsius, degC, degreeC, degree_C, degreesC, deg_C, degs_C, degsC

From pint, the following are allowed:
degree_Celsius, °C, celsius, degC, degreeC

It looks like Celcius is not on either list!

It also looks like MetPy will be parsing fewer CF-compliant files unless we enhance pint to include all the udunits, right @dopplershift ?

@hgrecco
Copy link
Owner

hgrecco commented Apr 17, 2020

Uppercase Celsius is not accepted by NIST, unless is as a modifier to degrees (as in degree Celsius)

https://www.nist.gov/pml/weights-and-measures/writing-metric-units

@dopplershift
Copy link
Contributor Author

@rsignell-usgs udunits also lists "degree_kelvin" and friends, which is an abomination against nature. 😉 But yes, there does seem to be quite a bit of departure between Pint and udunits; we'll want to do something about that in MetPy, but we don't need to belabor that here.

Just one point I want to throw out is that literally every mention in the NIST docs says "degrees Celsius"--never "celsius" by itself (or "Celsius temperature"). I'm not convinced that NIST would even sanction leaving off the degrees. Just food for thought (which wouldn't help fix my problem).

Regardless, the question of whether the lack of "Celsius" is an omission or otherwise a bug has been answered as definitively no.

@hgrecco
Copy link
Owner

hgrecco commented Apr 23, 2020

Just as a historical note, let me say that I think that adhering strictly (or at least as strictly as I could) to NIST and BIPM instead of making it straight forward for every community to use pint without changes was one of the best decisions that we took. I have seem people adapting their code to follow BIPM guidelines to use Pint resulting in a more interoperable ecosystem.

It is worth noting that we provide a flexible definition file and hackable preprocessor list. So we propose doing it the right way, but we also provide a way for user who cannot adapt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants