From 5976120e8961bf5785025d266ecb116b097f44eb Mon Sep 17 00:00:00 2001 From: Alp Erkent Date: Fri, 10 May 2024 17:42:47 -0400 Subject: [PATCH 1/2] Fix filtering in BIDSLayoutIndexer --- bids/layout/index.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bids/layout/index.py b/bids/layout/index.py index 2796e7aa..d3b23c4a 100644 --- a/bids/layout/index.py +++ b/bids/layout/index.py @@ -250,6 +250,9 @@ def _index_file(self, abs_fn, entities): m = e.match_file(bf) if m is None and e.mandatory: break + # Skip entities that don't match the filter + if self.filters and e.name and e.name in self.filters and m and m not in self.filters[e.name]: + continue if m is not None: match_vals[e.name] = (e, m) @@ -264,7 +267,7 @@ def _index_file(self, abs_fn, entities): def _index_metadata(self): """Index metadata for all files in the BIDS dataset. """ - filters = self.filters + filters = self.filters.copy() if self.filters else None if filters: # ensure we are returning objects From 9b9c74e905c064e0e1f04ffd1e93811175baef2b Mon Sep 17 00:00:00 2001 From: Alp Erkent Date: Wed, 22 May 2024 09:50:35 -0400 Subject: [PATCH 2/2] Update index.py Remove if clause on self.filters --- bids/layout/index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bids/layout/index.py b/bids/layout/index.py index d3b23c4a..6c083f8b 100644 --- a/bids/layout/index.py +++ b/bids/layout/index.py @@ -267,7 +267,7 @@ def _index_file(self, abs_fn, entities): def _index_metadata(self): """Index metadata for all files in the BIDS dataset. """ - filters = self.filters.copy() if self.filters else None + filters = self.filters.copy() if filters: # ensure we are returning objects