@@ -37,7 +37,7 @@ def filterdata(data, targdict=None, objects=None, **kwargs):
37
37
be a list of dictionaries, in which case the filters are applied
38
38
sequentially.
39
39
40
- A list of disctionaries is handled as follows: [ { or } and { or } ]
40
+ A list of dictionaries is handled as follows: [ { or } and { or } ]
41
41
If targdict and kwargs are both supplied, the
42
42
targdict filters are applied first, followed by the kwarg filters.
43
43
A targdict of None or {} corresponds to no filters applied, therefore
@@ -75,28 +75,31 @@ def filterdata(data, targdict=None, objects=None, **kwargs):
75
75
else :
76
76
# do the actual filtering
77
77
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 :
84
81
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
85
87
if key in obj .annotations and obj .annotations [key ] == value :
86
88
results .append (obj )
89
+ break
87
90
88
91
# 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 ())
90
93
91
94
# keep only objects of the correct classes
92
95
if objects :
93
- res = [result for result in res if
96
+ results = [result for result in results if
94
97
result .__class__ in objects or result .__class__ .__name__ in objects ]
95
98
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
100
103
101
104
102
105
class Container (BaseNeo ):
0 commit comments