[python-hdf5storage] 20/84: Added workaround for bug when allocating numpy.ndarray when its dtype.itemsize is zero.
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:24:59 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to annotated tag 0.1.10
in repository python-hdf5storage.
commit f2ac363af65ec7bc3fd16cae8d06d00819176bff
Author: Freja Nordsiek <fnordsie at gmail.com>
Date: Sun Sep 14 18:51:33 2014 -0400
Added workaround for bug when allocating numpy.ndarray when its dtype.itemsize is zero.
---
hdf5storage/Marshallers.py | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/hdf5storage/Marshallers.py b/hdf5storage/Marshallers.py
index 5d93f61..1149078 100644
--- a/hdf5storage/Marshallers.py
+++ b/hdf5storage/Marshallers.py
@@ -1065,8 +1065,18 @@ class NumpyScalarArrayMarshaller(TypeMarshaller):
# dtype. The shape is simply the shape of the object arrays
# of its fields, so we might as well use the shape of
# v. Then, all the elements of every field need to be
- # assigned.
- data = np.zeros(shape=v.shape, dtype=dt_whole)
+ # assigned. Now, if dtype's itemsize is 0, a TypeError will
+ # be thrown by numpy due to a bug in numpy. np.zeros (as
+ # well as ones and empty) does not like to make arrays with
+ # no bytes. A workaround is to make an empty array of some
+ # other type and convert its dtype. The smallest one we can
+ # make is an np.int8([]). Yes, one byte will be wasted, but
+ # at least no errors will happen.
+ dtwhole = np.dtype(dt_whole)
+ if dtwhole.itemsize == 0:
+ data = np.int8([]).astype(dtwhole)
+ else:
+ data = np.zeros(shape=v.shape, dtype=dtwhole)
for k, v in struct_data.items():
for index, x in np.ndenumerate(v):
data[k][index] = x
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-hdf5storage.git
More information about the debian-science-commits
mailing list