graphit/graph.py
def copy(self, deep=True, copy_view=False):
        """
        Return a (deep) copy of the graph

        The copy method offers shallow and deep copy functionality for graphs
        similar to Pythons building copy and deepcopy functions.

        A shallow copy (python `copy`) will copy the class and its attributes
        except for the nodes, edges, orm and origin objects that are referenced.
        As such the copy will not be independent from the source Graph.

        Using deep=True, a deep copy (python `deepcopy`) will be returned that
        is a new and fully independent copy of the source Graph.
        A new graph with only those nodes and edges represented by the node and
        edge 'views' will be returned by default. Setting the `copy_view`
        attribute to True will copy the full nodes and edges data set of the
        origin graph together with the views to the new graph.
        
        :param deep:        return a deep copy of the Graph object
        :type deep:         :py:bool
        :param copy_view:   make a deep copy of the full nodes and edges
                            dictionary and set any 'views'. Otherwise, only make
                            a deep copy of the 'view' state.
        :type copy_view:    :py:bool
        
        :return:            copy of the graph
        :rtype:             Graph object
        """
        
        # Make a new instance of the current class
        base_cls = self._get_class_object()

        # Make a deep copy
        if deep:
            class_copy = base_cls()

            # Copy nodes
            class_copy.nodes.update(copy.deepcopy(self.nodes.to_dict(return_full=copy_view)))
            if copy_view and self.nodes.is_view:
                class_copy.nodes.set_view(self.nodes.keys())

            # Copy edges
            class_copy.edges.update(copy.deepcopy(self.edges.to_dict(return_full=copy_view)))
            if copy_view and self.edges.is_view:
                class_copy.edges.set_view(self.edges.keys())

            # Copy ORM
            class_copy.orm.node_mapping.update(copy.deepcopy(self.orm.node_mapping.to_dict()))
            class_copy.orm.node_mapping.update(copy.deepcopy(self.orm.edge_mapping.to_dict()))

        # Make a shallow copy
        else:
            class_copy = base_cls(nodes=self.nodes, edges=self.edges, orm=self.orm)
            class_copy.origin = self.origin

        # Copy class attributes except fixed
        for key in self.__slots__:
            if key not in ('edges', 'nodes', 'adjacency', 'origin', 'orm', '__weakref__'):
                setattr(class_copy, key, copy.deepcopy(getattr(self, key)))
        
        # Reset the graph root if needed
        if class_copy.root and class_copy.root not in class_copy.nodes:
            class_copy.root = min(class_copy.nodes)
            logger.debug('Reset graph root to {0}'.format(class_copy.root))
        
        logger.debug(
            'Return {0} copy of graph {1}'.format('deep' if deep else 'shallow', repr(self)))
        
        return class_copy

        Return a (deep) copy of the graph

        The copy method offers shallow and deep copy functionality for graphs
        similar to Pythons building copy and deepcopy functions.

        A shallow copy (python `copy`) will copy the class and its attributes
        except for the nodes, edges, orm and origin objects that are referenced.
        As such the copy will not be independent from the source Graph.

        Using deep=True, a deep copy (python `deepcopy`) will be returned that
        is a new and fully independent copy of the source Graph.
        A new graph with only those nodes and edges represented by the node and
        edge 'views' will be returned by default. Setting the `copy_view`
        attribute to True will copy the full nodes and edges data set of the
        origin graph together with the views to the new graph.
        
        :param deep:        return a deep copy of the Graph object
        :type deep:         :py:bool
        :param copy_view:   make a deep copy of the full nodes and edges
                            dictionary and set any 'views'. Otherwise, only make
                            a deep copy of the 'view' state.
        :type copy_view:    :py:bool
        
        :return:            copy of the graph
        :rtype:             Graph object
        
Return a (deep) copy of the graph
The copy method offers shallow and deep copy functionality for graphs
similar to Pythons building copy and deepcopy functions.

A shallow copy (python `copy`) will copy the class and its attributes
except for the nodes, edges, orm and origin objects that are referenced.
As such the copy will not be independent from the source Graph.

