Skip to content

Commit

Permalink
Except unit uni pint quantity.
Browse files Browse the repository at this point in the history
  • Loading branch information
RubelMozumder authored and lukaspie committed Jan 30, 2025
1 parent 666a4ea commit 2a08efa
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/pynxtools/dataconverter/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@

import copy
import logging
import sys
import xml.etree.ElementTree as ET

import h5py
import numpy as np
import pint

from pynxtools.dataconverter import helpers
from pynxtools.dataconverter.exceptions import InvalidDictProvided
Expand Down Expand Up @@ -259,8 +259,10 @@ def _put_data_into_hdf5(self):

def add_units_key(dataset, path):
units_key = f"{path}/@units"
if units_key in self.data.keys() and self.data[units_key] is not None:
dataset.attrs["units"] = self.data[units_key]
units = self.data.get(units_key, None)
units = str(units) if isinstance(units, pint.Unit) else units
if units:
dataset.attrs["units"] = units

for path, value in self.data.items():
try:
Expand Down

0 comments on commit 2a08efa

Please sign in to comment.