PersistentGraph#
- class PersistentGraph#
Bases:
GraphView
A temporal graph that allows edges and nodes to be deleted.
Methods:
add_constant_properties
(properties)Adds static properties to the graph.
add_edge
(timestamp, src, dst[, properties, ...])Adds a new edge with the given source and destination nodes and properties to the graph.
add_node
(timestamp, id[, properties, ...])Adds a new node with the given id and properties to the graph.
add_properties
(timestamp, properties[, ...])Adds properties to the graph.
cache
(path)Write PersistentGraph to cache file and initialise the cache.
create_node
(timestamp, id[, properties, ...])Creates a new node with the given id and properties to the graph.
delete_edge
(timestamp, src, dst[, layer, ...])Deletes an edge given the timestamp, src and dst nodes and layer (optional)
deserialise
(bytes)Load PersistentGraph from serialised bytes.
edge
(src, dst)Gets the edge with the specified source and destination nodes
Get event graph
Returns all the node types in the graph.
import_edge
(edge[, merge])Import a single edge into the graph.
import_edge_as
(edge, new_id[, merge])Import a single edge into the graph with new id.
import_edges
(edges[, merge])Import multiple edges into the graph.
import_edges_as
(edges, new_ids[, merge])Import multiple edges into the graph with new ids.
import_node
(node[, merge])Import a single node into the graph.
import_node_as
(node, new_id[, merge])Import a single node into the graph with new id.
import_nodes
(nodes[, merge])Import multiple nodes into the graph.
import_nodes_as
(nodes, new_ids[, merge])Import multiple nodes into the graph with new ids.
load_cached
(path)Load PersistentGraph from a file and initialise it as a cache file.
load_edge_deletions_from_pandas
(df, time, ...)Load edges deletions from a Pandas DataFrame into the graph.
load_edge_deletions_from_parquet
(...[, ...])Load edges deletions from a Parquet file into the graph.
load_edge_props_from_pandas
(df, src, dst[, ...])Load edge properties from a Pandas DataFrame.
load_edge_props_from_parquet
(parquet_path, ...)Load edge properties from parquet file
load_edges_from_pandas
(df, time, src, dst[, ...])Load edges from a Pandas DataFrame into the graph.
load_edges_from_parquet
(parquet_path, time, ...)Load edges from a Parquet file into the graph.
load_from_file
(path)Load PersistentGraph from a file.
load_node_props_from_pandas
(df, id[, ...])Load node properties from a Pandas DataFrame.
load_node_props_from_parquet
(parquet_path, id)Load node properties from a parquet file.
load_nodes_from_pandas
(df, time, id[, ...])Load nodes from a Pandas DataFrame into the graph.
load_nodes_from_parquet
(parquet_path, time, id)Load nodes from a Parquet file into the graph.
node
(id)Gets the node with the specified id
Get persistent graph
save_to_file
(path)Saves the PersistentGraph to the given path.
save_to_zip
(path)Saves the PersistentGraph to the given path.
Serialise PersistentGraph to bytes.
update_constant_properties
(properties)Updates static properties to the graph.
Persist the new updates by appending them to the cache file.
- add_constant_properties(properties)#
Adds static properties to the graph.
- add_edge(timestamp, src, dst, properties=None, layer=None, secondary_index=None)#
Adds a new edge with the given source and destination nodes and properties to the graph.
- Parameters:
- Returns:
This function does not return a value, if the operation is successful.
- Return type:
- Raises:
GraphError – If the operation fails.
- add_node(timestamp, id, properties=None, node_type=None, secondary_index=None)#
Adds a new node with the given id and properties to the graph.
- Parameters:
- Returns:
This function does not return a value, if the operation is successful.
- Return type:
- Raises:
GraphError – If the operation fails.
- add_properties(timestamp, properties, secondary_index=None)#
Adds properties to the graph.
- Parameters:
- Returns:
This function does not return a value, if the operation is successful.
- Return type:
- Raises:
GraphError – If the operation fails.
- cache(path)#
Write PersistentGraph to cache file and initialise the cache.
Future updates are tracked. Use write_updates to persist them to the cache file. If the file already exists its contents are overwritten.
- create_node(timestamp, id, properties=None, node_type=None, secondary_index=None)#
Creates a new node with the given id and properties to the graph. It fails if the node already exists.
- Parameters:
- Returns:
the newly created node.
- Return type:
- Raises:
GraphError – If the operation fails.
- delete_edge(timestamp, src, dst, layer=None, secondary_index=None)#
Deletes an edge given the timestamp, src and dst nodes and layer (optional)
- Parameters:
- Returns:
The deleted edge
- Return type:
- Raises:
GraphError – If the operation fails.
- static deserialise(bytes)#
Load PersistentGraph from serialised bytes.
- Parameters:
bytes (bytes) – The serialised bytes to decode
- Return type:
- edge(src, dst)#
Gets the edge with the specified source and destination nodes
- get_all_node_types()#
Returns all the node types in the graph.
- import_edge(edge, merge=False)#
Import a single edge into the graph.
This function takes an edge object and an optional boolean flag. If the flag is set to true, the function will merge the import of the edge even if it already exists in the graph.
- import_edge_as(edge, new_id, merge=False)#
Import a single edge into the graph with new id.
This function takes a edge object, a new edge id and an optional boolean flag. If the flag is set to true, the function will merge the import of the edge even if it already exists in the graph.
- Parameters:
- Returns:
The imported edge.
- Return type:
- Raises:
GraphError – If the operation fails.
- import_edges(edges, merge=False)#
Import multiple edges into the graph.
This function takes a vector of edge objects and an optional boolean flag. If the flag is set to true, the function will merge the import of the edges even if they already exist in the graph.
- Parameters:
- Returns:
This function does not return a value, if the operation is successful.
- Return type:
- Raises:
GraphError – If the operation fails.
- import_edges_as(edges, new_ids, merge=False)#
Import multiple edges into the graph with new ids.
This function takes a vector of edge objects, a list of new edge ids and an optional boolean flag. If the flag is set to true, the function will merge the import of the edges even if they already exist in the graph.
- Parameters:
- Returns:
This function does not return a value, if the operation is successful.
- Return type:
- Raises:
GraphError – If the operation fails.
- import_node(node, merge=False)#
Import a single node into the graph.
This function takes a node object and an optional boolean flag. If the flag is set to true, the function will merge the import of the node even if it already exists in the graph.
- Parameters:
- Returns:
A Node object if the node was successfully imported, and an error otherwise.
- Return type:
- Raises:
GraphError – If the operation fails.
- import_node_as(node, new_id, merge=False)#
Import a single node into the graph with new id.
This function takes a node object, a new node id and an optional boolean flag. If the flag is set to true, the function will merge the import of the node even if it already exists in the graph.
- Parameters:
- Returns:
A Node object if the node was successfully imported, and an error otherwise.
- Return type:
- Raises:
GraphError – If the operation fails.
- import_nodes(nodes, merge=False)#
Import multiple nodes into the graph.
This function takes a vector of node objects and an optional boolean flag. If the flag is set to true, the function will merge the import of the nodes even if they already exist in the graph.
- Parameters:
- Returns:
This function does not return a value, if the operation is successful.
- Return type:
- Raises:
GraphError – If the operation fails.
- import_nodes_as(nodes, new_ids, merge=False)#
Import multiple nodes into the graph with new ids.
This function takes a vector of node objects, a list of new node ids and an optional boolean flag. If the flag is set to true, the function will merge the import of the nodes even if they already exist in the graph.
- Parameters:
- Returns:
This function does not return a value, if the operation is successful.
- Return type:
- Raises:
GraphError – If the operation fails.
- static load_cached(path)#
Load PersistentGraph from a file and initialise it as a cache file.
Future updates are tracked. Use write_updates to persist them to the cache file.
- Parameters:
path (str) – The path to the cache file
- Returns:
the loaded graph with initialised cache
- Return type:
- load_edge_deletions_from_pandas(df, time, src, dst, layer=None, layer_col=None)#
Load edges deletions from a Pandas DataFrame into the graph.
- Parameters:
df (DataFrame) – The Pandas DataFrame containing the edges.
time (str) – The column name for the update timestamps.
src (str) – The column name for the source node ids.
dst (str) – The column name for the destination node ids.
layer (str, optional) – A constant value to use as the layer for all edges. Defaults to None. (cannot be used in combination with layer_col)
layer_col (str, optional) – The edge layer col name in dataframe. Defaults to None. (cannot be used in combination with layer)
- Returns:
This function does not return a value, if the operation is successful.
- Return type:
- Raises:
GraphError – If the operation fails.
- load_edge_deletions_from_parquet(parquet_path, time, src, dst, layer=None, layer_col=None)#
Load edges deletions from a Parquet file into the graph.
- Parameters:
parquet_path (str) – Parquet file or directory of Parquet files path containing node information.
src (str) – The column name for the source node ids.
dst (str) – The column name for the destination node ids.
time (str) – The column name for the update timestamps.
layer (str, optional) – A constant value to use as the layer for all edges. Defaults to None. (cannot be used in combination with layer_col)
layer_col (str, optional) – The edge layer col name in dataframe. Defaults to None. (cannot be used in combination with layer)
- Returns:
This function does not return a value, if the operation is successful.
- Return type:
- Raises:
GraphError – If the operation fails.
- load_edge_props_from_pandas(df, src, dst, constant_properties=None, shared_constant_properties=None, layer=None, layer_col=None)#
Load edge properties from a Pandas DataFrame.
- Parameters:
df (DataFrame) – The Pandas DataFrame containing edge information.
src (str) – The column name for the source node.
dst (str) – The column name for the destination node.
constant_properties (List[str], optional) – List of constant edge property column names. Defaults to None.
shared_constant_properties (PropInput, optional) – A dictionary of constant properties that will be added to every edge. Defaults to None.
layer (str, optional) – The edge layer name. Defaults to None.
layer_col (str, optional) – The edge layer col name in dataframe. Defaults to None.
- Returns:
This function does not return a value, if the operation is successful.
- Return type:
- Raises:
GraphError – If the operation fails.
- load_edge_props_from_parquet(parquet_path, src, dst, constant_properties=None, shared_constant_properties=None, layer=None, layer_col=None)#
Load edge properties from parquet file
- Parameters:
parquet_path (str) – Parquet file or directory of Parquet files path containing edge information.
src (str) – The column name for the source node.
dst (str) – The column name for the destination node.
constant_properties (List[str], optional) – List of constant edge property column names. Defaults to None.
shared_constant_properties (PropInput, optional) – A dictionary of constant properties that will be added to every edge. Defaults to None.
layer (str, optional) – The edge layer name. Defaults to None.
layer_col (str, optional) – The edge layer col name in dataframe. Defaults to None.
- Returns:
This function does not return a value, if the operation is successful.
- Return type:
- Raises:
GraphError – If the operation fails.
- load_edges_from_pandas(df, time, src, dst, properties=None, constant_properties=None, shared_constant_properties=None, layer=None, layer_col=None)#
Load edges from a Pandas DataFrame into the graph.
- Parameters:
df (DataFrame) – The Pandas DataFrame containing the edges.
time (str) – The column name for the update timestamps.
src (str) – The column name for the source node ids.
dst (str) – The column name for the destination node ids.
properties (List[str], optional) – List of edge property column names. Defaults to None.
constant_properties (List[str], optional) – List of constant edge property column names. Defaults to None.
shared_constant_properties (PropInput, optional) – A dictionary of constant properties that will be added to every edge. Defaults to None.
layer (str, optional) – A constant value to use as the layer for all edges. Defaults to None. (cannot be used in combination with layer_col)
layer_col (str, optional) – The edge layer col name in dataframe. Defaults to None. (cannot be used in combination with layer)
- Returns:
This function does not return a value, if the operation is successful.
- Return type:
- Raises:
GraphError – If the operation fails.
- load_edges_from_parquet(parquet_path, time, src, dst, properties=None, constant_properties=None, shared_constant_properties=None, layer=None, layer_col=None)#
Load edges from a Parquet file into the graph.
- Parameters:
parquet_path (str) – Parquet file or directory of Parquet files path containing edges
time (str) – The column name for the update timestamps.
src (str) – The column name for the source node ids.
dst (str) – The column name for the destination node ids.
properties (List[str], optional) – List of edge property column names. Defaults to None.
constant_properties (List[str], optional) – List of constant edge property column names. Defaults to None.
shared_constant_properties (PropInput, optional) – A dictionary of constant properties that will be added to every edge. Defaults to None.
layer (str, optional) – A constant value to use as the layer for all edges. Defaults to None. (cannot be used in combination with layer_col)
layer_col (str, optional) – The edge layer col name in dataframe. Defaults to None. (cannot be used in combination with layer)
- Returns:
This function does not return a value, if the operation is successful.
- Return type:
- Raises:
GraphError – If the operation fails.
- static load_from_file(path)#
Load PersistentGraph from a file.
- Parameters:
path (str) – The path to the file.
- Return type:
- load_node_props_from_pandas(df, id, node_type=None, node_type_col=None, constant_properties=None, shared_constant_properties=None)#
Load node properties from a Pandas DataFrame.
- Parameters:
df (DataFrame) – The Pandas DataFrame containing node information.
id (str) – The column name for the node IDs.
node_type (str, optional) – A constant value to use as the node type for all nodes. Defaults to None. (cannot be used in combination with node_type_col)
node_type_col (str, optional) – The node type col name in dataframe. Defaults to None. (cannot be used in combination with node_type)
constant_properties (List[str], optional) – List of constant node property column names. Defaults to None.
shared_constant_properties (PropInput, optional) – A dictionary of constant properties that will be added to every node. Defaults to None.
- Returns:
This function does not return a value, if the operation is successful.
- Return type:
- Raises:
GraphError – If the operation fails.
- load_node_props_from_parquet(parquet_path, id, node_type=None, node_type_col=None, constant_properties=None, shared_constant_properties=None)#
Load node properties from a parquet file.
- Parameters:
parquet_path (str) – Parquet file or directory of Parquet files path containing node information.
id (str) – The column name for the node IDs.
node_type (str, optional) – A constant value to use as the node type for all nodes. Defaults to None. (cannot be used in combination with node_type_col)
node_type_col (str, optional) – The node type col name in dataframe. Defaults to None. (cannot be used in combination with node_type)
constant_properties (List[str], optional) – List of constant node property column names. Defaults to None.
shared_constant_properties (PropInput, optional) – A dictionary of constant properties that will be added to every node. Defaults to None.
- Returns:
This function does not return a value, if the operation is successful.
- Return type:
- Raises:
GraphError – If the operation fails.
- load_nodes_from_pandas(df, time, id, node_type=None, node_type_col=None, properties=None, constant_properties=None, shared_constant_properties=None)#
Load nodes from a Pandas DataFrame into the graph.
- Parameters:
df (DataFrame) – The Pandas DataFrame containing the nodes.
time (str) – The column name for the timestamps.
id (str) – The column name for the node IDs.
node_type (str, optional) – A constant value to use as the node type for all nodes. Defaults to None. (cannot be used in combination with node_type_col)
node_type_col (str, optional) – The node type col name in dataframe. Defaults to None. (cannot be used in combination with node_type)
properties (List[str], optional) – List of node property column names. Defaults to None.
constant_properties (List[str], optional) – List of constant node property column names. Defaults to None.
shared_constant_properties (PropInput, optional) – A dictionary of constant properties that will be added to every node. Defaults to None.
- Returns:
This function does not return a value, if the operation is successful.
- Return type:
- Raises:
GraphError – If the operation fails.
- load_nodes_from_parquet(parquet_path, time, id, node_type=None, node_type_col=None, properties=None, constant_properties=None, shared_constant_properties=None)#
Load nodes from a Parquet file into the graph.
- Parameters:
parquet_path (str) – Parquet file or directory of Parquet files containing the nodes
time (str) – The column name for the timestamps.
id (str) – The column name for the node IDs.
node_type (str, optional) – A constant value to use as the node type for all nodes. Defaults to None. (cannot be used in combination with node_type_col)
node_type_col (str, optional) – The node type col name in dataframe. Defaults to None. (cannot be used in combination with node_type)
properties (List[str], optional) – List of node property column names. Defaults to None.
constant_properties (List[str], optional) – List of constant node property column names. Defaults to None.
shared_constant_properties (PropInput, optional) – A dictionary of constant properties that will be added to every node. Defaults to None.
- Returns:
This function does not return a value, if the operation is successful.
- Return type:
- Raises:
GraphError – If the operation fails.
- node(id)#
Gets the node with the specified id
- Parameters:
- Returns:
The node with the specified id, or None if the node does not exist
- Return type:
- persistent_graph()#
Get persistent graph
- Returns:
the graph with persistent semantics applied
- Return type:
- save_to_file(path)#
Saves the PersistentGraph to the given path.
- save_to_zip(path)#
Saves the PersistentGraph to the given path.
- update_constant_properties(properties)#
Updates static properties to the graph.