Using deep=True, a deep copy (python `deepcopy`) will be returned that
is a new and fully independent copy of the source Graph.
A new graph with only those nodes and edges represented by the node and
edge 'views' will be returned by default. Setting the `copy_view`
attribute to True will copy the full nodes and edges data set of the
origin graph together with the views to the new graph.
Return a ( deep ) copy of the graph The copy method offers shallow and deep copy functionality for graphs similar to Pythons building copy and deepcopy functions . A shallow copy ( python ` copy ` ) will copy the class and its attributes except for the nodes edges orm and origin objects that are referenced . As such the copy will not be independent from the source Graph . Using deep = True a deep copy ( python ` deepcopy ` ) will be returned that is a new and fully independent copy of the source Graph . A new graph with only those nodes and edges represented by the node and edge ' views ' will be returned by default . Setting the ` copy_view ` attribute to True will copy the full nodes and edges data set of the origin graph together with the views to the new graph .
def copy(self, deep=True, copy_view=False):
        base_cls = self._get_class_object()
        if deep:
            class_copy = base_cls()
            class_copy.nodes.update(copy.deepcopy(self.nodes.to_dict(return_full=copy_view)))
            if copy_view and self.nodes.is_view:
                class_copy.nodes.set_view(self.nodes.keys())
            class_copy.edges.update(copy.deepcopy(self.edges.to_dict(return_full=copy_view)))
            if copy_view and self.edges.is_view:
                class_copy.edges.set_view(self.edges.keys())
            class_copy.orm.node_mapping.update(copy.deepcopy(self.orm.node_mapping.to_dict()))
            class_copy.orm.node_mapping.update(copy.deepcopy(self.orm.edge_mapping.to_dict()))
        else:
            class_copy = base_cls(nodes=self.nodes, edges=self.edges, orm=self.orm)
            class_copy.origin = self.origin
        for key in self.__slots__:
            if key not in ('edges', 'nodes', 'adjacency', 'origin', 'orm', '__weakref__'):
                setattr(class_copy, key, copy.deepcopy(getattr(self, key)))
        if class_copy.root and class_copy.root not in class_copy.nodes:
            class_copy.root = min(class_copy.nodes)
            logger.debug('Reset graph root to {0}'.format(class_copy.root))
        logger.debug(
            'Return {0} copy of graph {1}'.format('deep' if deep else 'shallow', repr(self)))
        return class_copy
def copy ( self , deep = True , copy_view = False ) : base_cls = self . _get_class_object ( ) if deep : class_copy = base_cls ( ) class_copy . nodes . update ( copy . deepcopy ( self . nodes . to_dict ( return_full = copy_view ) ) ) if copy_view and self . nodes . is_view : class_copy . nodes . set_view ( self . nodes . keys ( ) ) class_copy . edges . update ( copy . deepcopy ( self . edges . to_dict ( return_full = copy_view ) ) ) if copy_view and self . edges . is_view : class_copy . edges . set_view ( self . edges . keys ( ) ) class_copy . orm . node_mapping . update ( copy . deepcopy ( self . orm . node_mapping . to_dict ( ) ) ) class_copy . orm . node_mapping . update ( copy . deepcopy ( self . orm . edge_mapping . to_dict ( ) ) ) else : class_copy = base_cls ( nodes = self . nodes , edges = self . edges , orm = self . orm ) class_copy . origin = self . origin for key in self . __slots__ : if key not in ( 'edges' , 'nodes' , 'adjacency' , 'origin' , 'orm' , '__weakref__' ) : setattr ( class_copy , key , copy . deepcopy ( getattr ( self , key ) ) ) if class_copy . root and class_copy . root not in class_copy . nodes : class_copy . root = min ( class_copy . nodes ) logger . debug ( 'Reset graph root to {0}' . format ( class_copy . root ) ) logger . debug ( 'Return {0} copy of graph {1}' . format ( 'deep' if deep else 'shallow' , repr ( self ) ) ) return class_copy
Return a (deep) copy of the graph
The copy method offers shallow and deep copy functionality for graphs
similar to Pythons building copy and deepcopy functions.
Return a ( deep ) copy of the graph The copy method offers shallow and deep copy functionality for graphs similar to Pythons building copy and deepcopy functions .
"""
        Return a (deep) copy of the graph

        The copy method offers shallow and deep copy functionality for graphs
        similar to Pythons building copy and deepcopy functions.

        A shallow copy (python `copy`) will copy the class and its attributes
        except for the nodes, edges, orm and origin objects that are referenced.
        As such the copy will not be independent from the source Graph.

        Using deep=True, a deep copy (python `deepcopy`) will be returned that
        is a new and fully independent copy of the source Graph.
        A new graph with only those nodes and edges represented by the node and
        edge 'views' will be returned by default. Setting the `copy_view`
        attribute to True will copy the full nodes and edges data set of the
        origin graph together with the views to the new graph.
        
        :param deep:        return a deep copy of the Graph object
        :type deep:         :py:bool
        :param copy_view:   make a deep copy of the full nodes and edges
                            dictionary and set any 'views'. Otherwise, only make
                            a deep copy of the 'view' state.
        :type copy_view:    :py:bool
        
        :return:            copy of the graph
        :rtype:             Graph object
        """ # Make a new instance of the current class # Make a deep copy # Copy nodes # Copy edges # Copy ORM # Make a shallow copy # Copy class attributes except fixed # Reset the graph root if needed
copy of the graph
copy of the graph
Graph object
self
deep
return a deep copy of the Graph object
return a deep copy of the Graph object
copy_view
make a deep copy of the full nodes and edges
dictionary and set any 'views'. Otherwise, only make
a deep copy of the 'view' state.
make a deep copy of the full nodes and edges dictionary and set any ' views ' . Otherwise only make a deep copy of the ' view ' state .