Skip to content

Commit

Permalink
Fix bug where wrong TypeError was caught with spike trains of length 1
Browse files Browse the repository at this point in the history
  • Loading branch information
lkoelman committed Jun 21, 2018
1 parent 12d7330 commit 6b04545
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions neo/io/neomatlabio.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ def create_ob_from_struct(self, struct, classname):
if "sampling_rate" in (at[0] for at in cl._necessary_attrs):
# put fake value for now, put correct value later
data_complement["sampling_rate"] = 0 * pq.kHz
try:
len(arr)
except TypeError:
# strange scipy.io behavior: if len is 1 we get a float
arr = np.array(arr)
arr = arr.reshape((-1,)) # new view with one dimension
if "t_stop" in (at[0] for at in cl._necessary_attrs):
if len(arr) > 0:
data_complement["t_stop"] = arr.max()
Expand All @@ -345,18 +351,23 @@ def create_ob_from_struct(self, struct, classname):
for attrname in struct._fieldnames:
# check children
if attrname in getattr(ob, '_single_child_containers', []):
child_struct = getattr(struct, attrname)
try:
for c in range(len(getattr(struct, attrname))):
child = self.create_ob_from_struct(
getattr(struct, attrname)[c],
classname_lower_to_upper[attrname[:-1]])
getattr(ob, attrname.lower()).append(child)
# try must only surround len() or other errors are captured
child_len = len(child_struct)
except TypeError:
# strange scipy.io behavior: if len is 1 there is no len()
child = self.create_ob_from_struct(
getattr(struct, attrname),
child_struct,
classname_lower_to_upper[attrname[:-1]])
getattr(ob, attrname.lower()).append(child)
else:
for c in range(child_len):
child = self.create_ob_from_struct(
child_struct[c],
classname_lower_to_upper[attrname[:-1]])
getattr(ob, attrname.lower()).append(child)

continue

# attributes
Expand Down

0 comments on commit 6b04545

Please sign in to comment.