[python-hdf5storage] 19/152: Changed writing of complex types to set complex field names manually.
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:24:30 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to annotated tag 0.1
in repository python-hdf5storage.
commit 254420bca71363d03eed717d1cee4b9833498aff
Author: Freja Nordsiek <fnordsie at gmail.com>
Date: Tue Jan 21 19:45:56 2014 -0500
Changed writing of complex types to set complex field names manually.
---
hdf5storage/Marshallers.py | 6 ++++++
hdf5storage/core.py | 11 ++---------
2 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/hdf5storage/Marshallers.py b/hdf5storage/Marshallers.py
index 9b2144b..a4b809b 100644
--- a/hdf5storage/Marshallers.py
+++ b/hdf5storage/Marshallers.py
@@ -392,6 +392,12 @@ class NumpyScalarArrayMarshaller(TypeMarshaller):
if options.reverse_dimension_order:
data_to_store = data_to_store.T
+ # If it is a complex type, then it needs to be encoded to have
+ # the proper complex field names.
+ if np.iscomplexobj(data_to_store):
+ data_to_store = encode_complex(data_to_store,
+ options.complex_names)
+
# The data must first be written. If name is not present yet,
# then it must be created. If it is present, but not a Dataset,
# has the wrong dtype, or is the wrong shape; then it must be
diff --git a/hdf5storage/core.py b/hdf5storage/core.py
index cf78928..dc5d9ab 100644
--- a/hdf5storage/core.py
+++ b/hdf5storage/core.py
@@ -602,7 +602,7 @@ def write(filename='data.h5', name='/data', data=None,
reverse_dimension_order=False,
convert_strings_to_utf16=False,
store_shape_for_empty=False,
- complex_names=('r','i')):
+ complex_names=('r', 'i')):
# Pack the different options into an Options class. The easiest way
# to do this is to get all the arguments (locals() gets them since
# they are the only symbols in the local table at this point) and
@@ -641,15 +641,9 @@ def write(filename='data.h5', name='/data', data=None,
# Open the hdf5 file and start writing the data (and making the
# group groupname at the same time if it doesn't exist). This is all
# wrapped in a try block, so that the file can be closed if any
- # errors happen (the error is re-raised). The
- # h5py.get_config().complex_names is changed to complex_names. The
- # previous value is restored at the end. Obviously, this makes this
- # whole function thread unsafe as it changes it for h5py globally.
-
- backup_complex_names = h5py.get_config().complex_names
+ # errors happen (the error is re-raised).
try:
- h5py.get_config().complex_names = options.complex_names
# If the file already exists, we just open it. If it doesn't
# exist yet and we are doing any MATLAB formatting, we need to
@@ -676,7 +670,6 @@ def write(filename='data.h5', name='/data', data=None,
finally:
userblock_size = f.userblock_size
f.close()
- h5py.get_config().complex_names = backup_complex_names
# If we are doing MATLAB formatting and there is a sufficiently
# large userblock, write the new userblock. The same sort of error
--
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