hatchet/graphframe.py
def _insert_missing_rows(self, other):
        """Helper function to add rows that exist in other, but not in self.

        This returns a graphframe with a modified dataframe. The new rows will
        contain zeros for numeric columns.

        Return:
            (GraphFrame): self's modified graphframe
        """
        all_metrics = list(
            set().union(
                self.exc_metrics, self.inc_metrics, other.exc_metrics, other.inc_metrics
            )
        )

        # get nodes that exist in other, but not in self, set metric columns to 0 for
        # these rows
        other_not_in_self = other.dataframe[
            ~other.dataframe.index.isin(self.dataframe.index)
        ]
        # get nodes that exist in self, but not in other
        self_not_in_other = self.dataframe[
            ~self.dataframe.index.isin(other.dataframe.index)
        ]

        # if there are missing nodes in either self or other, add a new column
        # called _missing_node
        if not self_not_in_other.empty:
            new_df = pd.DataFrame(index=self.dataframe.index)
            new_df["_missing_node"] = ""
            self.dataframe = self.dataframe.join(new_df)
        if not other_not_in_self.empty:
            new_df = pd.DataFrame(index=other_not_in_self.index)
            new_df["_missing_node"] = ""
            other_not_in_self = other_not_in_self.join(new_df)

            # add a new column to self if other has nodes not in self
            if self_not_in_other.empty:
                new_df = pd.DataFrame(index=self.dataframe.index)
                new_df["_missing_node"] = ""
                self.dataframe = self.dataframe.join(new_df)

        # for nodes that only exist in self, set value to be "L" indicating
        # it exists in left graphframe
        for i in self_not_in_other.index:
            # a value of L indicates that the node exists in self, but not other
            self.dataframe.at[i, "_missing_node"] = "L"

        # for nodes that only exist in other, set the metric to be 0 (since
        # it's a missing node in sel), and set value of _missing_node to be "R"
        # indicating it exists in right graphframe
        for i in other_not_in_self.index:
            for j in all_metrics:
                other_not_in_self.at[i, j] = 0
            # a value of R indicates that the node exists in other, but not self
            other_not_in_self.at[i, "_missing_node"] = "R"

        # append missing rows (nodes that exist in other, but not self) to self's
        # dataframe
        self.dataframe = self.dataframe.append(other_not_in_self, sort=True)

        return self
Helper function to add rows that exist in other, but not in self.

        This returns a graphframe with a modified dataframe. The new rows will
        contain zeros for numeric columns.

        Return:
            (GraphFrame): self's modified graphframe
        
Helper function to add rows that exist in other, but not in self.
This returns a graphframe with a modified dataframe. The new rows will
contain zeros for numeric columns.

self's modified graphframe
Helper function to add rows that exist in other but not in self . This returns a graphframe with a modified dataframe . The new rows will contain zeros for numeric columns . self ' s modified graphframe
def _insert_missing_rows(self, other):
        all_metrics = list(
            set().union(
                self.exc_metrics, self.inc_metrics, other.exc_metrics, other.inc_metrics
            )
        )
        other_not_in_self = other.dataframe[
            ~other.dataframe.index.isin(self.dataframe.index)
        ]
        self_not_in_other = self.dataframe[
            ~self.dataframe.index.isin(other.dataframe.index)
        ]
        if not self_not_in_other.empty:
            new_df = pd.DataFrame(index=self.dataframe.index)
            new_df["_missing_node"] = ""
            self.dataframe = self.dataframe.join(new_df)
        if not other_not_in_self.empty:
            new_df = pd.DataFrame(index=other_not_in_self.index)
            new_df["_missing_node"] = ""
            other_not_in_self = other_not_in_self.join(new_df)
            if self_not_in_other.empty:
                new_df = pd.DataFrame(index=self.dataframe.index)
                new_df["_missing_node"] = ""
                self.dataframe = self.dataframe.join(new_df)
        for i in self_not_in_other.index:
            self.dataframe.at[i, "_missing_node"] = "L"
        for i in other_not_in_self.index:
            for j in all_metrics:
                other_not_in_self.at[i, j] = 0
            other_not_in_self.at[i, "_missing_node"] = "R"
        self.dataframe = self.dataframe.append(other_not_in_self, sort=True)
        return self
def _insert_missing_rows ( self , other ) : all_metrics = list ( set ( ) . union ( self . exc_metrics , self . inc_metrics , other . exc_metrics , other . inc_metrics ) ) other_not_in_self = other . dataframe [ ~ other . dataframe . index . isin ( self . dataframe . index ) ] self_not_in_other = self . dataframe [ ~ self . dataframe . index . isin ( other . dataframe . index ) ] if not self_not_in_other . empty : new_df = pd . DataFrame ( index = self . dataframe . index ) new_df [ "_missing_node" ] = "" self . dataframe = self . dataframe . join ( new_df ) if not other_not_in_self . empty : new_df = pd . DataFrame ( index = other_not_in_self . index ) new_df [ "_missing_node" ] = "" other_not_in_self = other_not_in_self . join ( new_df ) if self_not_in_other . empty : new_df = pd . DataFrame ( index = self . dataframe . index ) new_df [ "_missing_node" ] = "" self . dataframe = self . dataframe . join ( new_df ) for i in self_not_in_other . index : self . dataframe . at [ i , "_missing_node" ] = "L" for i in other_not_in_self . index : for j in all_metrics : other_not_in_self . at [ i , j ] = 0 other_not_in_self . at [ i , "_missing_node" ] = "R" self . dataframe = self . dataframe . append ( other_not_in_self , sort = True ) return self
Helper function to add rows that exist in other, but not in self.
Helper function to add rows that exist in other but not in self .
"""Helper function to add rows that exist in other, but not in self.

        This returns a graphframe with a modified dataframe. The new rows will
        contain zeros for numeric columns.

        Return:
            (GraphFrame): self's modified graphframe
        """ # get nodes that exist in other, but not in self, set metric columns to 0 for # these rows # get nodes that exist in self, but not in other # if there are missing nodes in either self or other, add a new column # called _missing_node # add a new column to self if other has nodes not in self # for nodes that only exist in self, set value to be "L" indicating # it exists in left graphframe # a value of L indicates that the node exists in self, but not other # for nodes that only exist in other, set the metric to be 0 (since # it's a missing node in sel), and set value of _missing_node to be "R" # indicating it exists in right graphframe # a value of R indicates that the node exists in other, but not self # append missing rows (nodes that exist in other, but not self) to self's # dataframe
self
other