Skip to content

Commit 2a08efa

Browse files
RubelMozumderlukaspie
authored andcommitted
Except unit uni pint quantity.
1 parent 666a4ea commit 2a08efa

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/pynxtools/dataconverter/writer.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121

2222
import copy
2323
import logging
24-
import sys
2524
import xml.etree.ElementTree as ET
2625

2726
import h5py
2827
import numpy as np
28+
import pint
2929

3030
from pynxtools.dataconverter import helpers
3131
from 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:

0 commit comments

Comments
 (0)