Open ericpre opened 6 months ago
year
is another unit that is not supported in that version of pint.
Here is the log showing the error when parsing data with a schema containing the unit um / year
:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/nomad/processing/data.py", line 1203, in parsing
parser.parse(self.mainfile_file.os_path, self._parser_results, logger=logger, **kwargs)
File "/usr/local/lib/python3.9/site-packages/nomad/parsing/parser.py", line 505, in parse
self.parse_file(mainfile, f, archive, logger)
File "/usr/local/lib/python3.9/site-packages/nomad/parsing/parser.py", line 494, in parse_file
archive.definitions = Package.m_from_dict(
File "/usr/local/lib/python3.9/site-packages/nomad/metainfo/metainfo.py", line 4120, in m_from_dict
return super(Package, cls).m_from_dict(data, **kwargs)
File "/usr/local/lib/python3.9/site-packages/nomad/metainfo/metainfo.py", line 2371, in m_from_dict
return MSection.from_dict(data, cls=cls, **kwargs)
File "/usr/local/lib/python3.9/site-packages/nomad/metainfo/metainfo.py", line 2436, in from_dict
section.m_update_from_dict(dct)
File "/usr/local/lib/python3.9/site-packages/nomad/metainfo/metainfo.py", line 2322, in m_update_from_dict
sub_section = sub_section_cls.m_from_dict(
File "/usr/local/lib/python3.9/site-packages/nomad/metainfo/metainfo.py", line 4007, in m_from_dict
return super(Section, cls).m_from_dict(data, **kwargs)
File "/usr/local/lib/python3.9/site-packages/nomad/metainfo/metainfo.py", line 2371, in m_from_dict
return MSection.from_dict(data, cls=cls, **kwargs)
File "/usr/local/lib/python3.9/site-packages/nomad/metainfo/metainfo.py", line 2436, in from_dict
section.m_update_from_dict(dct)
File "/usr/local/lib/python3.9/site-packages/nomad/metainfo/metainfo.py", line 2322, in m_update_from_dict
sub_section = sub_section_cls.m_from_dict(
File "/usr/local/lib/python3.9/site-packages/nomad/metainfo/metainfo.py", line 2371, in m_from_dict
return MSection.from_dict(data, cls=cls, **kwargs)
File "/usr/local/lib/python3.9/site-packages/nomad/metainfo/metainfo.py", line 2436, in from_dict
section.m_update_from_dict(dct)
File "/usr/local/lib/python3.9/site-packages/nomad/metainfo/metainfo.py", line 2357, in m_update_from_dict
section.__dict__[property_def.name] = self.__deserialize(section, quantity_def, quantity_value)
File "/usr/local/lib/python3.9/site-packages/nomad/metainfo/metainfo.py", line 2285, in __deserialize
return __type_specific_deserialize(quantity_value)
File "/usr/local/lib/python3.9/site-packages/nomad/metainfo/metainfo.py", line 2280, in __type_specific_deserialize
return tgt_type.deserialize(section, quantity_def, v)
File "/usr/local/lib/python3.9/site-packages/nomad/metainfo/metainfo.py", line 347, in deserialize
value = units.parse_units(value)
File "/usr/local/lib/python3.9/site-packages/pint/registry.py", line 1093, in parse_units
units = self._parse_units(input_string, as_delta, case_sensitive)
File "/usr/local/lib/python3.9/site-packages/pint/registry.py", line 1306, in _parse_units
return super()._parse_units(input_string, as_delta, case_sensitive)
File "/usr/local/lib/python3.9/site-packages/pint/registry.py", line 1121, in _parse_units
cname = self.get_name(name, case_sensitive=case_sensitive)
File "/usr/local/lib/python3.9/site-packages/pint/registry.py", line 643, in get_name
raise UndefinedUnitError(name_or_alias)
pint.errors.UndefinedUnitError: 'year' is not defined in the unit registry
Thanks for bringing this up. We can definitely try updating to pint==0.21
, especially since it seems to bring support to "%" which will be very useful. I can try the update and see how smoothly it goes: we also have to check that the code we use in the browser to deal with unit transformations works with these new units.
In general, we like to pin many of our dependencies, because we have had so many problems with unpinned libraries breaking our code. But a controlled update of the pinned version is totally fine.
An update: unfortunately pint>=0.21
seems to have broken certain math operations with numpy arrays that have units (see issue here). This is currently preventing us from updating until the problem gets fixed or we refactor several of our parsers to avoid these operations.
It seems that
pint
is pinned to 0.17 and it would be convenient to unpin it be able to useppm
unit, which was introduced in pint 0.21 https://pint.readthedocs.io/en/stable/changes.html#id3.