def filter(self, func, dropna=True, *args, **kwargs):  # noqa
        if isinstance(func, compat.string_types):
            wrapper = lambda x: getattr(x, func)(*args, **kwargs)
        else:
            wrapper = lambda x: func(x, *args, **kwargs)

        # Interpret np.nan as False.
        def true_and_notnull(x, *args, **kwargs):
            b = wrapper(x, *args, **kwargs)
            return b and notnull(b)

        try:
            indices = [self._get_index(name) for name, group in self
                       if true_and_notnull(group)]
        except ValueError:
            raise TypeError("the filter must return a boolean result")
        except TypeError:
            raise TypeError("the filter must return a boolean result")

        filtered = self._apply_filter(indices, dropna)
        return filtered
Return a copy of a Series excluding elements from groups that
dataset/ETHPy150Open pydata/pandas/pandas/core/groupby.py/SeriesGroupBy.filter