hatchet/graphframe.py
def subgraph_sum(self, columns, out_columns=None, function=np.sum):
        """Compute sum of elements in subgraphs.

        For each row in the graph, ``out_columns`` will contain the
        element-wise sum of all values in ``columns`` for that row's node
        and all of its descendants.

        This algorithm is worst-case quadratic in the size of the graph,
        so we try to call ``subtree_sum`` if we can.  In general, there
        is not a particularly efficient algorithm known for subgraph
        sums, so this does about as well as we know how.

        Arguments:
            columns (list of str):  names of columns to sum (default: all columns)
            out_columns (list of str): names of columns to store results
                (default: in place)
            function (callable): associative operator used to sum
                elements (default: sum)
        """
        if self.graph.is_tree():
            self.subtree_sum(columns, out_columns, function)
            return

        out_columns = self._init_sum_columns(columns, out_columns)
        for node in self.graph.traverse():
            subgraph_nodes = list(node.traverse())
            # TODO: need a better way of aggregating inclusive metrics when
            # TODO: there is a multi-index
            try:
                is_index_or_multiindex = isinstance(
                    self.dataframe.index, pd.core.index.MultiIndex
                )
            except AttributeError:
                is_index_or_multiindex = isinstance(self.dataframe.index, pd.MultiIndex)

            if is_index_or_multiindex:
                for i in self.dataframe.loc[(node), out_columns].index.unique():
                    # TODO: if you take the list constructor away from the
                    # TODO: assignment below, this assignment gives NaNs. Why?
                    self.dataframe.loc[(node, i), out_columns] = list(
                        function(self.dataframe.loc[(subgraph_nodes, i), columns])
                    )
            else:
                # TODO: if you take the list constructor away from the
                # TODO: assignment below, this assignment gives NaNs. Why?
                self.dataframe.loc[(node), out_columns] = list(
                    function(self.dataframe.loc[(subgraph_nodes), columns])
                )
Compute sum of elements in subgraphs.

        For each row in the graph, ``out_columns`` will contain the
        element-wise sum of all values in ``columns`` for that row's node
        and all of its descendants.

        This algorithm is worst-case quadratic in the size of the graph,
        so we try to call ``subtree_sum`` if we can.  In general, there
        is not a particularly efficient algorithm known for subgraph
        sums, so this does about as well as we know how.

        Arguments:
            columns (list of str):  names of columns to sum (default: all columns)
            out_columns (list of str): names of columns to store results
                (default: in place)
            function (callable): associative operator used to sum
                elements (default: sum)
        
Compute sum of elements in subgraphs.

This algorithm is worst-case quadratic in the size of the graph,
so we try to call ``subtree_sum`` if we can.  In general, there
is not a particularly efficient algorithm known for subgraph
sums, so this does about as well as we know how.
Compute sum of elements in subgraphs . This algorithm is worst - case quadratic in the size of the graph so we try to call ` ` subtree_sum ` ` if we can . In general there is not a particularly efficient algorithm known for subgraph sums so this does about as well as we know how .
def subgraph_sum(self, columns, out_columns=None, function=np.sum):
        if self.graph.is_tree():
            self.subtree_sum(columns, out_columns, function)
            return
        out_columns = self._init_sum_columns(columns, out_columns)
        for node in self.graph.traverse():
            subgraph_nodes = list(node.traverse())
            try:
                is_index_or_multiindex = isinstance(
                    self.dataframe.index, pd.core.index.MultiIndex
                )
            except AttributeError:
                is_index_or_multiindex = isinstance(self.dataframe.index, pd.MultiIndex)
            if is_index_or_multiindex:
                for i in self.dataframe.loc[(node), out_columns].index.unique():
                    self.dataframe.loc[(node, i), out_columns] = list(
                        function(self.dataframe.loc[(subgraph_nodes, i), columns])
                    )
            else:
                self.dataframe.loc[(node), out_columns] = list(
                    function(self.dataframe.loc[(subgraph_nodes), columns])
                )
def subgraph_sum ( self , columns , out_columns = None , function = np . sum ) : if self . graph . is_tree ( ) : self . subtree_sum ( columns , out_columns , function ) return out_columns = self . _init_sum_columns ( columns , out_columns ) for node in self . graph . traverse ( ) : subgraph_nodes = list ( node . traverse ( ) ) try : is_index_or_multiindex = isinstance ( self . dataframe . index , pd . core . index . MultiIndex ) except AttributeError : is_index_or_multiindex = isinstance ( self . dataframe . index , pd . MultiIndex ) if is_index_or_multiindex : for i in self . dataframe . loc [ ( node ) , out_columns ] . index . unique ( ) : self . dataframe . loc [ ( node , i ) , out_columns ] = list ( function ( self . dataframe . loc [ ( subgraph_nodes , i ) , columns ] ) ) else : self . dataframe . loc [ ( node ) , out_columns ] = list ( function ( self . dataframe . loc [ ( subgraph_nodes ) , columns ] ) )
Compute sum of elements in subgraphs.
Compute sum of elements in subgraphs .
"""Compute sum of elements in subgraphs.

        For each row in the graph, ``out_columns`` will contain the
        element-wise sum of all values in ``columns`` for that row's node
        and all of its descendants.

        This algorithm is worst-case quadratic in the size of the graph,
        so we try to call ``subtree_sum`` if we can.  In general, there
        is not a particularly efficient algorithm known for subgraph
        sums, so this does about as well as we know how.

        Arguments:
            columns (list of str):  names of columns to sum (default: all columns)
            out_columns (list of str): names of columns to store results
                (default: in place)
            function (callable): associative operator used to sum
                elements (default: sum)
        """ # TODO: need a better way of aggregating inclusive metrics when # TODO: there is a multi-index # TODO: if you take the list constructor away from the # TODO: assignment below, this assignment gives NaNs. Why? # TODO: if you take the list constructor away from the # TODO: assignment below, this assignment gives NaNs. Why?
self
columns
names of columns to sum (default: all columns)
names of columns to sum ( default : all columns )
out_columns
names of columns to store results
(default: in place)
names of columns to store results ( default : in place )
function
associative operator used to sum
elements (default: sum)
associative operator used to sum elements ( default : sum )