File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed
src/pynxtools/dataconverter Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change 2121
2222import copy
2323import logging
24- import sys
2524import xml .etree .ElementTree as ET
2625
2726import h5py
2827import numpy as np
28+ import pint
2929
3030from pynxtools .dataconverter import helpers
3131from pynxtools .dataconverter .exceptions import InvalidDictProvided
@@ -259,8 +259,10 @@ def _put_data_into_hdf5(self):
259259
260260 def add_units_key (dataset , path ):
261261 units_key = f"{ path } /@units"
262- if units_key in self .data .keys () and self .data [units_key ] is not None :
263- dataset .attrs ["units" ] = self .data [units_key ]
262+ units = self .data .get (units_key , None )
263+ units = str (units ) if isinstance (units , pint .Unit ) else units
264+ if units :
265+ dataset .attrs ["units" ] = units
264266
265267 for path , value in self .data .items ():
266268 try :
You can’t perform that action at this time.
0 commit comments