Skip to content

Commit f3bb3fb

Browse files
author
kleinjohann
committed
Fix dict changing during iteration
1 parent 39d3794 commit f3bb3fb

File tree

1 file changed

+10
-50
lines changed

1 file changed

+10
-50
lines changed

neo/io/nixio.py

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -406,23 +406,15 @@ def _nix_to_neo_analogsignal(self, nix_da_group):
406406
sig_length = 1
407407

408408
array_annotations = {}
409-
410409
if sig_length > 1:
411410
for attr_key, attr_val in neo_attrs.items():
412411
if isinstance(attr_val, (list, np.ndarray, pq.Quantity)):
413412
if isinstance(attr_val, (np.ndarray, pq.Quantity)) and attr_val.shape == ():
414413
attr_val = attr_val.flatten()
415414
if len(attr_val) == sig_length:
416-
if isinstance(attr_val, list) or (isinstance(attr_val, np.ndarray) and not (
417-
isinstance(attr_val, pq.Quantity) and (
418-
attr_val.shape == () or attr_val.shape == (1,)))):
419-
# Array annotations should only be 1-dimensional
420-
continue
421-
if isinstance(attr_val, dict):
422-
# Dictionaries are not supported as array annotations
423-
continue
424415
array_annotations[attr_key] = attr_val
425-
del neo_attrs[attr_key]
416+
for key in array_annotations:
417+
del neo_attrs[key]
426418

427419
neo_signal = AnalogSignal(
428420
signal=signaldata, sampling_period=sampling_period,
@@ -465,23 +457,15 @@ def _nix_to_neo_irregularlysampledsignal(self, nix_da_group):
465457
sig_length = 1
466458

467459
array_annotations = {}
468-
469460
if sig_length > 1:
470461
for attr_key, attr_val in neo_attrs.items():
471462
if isinstance(attr_val, (list, np.ndarray, pq.Quantity)):
472463
if isinstance(attr_val, (np.ndarray, pq.Quantity)) and attr_val.shape == ():
473464
attr_val = attr_val.flatten()
474465
if len(attr_val) == sig_length:
475-
if isinstance(attr_val, list) or (isinstance(attr_val, np.ndarray) and not (
476-
isinstance(attr_val, pq.Quantity) and (
477-
attr_val.shape == () or attr_val.shape == (1,)))):
478-
# Array annotations should only be 1-dimensional
479-
continue
480-
if isinstance(attr_val, dict):
481-
# Dictionaries are not supported as array annotations
482-
continue
483466
array_annotations[attr_key] = attr_val
484-
del neo_attrs[attr_key]
467+
for key in array_annotations:
468+
del neo_attrs[key]
485469

486470
neo_signal = IrregularlySampledSignal(
487471
signal=signaldata, times=times, array_annotations=array_annotations, **neo_attrs
@@ -511,23 +495,15 @@ def _nix_to_neo_event(self, nix_mtag):
511495
sig_length = 1
512496

513497
array_annotations = {}
514-
515498
if sig_length > 1:
516499
for attr_key, attr_val in neo_attrs.items():
517500
if isinstance(attr_val, (list, np.ndarray, pq.Quantity)):
518501
if isinstance(attr_val, (np.ndarray, pq.Quantity)) and attr_val.shape == ():
519502
attr_val = attr_val.flatten()
520503
if len(attr_val) == sig_length:
521-
if isinstance(attr_val, list) or (isinstance(attr_val, np.ndarray) and not (
522-
isinstance(attr_val, pq.Quantity) and (
523-
attr_val.shape == () or attr_val.shape == (1,)))):
524-
# Array annotations should only be 1-dimensional
525-
continue
526-
if isinstance(attr_val, dict):
527-
# Dictionaries are not supported as array annotations
528-
continue
529504
array_annotations[attr_key] = attr_val
530-
del neo_attrs[attr_key]
505+
for key in array_annotations:
506+
del neo_attrs[key]
531507

532508
neo_event = Event(times=times, labels=labels, array_annotations=array_annotations,
533509
**neo_attrs)
@@ -550,23 +526,15 @@ def _nix_to_neo_epoch(self, nix_mtag):
550526
sig_length = 1
551527

552528
array_annotations = {}
553-
554529
if sig_length > 1:
555530
for attr_key, attr_val in neo_attrs.items():
556531
if isinstance(attr_val, (list, np.ndarray, pq.Quantity)):
557532
if isinstance(attr_val, (np.ndarray, pq.Quantity)) and attr_val.shape == ():
558533
attr_val = attr_val.flatten()
559534
if len(attr_val) == sig_length:
560-
if isinstance(attr_val, list) or (isinstance(attr_val, np.ndarray) and not (
561-
isinstance(attr_val, pq.Quantity) and (
562-
attr_val.shape == () or attr_val.shape == (1,)))):
563-
# Array annotations should only be 1-dimensional
564-
continue
565-
if isinstance(attr_val, dict):
566-
# Dictionaries are not supported as array annotations
567-
continue
568535
array_annotations[attr_key] = attr_val
569-
del neo_attrs[attr_key]
536+
for key in array_annotations:
537+
del neo_attrs[key]
570538

571539
if len(nix_mtag.positions.dimensions[0].labels) > 0:
572540
labels = np.array(nix_mtag.positions.dimensions[0].labels,
@@ -592,23 +560,15 @@ def _nix_to_neo_spiketrain(self, nix_mtag):
592560
sig_length = 1
593561

594562
array_annotations = {}
595-
596563
if sig_length > 1:
597564
for attr_key, attr_val in neo_attrs.items():
598565
if isinstance(attr_val, (list, np.ndarray, pq.Quantity)):
599566
if isinstance(attr_val, (np.ndarray, pq.Quantity)) and attr_val.shape == ():
600567
attr_val = attr_val.flatten()
601568
if len(attr_val) == sig_length:
602-
if isinstance(attr_val, list) or (isinstance(attr_val, np.ndarray) and not (
603-
isinstance(attr_val, pq.Quantity) and (
604-
attr_val.shape == () or attr_val.shape == (1,)))):
605-
# Array annotations should only be 1-dimensional
606-
continue
607-
if isinstance(attr_val, dict):
608-
# Dictionaries are not supported as array annotations
609-
continue
610569
array_annotations[attr_key] = attr_val
611-
del neo_attrs[attr_key]
570+
for key in array_annotations:
571+
del neo_attrs[key]
612572

613573
neo_spiketrain = SpikeTrain(times=times, array_annotations=array_annotations, **neo_attrs)
614574
if nix_mtag.features:

0 commit comments

Comments
 (0)