Skip to content
Snippets Groups Projects

Improved the handling of numpy scalars in cfoods.h5.h5_attr_to_property

Merged Alexander Kreft requested to merge improving-h5-scalar-attribute-handling into dev
2 files
+ 12
7
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -6,6 +6,8 @@
# Copyright (C) 2020 Daniel Hornung <d.hornung@indiscale.com>
# Copyright (C) 2021 Henrik tom Wörden <h.tomwoerden@indiscale.com>
# Copyright (C) 2021 Alexander Kreft
# Copyright (C) 2021 Laboratory for Fluid Physics and Biocomplexity,
# Max-Planck-Insitute für Dynamik und Selbstorganisation <www.lfpn.ds.mpg.de>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@@ -85,13 +87,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
Loading