Skip to content

Commit

Permalink
Merge pull request #3725 from t20100/fix-pint
Browse files Browse the repository at this point in the history
Fixed support of `pint` >= 0.20
  • Loading branch information
t20100 authored Nov 30, 2022
2 parents 4fe5ac9 + f55cf04 commit 24f80f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ PyOpenGL # For silx.gui.plot3d
python-dateutil # For silx.gui.plot
scipy # For silx.math.fit demo, silx.image.sift demo, silx.image.sift.test
Pillow # For silx.opencl.image.test
pint # For silx.io.dictdump
PyQt5 # PySide6, PyQt6>=6.3 # For silx.gui
11 changes: 7 additions & 4 deletions src/silx/io/dictdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@
import os.path
import h5py
try:
import pint
from pint import Quantity as PintQuantity
except ImportError:
pint = None
try:
from pint.quantity import Quantity as PintQuantity
except ImportError:
PintQuantity = None

from .configdict import ConfigDict
from .utils import is_group
Expand Down Expand Up @@ -67,7 +70,7 @@ def _prepare_hdf5_write_value(array_like):
``numpy.array()`` (`str`, `list`, `numpy.ndarray`…)
:return: ``numpy.ndarray`` ready to be written as an HDF5 dataset
"""
if pint is not None and isinstance(array_like, pint.quantity.Quantity):
if PintQuantity is not None and isinstance(array_like, PintQuantity):
return numpy.array(array_like.magnitude)
array = numpy.asarray(array_like)
if numpy.issubdtype(array.dtype, numpy.bytes_):
Expand Down Expand Up @@ -470,7 +473,7 @@ def nexus_to_h5_dict(
add_nx_class=add_nx_class,
has_nx_class=key_has_nx_class)

elif pint is not None and isinstance(value, pint.quantity.Quantity):
elif PintQuantity is not None and isinstance(value, PintQuantity):
copy[key] = value.magnitude
copy[(key, "units")] = f"{value.units:~C}"

Expand Down

0 comments on commit 24f80f6

Please sign in to comment.