toolbox/nt/database/iterator.py
def filter(self, filter_fn, lazy=True):
        """
        The filter_fn consumes an example. If the filter_fn returns True, we
        keep the example. If it is False, we drop the example.

        Filtering examples. If using lazy=False this method should be called
        before applying expensive map functions.

        Syntax is inspired by:
        https://docs.python.org/3/library/functions.html#filter

        :param filter_fn: function to filter examples, takes example as input
            and returns True if example should be kept, else False.
        :param lazy: If True, iterator does not support `len(it)` anymore but
            computation is performed once the iterator visits the item.
        :return: FilterIterator iterating over filtered examples.
        """
        if lazy:
            # Input iterator can be indexable, but this is not needed.
            # Output still does not have `len` and is not indexable.
            return FilterIterator(filter_fn, self)
        else:
            # Input iterator needs to be indexable.
            # Output still has `len`, following line should not raise errors.
            try:
                _ = self.keys()
            except Exception:
                raise RuntimeError(
                    'You can only use lazy=False if the incoming iterator is '
                    'indexable.'
                )
            return self[[i for i, e in enumerate(self) if filter_fn(e)]]

        The filter_fn consumes an example. If the filter_fn returns True, we
        keep the example. If it is False, we drop the example.

        Filtering examples. If using lazy=False this method should be called
        before applying expensive map functions.

        Syntax is inspired by:
        https://docs.python.org/3/library/functions.html#filter

        :param filter_fn: function to filter examples, takes example as input
            and returns True if example should be kept, else False.
        :param lazy: If True, iterator does not support `len(it)` anymore but
            computation is performed once the iterator visits the item.
        :return: FilterIterator iterating over filtered examples.
        
The filter_fn consumes an example. If the filter_fn returns True, we
keep the example. If it is False, we drop the example.

Filtering examples. If using lazy=False this method should be called
before applying expensive map functions.


The filter_fn consumes an example . If the filter_fn returns True we keep the example . If it is False we drop the example . Filtering examples . If using lazy = False this method should be called before applying expensive map functions .
def filter(self, filter_fn, lazy=True):
        if lazy:
            return FilterIterator(filter_fn, self)
        else:
            try:
                _ = self.keys()
            except Exception:
                raise RuntimeError(
                    'You can only use lazy=False if the incoming iterator is '
                    'indexable.'
                )
            return self[[i for i, e in enumerate(self) if filter_fn(e)]]
def filter ( self , filter_fn , lazy = True ) : if lazy : return FilterIterator ( filter_fn , self ) else : try : _ = self . keys ( ) except Exception : raise RuntimeError ( 'You can only use lazy=False if the incoming iterator is ' 'indexable.' ) return self [ [ i for i , e in enumerate ( self ) if filter_fn ( e ) ] ]
The filter_fn consumes an example.
The filter_fn consumes an example .
"""
        The filter_fn consumes an example. If the filter_fn returns True, we
        keep the example. If it is False, we drop the example.

        Filtering examples. If using lazy=False this method should be called
        before applying expensive map functions.

        Syntax is inspired by:
        https://docs.python.org/3/library/functions.html#filter

        :param filter_fn: function to filter examples, takes example as input
            and returns True if example should be kept, else False.
        :param lazy: If True, iterator does not support `len(it)` anymore but
            computation is performed once the iterator visits the item.
        :return: FilterIterator iterating over filtered examples.
        """ # Input iterator can be indexable, but this is not needed. # Output still does not have `len` and is not indexable. # Input iterator needs to be indexable. # Output still has `len`, following line should not raise errors.
FilterIterator iterating over filtered examples.
FilterIterator iterating over filtered examples .
self
filter_fn
function to filter examples, takes example as input
and returns True if example should be kept, else False.
function to filter examples takes example as input and returns True if example should be kept else False .
lazy
If True, iterator does not support `len(it)` anymore but
computation is performed once the iterator visits the item.
If True iterator does not support ` len ( it ) ` anymore but computation is performed once the iterator visits the item .