[Bug] CF Conventions units - formatting tilde breaks string representation
With default_format = "~cf"
, the registry can't print units like "mm"
, although it can handle it in checks etc.
Temporarily fixed !109 (merged). Added tests for it in !110 (merged).
Error backtrace:
...
File "C:\Data\Hack\Python\FINAM\finam\src\finam\data\tools.py", line 425, in check
f"check: given data has wrong units. "
File "C:\Programs\Python39\lib\site-packages\pint\unit.py", line 99, in __format__
return format_unit(units, uspec, registry=self._REGISTRY)
File "C:\Programs\Python39\lib\site-packages\pint\formatting.py", line 411, in format_unit
return fmt(unit, registry=registry, **options)
File "C:\Programs\Python39\lib\site-packages\cf_xarray\units.py", line 39, in short_formatter
s = f"{unit:~D}"
File "C:\Programs\Python39\lib\site-packages\pint\unit.py", line 90, in __format__
dict(
File "C:\Programs\Python39\lib\site-packages\pint\unit.py", line 91, in <genexpr>
(self._REGISTRY._get_symbol(key), value)
File "C:\Programs\Python39\lib\site-packages\pint\registry.py", line 766, in _get_symbol
return self._units[name].symbol
File "C:\Programs\Python39\lib\collections\__init__.py", line 941, in __getitem__
return self.__missing__(key) # support subclasses that define __missing__
File "C:\Programs\Python39\lib\collections\__init__.py", line 933, in __missing__
raise KeyError(key)
KeyError: 'mm'
Edited by Martin Lange