From 94ae2395f204f125ccd048d39ffa7bf0a5642213 Mon Sep 17 00:00:00 2001 From: Freja Nordsiek <freja.nordsiek@ds.mpg.de> Date: Wed, 15 Sep 2021 09:41:14 +0200 Subject: [PATCH] Improved the handling of numpy scalars (whether bare or 0-dimensional ndarrays) in cfoods.h5.h5_attr_to_property. --- src/caosadvancedtools/cfoods/h5.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/caosadvancedtools/cfoods/h5.py b/src/caosadvancedtools/cfoods/h5.py index 543ac327..33f87510 100644 --- a/src/caosadvancedtools/cfoods/h5.py +++ b/src/caosadvancedtools/cfoods/h5.py @@ -85,13 +85,13 @@ def h5_attr_to_property(val): if isinstance(val, np.ndarray): if val.ndim > 1: return None, None - - if val.ndim == 0: - raise NotImplementedError( - "Code assumes that scalar values " - "will not be given as np.ndarray objects") - val = list(val) + # The tolist method is on both numpy.ndarray and numpy.generic + # and properly converts scalars (including 0-dimensional + # numpy.ndarray) to Python scalars and 1D arrays to lists of + # Python scalars. + if val.ndim != 0: dtype = db.LIST(dtype) + val = val.tolist() # TODO this can eventually be removed -- GitLab