Skip to content

Commit dedfc1b

Browse files
author
Moritz-Alexander-Kern
committed
fix typo and refactor filterdata
1 parent 9c30bde commit dedfc1b

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

neo/core/container.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def filterdata(data, targdict=None, objects=None, **kwargs):
3737
be a list of dictionaries, in which case the filters are applied
3838
sequentially.
3939
40-
A list of disctionaries is handled as follows: [ { or } and { or } ]
40+
A list of dictionaries is handled as follows: [ { or } and { or } ]
4141
If targdict and kwargs are both supplied, the
4242
targdict filters are applied first, followed by the kwarg filters.
4343
A targdict of None or {} corresponds to no filters applied, therefore
@@ -75,28 +75,31 @@ def filterdata(data, targdict=None, objects=None, **kwargs):
7575
else:
7676
# do the actual filtering
7777
results = []
78-
for key, value in sorted(targdict.items()):
79-
for obj in data:
80-
if (hasattr(obj, key) and getattr(obj, key) == value):
81-
results.append(obj)
82-
if (isinstance(value, filters.FilterCondition)) and (
83-
key in obj.annotations and value.evaluate(obj.annotations[key])):
78+
for obj in data:
79+
for key, value in sorted(targdict.items()):
80+
if hasattr(obj, key) and getattr(obj, key) == value:
8481
results.append(obj)
82+
break
83+
if isinstance(value, filters.FilterCondition) and key in obj.annotations:
84+
if value.evaluate(obj.annotations[key]):
85+
results.append(obj)
86+
break
8587
if key in obj.annotations and obj.annotations[key] == value:
8688
results.append(obj)
89+
break
8790

8891
# remove duplicates from results
89-
res = list({ id(res): res for res in results }.values())
92+
results = list({ id(res): res for res in results }.values())
9093

9194
# keep only objects of the correct classes
9295
if objects:
93-
res = [result for result in res if
96+
results = [result for result in results if
9497
result.__class__ in objects or result.__class__.__name__ in objects]
9598

96-
if res and all(isinstance(obj, SpikeTrain) for obj in res):
97-
return SpikeTrainList(res)
98-
99-
return res
99+
if results and all(isinstance(obj, SpikeTrain) for obj in results):
100+
return SpikeTrainList(results)
101+
else:
102+
return results
100103

101104

102105
class Container(BaseNeo):

0 commit comments

Comments
 (0)