hatchet/graphframe.py
def filter(self, filter_obj, squash=False):
        """Filter the dataframe using a user-supplied function.

        Arguments:
            filter_obj (callable, list, or QueryMatcher): the filter to apply to the GraphFrame.
            squash (boolean, optional): if True, automatically call squash for the user.
        """
        dataframe_copy = self.dataframe.copy()

        index_names = self.dataframe.index.names
        dataframe_copy.reset_index(inplace=True)

        filtered_df = None

        if callable(filter_obj):
            filtered_rows = dataframe_copy.apply(filter_obj, axis=1)
            filtered_df = dataframe_copy[filtered_rows]
        elif isinstance(filter_obj, list) or isinstance(filter_obj, QueryMatcher):
            query = filter_obj
            if isinstance(filter_obj, list):
                query = QueryMatcher(filter_obj)
            query_matches = query.apply(self)
            match_set = list(set().union(*query_matches))
            filtered_df = dataframe_copy.loc[dataframe_copy["node"].isin(match_set)]
        else:
            raise InvalidFilter(
                "The argument passed to filter must be a callable, a query path list, or a QueryMatcher object."
            )

        if filtered_df.shape[0] == 0:
            raise EmptyFilter(
                "The provided filter would have produced an empty GraphFrame."
            )

        filtered_df.set_index(index_names, inplace=True)

        filtered_gf = GraphFrame(self.graph, filtered_df)
        filtered_gf.exc_metrics = self.exc_metrics
        filtered_gf.inc_metrics = self.inc_metrics

        if squash:
            return filtered_gf.squash()
        return filtered_gf
Filter the dataframe using a user-supplied function.

        Arguments:
            filter_obj (callable, list, or QueryMatcher): the filter to apply to the GraphFrame.
            squash (boolean, optional): if True, automatically call squash for the user.
        
Filter the dataframe using a user-supplied function.
Filter the dataframe using a user - supplied function .
def filter(self, filter_obj, squash=False):
        dataframe_copy = self.dataframe.copy()
        index_names = self.dataframe.index.names
        dataframe_copy.reset_index(inplace=True)
        filtered_df = None
        if callable(filter_obj):
            filtered_rows = dataframe_copy.apply(filter_obj, axis=1)
            filtered_df = dataframe_copy[filtered_rows]
        elif isinstance(filter_obj, list) or isinstance(filter_obj, QueryMatcher):
            query = filter_obj
            if isinstance(filter_obj, list):
                query = QueryMatcher(filter_obj)
            query_matches = query.apply(self)
            match_set = list(set().union(*query_matches))
            filtered_df = dataframe_copy.loc[dataframe_copy["node"].isin(match_set)]
        else:
            raise InvalidFilter(
                "The argument passed to filter must be a callable, a query path list, or a QueryMatcher object."
            )
        if filtered_df.shape[0] == 0:
            raise EmptyFilter(
                "The provided filter would have produced an empty GraphFrame."
            )
        filtered_df.set_index(index_names, inplace=True)
        filtered_gf = GraphFrame(self.graph, filtered_df)
        filtered_gf.exc_metrics = self.exc_metrics
        filtered_gf.inc_metrics = self.inc_metrics
        if squash:
            return filtered_gf.squash()
        return filtered_gf
def filter ( self , filter_obj , squash = False ) : dataframe_copy = self . dataframe . copy ( ) index_names = self . dataframe . index . names dataframe_copy . reset_index ( inplace = True ) filtered_df = None if callable ( filter_obj ) : filtered_rows = dataframe_copy . apply ( filter_obj , axis = 1 ) filtered_df = dataframe_copy [ filtered_rows ] elif isinstance ( filter_obj , list ) or isinstance ( filter_obj , QueryMatcher ) : query = filter_obj if isinstance ( filter_obj , list ) : query = QueryMatcher ( filter_obj ) query_matches = query . apply ( self ) match_set = list ( set ( ) . union ( * query_matches ) ) filtered_df = dataframe_copy . loc [ dataframe_copy [ "node" ] . isin ( match_set ) ] else : raise InvalidFilter ( "The argument passed to filter must be a callable, a query path list, or a QueryMatcher object." ) if filtered_df . shape [ 0 ] == 0 : raise EmptyFilter ( "The provided filter would have produced an empty GraphFrame." ) filtered_df . set_index ( index_names , inplace = True ) filtered_gf = GraphFrame ( self . graph , filtered_df ) filtered_gf . exc_metrics = self . exc_metrics filtered_gf . inc_metrics = self . inc_metrics if squash : return filtered_gf . squash ( ) return filtered_gf
Filter the dataframe using a user-supplied function.
Filter the dataframe using a user - supplied function .
"""Filter the dataframe using a user-supplied function.

        Arguments:
            filter_obj (callable, list, or QueryMatcher): the filter to apply to the GraphFrame.
            squash (boolean, optional): if True, automatically call squash for the user.
        """
self
filter_obj
the filter to apply to the GraphFrame.
the filter to apply to the GraphFrame .
squash
if True, automatically call squash for the user.
if True automatically call squash for the user .