Skip to content

Commit efa9390

Browse files
committed
delegate filter combination to _Filters.compose_with
1 parent 89da83f commit efa9390

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/stagpy/stagyydata.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,14 @@ def passes(self, step: Step) -> bool:
510510
return False
511511
return all(func(step) for func in self.funcs)
512512

513+
def compose_with(self, other: _Filters) -> _Filters:
514+
return _Filters(
515+
snap=self.snap or other.snap,
516+
rprofs=self.rprofs or other.rprofs,
517+
fields=self.fields | other.fields,
518+
funcs=self.funcs + other.funcs,
519+
)
520+
513521

514522
class StepsView:
515523
"""Filtered iterator over steps or snaps.
@@ -597,12 +605,13 @@ def filter(
597605
Returns:
598606
self.
599607
"""
600-
self._flt.snap = self._flt.snap or snap
601-
self._flt.rprofs = self._flt.rprofs or rprofs
602-
if fields is not None:
603-
self._flt.fields = self._flt.fields.union(fields)
604-
if func is not None:
605-
self._flt.funcs.append(func)
608+
new_filters = _Filters(
609+
snap=snap,
610+
rprofs=rprofs,
611+
fields=set() if fields is None else set(fields),
612+
funcs=[] if func is None else [func],
613+
)
614+
self._flt = self._flt.compose_with(new_filters)
606615
return self
607616

608617
def __iter__(self) -> Iterator[Step]:

0 commit comments

Comments
 (0)