[python-hdf5storage] 144/152: Fixed bug where loadmat was not returning a dict of the variables and not putting it in mdict if it was given.
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:24:43 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 20b5798f1175a91cc0d5fe4656b398fff24d9176
Author: Freja Nordsiek <fnordsie at gmail.com>
Date: Sun Feb 16 03:11:59 2014 -0500
Fixed bug where loadmat was not returning a dict of the variables and not putting it in mdict if it was given.
---
hdf5storage/__init__.py | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/hdf5storage/__init__.py b/hdf5storage/__init__.py
index 857eb38..37c7efb 100644
--- a/hdf5storage/__init__.py
+++ b/hdf5storage/__init__.py
@@ -1346,17 +1346,30 @@ def loadmat(file_name, mdict=None, appendmat=True,
filename = file_name
# Read everything if we were instructed.
+
if variable_names is None:
- return read(path='/', filename=filename, options=options)
+ # Read everything from the root node.
+ data = read(path='/', filename=filename, options=options)
+
+ # If we didn't make a dict but instead got a structured
+ # ndarray, extract all the fields and make a dict from them.
+ if not isinstance(data, dict):
+ new_data = dict()
+ for field in data.dtype.names:
+ new_data[field] = data[field][0]
+ data = new_data
+ else:
+ # Extract the desired fields into a dictionary one by one.
+ data = dict()
+ for name in variable_names:
+ data[name] = read(path=name, filename=filename,
+ options=options)
# Read all the variables, stuff them into mdict, and return it.
if mdict is None:
mdict = dict()
-
- for name in variable_names:
- mdict[name] = read(name=name, filename=filename,
- options=options)
-
+ for k, v in data.items():
+ mdict[k] = v
return mdict
except OSError:
import scipy.io
--
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