diff --git a/bids/layout/index.py b/bids/layout/index.py index 2796e7aa..6c083f8b 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 filters: # ensure we are returning objects