File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed
src/pynxtools/dataconverter Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 3535)
3636
3737logger = logging .getLogger ("pynxtools" ) # pylint: disable=C0103
38-
38+ ureg = pint . UnitRegistry ()
3939
4040def does_path_exist (path , h5py_obj ) -> bool :
4141 """Returns true if the requested path exists in the given h5py object."""
@@ -260,7 +260,20 @@ def _put_data_into_hdf5(self):
260260 def add_units_key (dataset , path ):
261261 units_key = f"{ path } /@units"
262262 units = self .data .get (units_key , None )
263- units = str (units ) if isinstance (units , pint .Unit ) else units
263+ if units is None :
264+ return
265+ if isinstance (units , pint .Unit ):
266+ units = str (units )
267+ else :
268+ try :
269+ ureg .Unit (units )
270+ except pint .errors .UndefinedUnitError as exc :
271+ massage = (
272+ f"Units provided for path: '{ path } @units' are not valid."
273+ f" Please provide a valid unit."
274+ )
275+ raise InvalidDictProvided (massage ) from exc
276+
264277 if units :
265278 dataset .attrs ["units" ] = units
266279
You can’t perform that action at this time.
0 commit comments