[python-hdf5storage] 03/12: Fixed bug when reading complex numbers where one part is NaN but the other is not.
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:24:48 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to annotated tag 0.1.1
in repository python-hdf5storage.
commit 0189bcde0f04eeae0d90acda460317c1d1cbb939
Author: Freja Nordsiek <fnordsie at gmail.com>
Date: Fri Mar 7 17:47:12 2014 -0500
Fixed bug when reading complex numbers where one part is NaN but the other is not.
---
hdf5storage/utilities.py | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/hdf5storage/utilities.py b/hdf5storage/utilities.py
index d754f2b..d746dcb 100644
--- a/hdf5storage/utilities.py
+++ b/hdf5storage/utilities.py
@@ -587,10 +587,20 @@ def decode_complex(data, complex_names=(None, None)):
cnames[1] = s
# If the real and imaginary fields were found, construct the complex
- # form from the fields. Otherwise, return what we were given because
- # it isn't in the right form.
+ # form from the fields. Now, in the case that one part is NaN but
+ # the other is not, simply adding the real and complex parts
+ # together will set both to NaN; so the ones where one and only one
+ # component is NaN have to be set manually using the complex
+ # function. Otherwise, return what we were given because it isn't in
+ # the right form.
if cnames[0] is not None and cnames[1] is not None:
- return data[cnames[0]] + 1j*data[cnames[1]]
+ cdata = data[cnames[0]] + 1j*data[cnames[1]]
+ for index in np.flatnonzero(np.isnan(data[cnames[0]]) \
+ ^ np.isnan(data[cnames[1]])):
+ cdata.ravel()[index] = complex( \
+ data[cnames[0]].ravel()[index], \
+ data[cnames[1]].ravel()[index])
+ return cdata
else:
return data
--
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