graphrecords.graphrecord.GraphRecord#

class GraphRecord[source]#

Bases: object

An immutable record of nodes, edges and the groups they belong to.

__init__()[source]#

Initializes an empty GraphRecord.

Methods

__init__()

Initializes an empty GraphRecord.

add_edge(source_node_index, ...)

Adds a single edge with the given attributes.

add_edge_in_group(source_node_index, ...)

Adds a single edge with the given attributes to a group.

add_edges(source)

Adds the edges of the given source.

add_edges_in_group(source, group_index)

Adds the edges of the given source to a group.

add_edges_to_group(edge_indices, group_index)

Adds the selected edges to a group.

add_group(group_index)

Adds an empty group.

add_node(node_index, attributes)

Adds a single node with the given attributes.

add_node_in_group(node_index, attributes, ...)

Adds a single node with the given attributes to a group.

add_nodes(source)

Adds the nodes of the given source.

add_nodes_in_group(source, group_index)

Adds the nodes of the given source to a group.

add_nodes_to_group(node_indices, group_index)

Adds the selected nodes to a group.

add_plugin(name, plugin)

Attaches a plugin under the given name.

clear()

Removes all nodes, edges and groups, keeping the schema and the plugins.

compact()

Reclaims the space that removed nodes and edges still occupy.

contains_edge(edge_index)

Checks whether the GraphRecord holds an edge with the given index.

contains_group(group_index)

Checks whether the GraphRecord holds a group with the given index.

contains_node(node_index)

Checks whether the GraphRecord holds a node with the given index.

difference(other)

Removes everything the other GraphRecord also holds.

edge(edge_index)

Views a single edge.

edge_count()

Counts the edges of the GraphRecord.

edge_indices()

Lists the indices of all edges.

edges()

Starts a query over the edges of the GraphRecord.

export(writer)

Exports the GraphRecord through a writer.

freeze_schema()

Stops the schema from growing with the data written to the GraphRecord.

from_ron(path)

Reads a GraphRecord from a RON file.

group(group_index)

Views a single group.

group_count()

Counts the groups of the GraphRecord.

group_indices()

Lists the indices of all groups.

group_overview(group_index[, truncate_details])

Summarizes the contents of a single group.

groups()

Starts a query over the groups of the GraphRecord.

intersect(other)

Keeps what this GraphRecord and the other one have in common.

keep_edges(edge_indices)

Keeps only the selected edges.

keep_groups(group_indices)

Keeps only the selected groups and their members.

keep_nodes(node_indices)

Keeps only the selected nodes and the edges between them.

merge(other[, on_conflict])

Merges the other GraphRecord into this one.

node(node_index)

Views a single node.

node_count()

Counts the nodes of the GraphRecord.

node_indices()

Lists the indices of all nodes.

nodes()

Starts a query over the nodes of the GraphRecord.

overview([truncate_details])

Summarizes the contents of the GraphRecord.

query(expression)

Binds an expression to the GraphRecord.

remove_edge_attributes(edge_indices, ...)

Removes the named attributes from the selected edges.

remove_edges(edge_indices)

Removes the selected edges.

remove_edges_from_group(edge_indices, ...)

Removes the selected edges from a group, keeping the edges themselves.

remove_groups(group_indices)

Removes the selected groups, keeping their members ungrouped.

remove_node_attributes(node_indices, ...)

Removes the named attributes from the selected nodes.

remove_nodes(node_indices)

Removes the selected nodes and the edges attached to them.

remove_nodes_from_group(node_indices, ...)

Removes the selected nodes from a group, keeping the nodes themselves.

remove_plugin(name)

Detaches the plugin attached under the given name.

replace_edge_attributes(edge_indices, attributes)

Replaces all attributes of the selected edges with the given ones.

replace_node_attributes(node_indices, attributes)

Replaces all attributes of the selected nodes with the given ones.

set_edge_attributes(edge_indices, attributes)

Sets the given attributes on the selected edges, keeping the others.

set_node_attributes(node_indices, attributes)

Sets the given attributes on the selected nodes, keeping the others.

set_schema(schema)

Validates the GraphRecord against the given schema and adopts it.

to_arrow()

Exports the GraphRecord to Arrow record batches, partitioned by group.

to_pandas()

Exports the GraphRecord to Pandas DataFrames, partitioned by group.

to_polars()

Exports the GraphRecord to Polars DataFrames, partitioned by group.

to_ron(path)

Writes the GraphRecord to a RON file.

unfreeze_schema()

Lets the schema grow with the data written to the GraphRecord again.

with_schema(schema)

Creates an empty GraphRecord that validates against the given schema.

Attributes

plugin_entries

The plugins attached to the GraphRecord, by the name they are attached under.

plugins

The names of the plugins attached to the GraphRecord.

schema

The schema the GraphRecord validates against.

__copy__()[source]#

Copies the GraphRecord.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord holding the same contents.

__deepcopy__(memo=None)[source]#

Deep copies the GraphRecord.

Parameters:

memo (Optional[Dict[int, object]]) – The objects copied so far.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord holding the same contents.

__eq__(other)[source]#

Compares the GraphRecord with another one by its contents.

Parameters:

other (object) – The object to compare against.

Return type:

bool

Returns:

bool

True if both hold the same nodes, edges and groups, otherwise

False.

__reduce__()[source]#

Reduces the GraphRecord to what pickle needs to restore it.

Return type:

Tuple[Callable[[PyGraphRecord], GraphRecord], Tuple[PyGraphRecord]]

Returns:

Tuple[Callable[[PyGraphRecord], GraphRecord], Tuple[PyGraphRecord]]

The

callable that restores the GraphRecord and its arguments.

__repr__()[source]#

Returns the string representation of the GraphRecord.

Return type:

str

Returns:

str – The overview of the GraphRecord.

add_edge(source_node_index, target_node_index, attributes)[source]#

Adds a single edge with the given attributes.

Parameters:
  • source_node_index (SingleNodeSelection) – The node the edge starts at.

  • target_node_index (SingleNodeSelection) – The node the edge ends at.

  • attributes (Attributes) – The attributes of the edge.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord containing the added edge.

add_edge_in_group(source_node_index, target_node_index, attributes, group_index)[source]#

Adds a single edge with the given attributes to a group.

Parameters:
  • source_node_index (SingleNodeSelection) – The node the edge starts at.

  • target_node_index (SingleNodeSelection) – The node the edge ends at.

  • attributes (Attributes) – The attributes of the edge.

  • group_index (SingleGroupSelection) – The group the edge is added in.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord containing the added edge.

add_edges(source)[source]#

Adds the edges of the given source.

Parameters:

source (EdgeSource) – The edges to add.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord containing the added edges.

add_edges_in_group(source, group_index)[source]#

Adds the edges of the given source to a group.

Parameters:
  • source (EdgeSource) – The edges to add.

  • group_index (SingleGroupSelection) – The group the edges are added in.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord containing the added edges.

add_edges_to_group(edge_indices, group_index)[source]#

Adds the selected edges to a group.

Parameters:
  • edge_indices (MultipleEdgeSelection) – The edges to add.

  • group_index (SingleGroupSelection) – The group the edges join.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord with those edges in the group.

add_group(group_index)[source]#

Adds an empty group.

Parameters:

group_index (SingleGroupSelection) – The index of the group to add.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord containing the added group.

add_node(node_index, attributes)[source]#

Adds a single node with the given attributes.

Parameters:
  • node_index (SingleNodeSelection) – The index of the node to add.

  • attributes (Attributes) – The attributes of the node.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord containing the added node.

add_node_in_group(node_index, attributes, group_index)[source]#

Adds a single node with the given attributes to a group.

Parameters:
  • node_index (SingleNodeSelection) – The index of the node to add.

  • attributes (Attributes) – The attributes of the node.

  • group_index (SingleGroupSelection) – The group the node is added in.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord containing the added node.

add_nodes(source)[source]#

Adds the nodes of the given source.

Parameters:

source (NodeSource) – The nodes to add.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord containing the added nodes.

add_nodes_in_group(source, group_index)[source]#

Adds the nodes of the given source to a group.

Parameters:
  • source (NodeSource) – The nodes to add.

  • group_index (SingleGroupSelection) – The group the nodes are added in.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord containing the added nodes.

add_nodes_to_group(node_indices, group_index)[source]#

Adds the selected nodes to a group.

Parameters:
  • node_indices (MultipleNodeSelection) – The nodes to add.

  • group_index (SingleGroupSelection) – The group the nodes join.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord with those nodes in the group.

add_plugin(name, plugin)[source]#

Attaches a plugin under the given name.

Parameters:
  • name (PluginName) – The name to attach the plugin under.

  • plugin (Plugin) – The plugin to attach.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord with the plugin attached.

clear()[source]#

Removes all nodes, edges and groups, keeping the schema and the plugins.

Return type:

GraphRecord

Returns:

GraphRecord – An empty GraphRecord.

compact()[source]#

Reclaims the space that removed nodes and edges still occupy.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord holding the same contents, compacted.

contains_edge(edge_index)[source]#

Checks whether the GraphRecord holds an edge with the given index.

Parameters:

edge_index (EdgeIndex) – The index to look for.

Return type:

bool

Returns:

bool – True if the edge exists, otherwise False.

contains_group(group_index)[source]#

Checks whether the GraphRecord holds a group with the given index.

Parameters:

group_index (GroupIndex) – The index to look for.

Return type:

bool

Returns:

bool – True if the group exists, otherwise False.

contains_node(node_index)[source]#

Checks whether the GraphRecord holds a node with the given index.

Parameters:

node_index (NodeIndex) – The index to look for.

Return type:

bool

Returns:

bool – True if the node exists, otherwise False.

difference(other)[source]#

Removes everything the other GraphRecord also holds.

Parameters:

other (GraphRecord) – The GraphRecord to subtract.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord holding what only this one held.

edge(edge_index)[source]#

Views a single edge.

Parameters:

edge_index (EdgeIndex) – The index of the edge to view.

Return type:

EdgeView

Returns:

EdgeView – A view of the edge as this GraphRecord holds it.

edge_count()[source]#

Counts the edges of the GraphRecord.

Return type:

int

Returns:

int – The number of edges.

edge_indices()[source]#

Lists the indices of all edges.

Return type:

List[EdgeIndex]

Returns:

List[EdgeIndex] – The index of every edge.

edges()[source]#

Starts a query over the edges of the GraphRecord.

Return type:

Expression[Bound, Indexed[EdgeIndex, Unit], Multiple[Unordered]]

Returns:

EdgesSeries – A series of all edges, bound to this GraphRecord.

export(writer)[source]#

Exports the GraphRecord through a writer.

Parameters:

writer (Writer[T]) – The writer to export through.

Return type:

TypeVar(T, covariant=True)

Returns:

T – What the writer handed back.

freeze_schema()[source]#

Stops the schema from growing with the data written to the GraphRecord.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord with a frozen schema.

classmethod from_ron(path)[source]#

Reads a GraphRecord from a RON file.

Parameters:

path (Union[str, os.PathLike[str]]) – The path of the file to read.

Return type:

GraphRecord

Returns:

GraphRecord – The GraphRecord stored in the file.

group(group_index)[source]#

Views a single group.

Parameters:

group_index (GroupIndex) – The index of the group to view.

Return type:

GroupView

Returns:

GroupView – A view of the group as this GraphRecord holds it.

group_count()[source]#

Counts the groups of the GraphRecord.

Return type:

int

Returns:

int – The number of groups.

group_indices()[source]#

Lists the indices of all groups.

Return type:

List[Union[str, int]]

Returns:

List[GroupIndex] – The index of every group.

group_overview(group_index, truncate_details=80)[source]#

Summarizes the contents of a single group.

Parameters:
  • group_index (GroupIndex) – The group to summarize.

  • truncate_details (Optional[int]) – The width detail columns are truncated to. No truncation if None. Defaults to DEFAULT_TRUNCATE_DETAILS.

Return type:

GroupOverview

Returns:

GroupOverview – The summary of the group.

groups()[source]#

Starts a query over the groups of the GraphRecord.

Return type:

Expression[Bound, Indexed[GroupIndex, Unit], Multiple[Unordered]]

Returns:

GroupsSeries – A series of all groups, bound to this GraphRecord.

intersect(other)[source]#

Keeps what this GraphRecord and the other one have in common.

Parameters:

other (GraphRecord) – The GraphRecord to intersect with.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord holding the shared nodes, edges and groups.

keep_edges(edge_indices)[source]#

Keeps only the selected edges.

Parameters:

edge_indices (MultipleEdgeSelection) – The edges to keep.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord holding only those edges.

keep_groups(group_indices)[source]#

Keeps only the selected groups and their members.

Parameters:

group_indices (MultipleGroupSelection) – The groups to keep.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord holding only those groups.

keep_nodes(node_indices)[source]#

Keeps only the selected nodes and the edges between them.

Parameters:

node_indices (MultipleNodeSelection) – The nodes to keep.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord holding only those nodes.

merge(other, on_conflict=OnConflict.Raise)[source]#

Merges the other GraphRecord into this one.

Parameters:
  • other (GraphRecord) – The GraphRecord to merge in.

  • on_conflict (OnConflict) – How attributes both GraphRecords define are resolved. Defaults to OnConflict.Raise.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord holding both.

node(node_index)[source]#

Views a single node.

Parameters:

node_index (NodeIndex) – The index of the node to view.

Return type:

NodeView

Returns:

NodeView – A view of the node as this GraphRecord holds it.

node_count()[source]#

Counts the nodes of the GraphRecord.

Return type:

int

Returns:

int – The number of nodes.

node_indices()[source]#

Lists the indices of all nodes.

Return type:

List[Union[str, int]]

Returns:

List[NodeIndex] – The index of every node.

nodes()[source]#

Starts a query over the nodes of the GraphRecord.

Return type:

Expression[Bound, Indexed[NodeIndex, Unit], Multiple[Unordered]]

Returns:

NodesSeries – A series of all nodes, bound to this GraphRecord.

overview(truncate_details=80)[source]#

Summarizes the contents of the GraphRecord.

Parameters:

truncate_details (Optional[int]) – The width detail columns are truncated to. No truncation if None. Defaults to DEFAULT_TRUNCATE_DETAILS.

Return type:

Overview

Returns:

Overview – The summary of every group and of the ungrouped part.

property plugin_entries: Dict[str | int, Plugin]#

The plugins attached to the GraphRecord, by the name they are attached under.

Returns:

Dict[PluginName, Plugin] – Every attached plugin, by its name.

property plugins: List[str | int]#

The names of the plugins attached to the GraphRecord.

Returns:

List[PluginName] – The name of every attached plugin.

query(expression)[source]#

Binds an expression to the GraphRecord.

Parameters:

expression (Expression[Unbound, S, C, Unpack[Levels]]) – The expression to bind.

Return type:

Series[TypeVar(S, bound= Shape, covariant=True), TypeVar(C, bound= Container), Unpack[TypeVarTuple]]

Returns:

Series[S, C, Unpack[Levels]] – The expression, bound to this GraphRecord.

remove_edge_attributes(edge_indices, attribute_names)[source]#

Removes the named attributes from the selected edges.

Parameters:
  • edge_indices (MultipleEdgeSelection) – The edges to remove the attributes from.

  • attribute_names (Iterable[AttributeName]) – The names of the attributes to remove.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord without those attributes.

remove_edges(edge_indices)[source]#

Removes the selected edges.

Parameters:

edge_indices (MultipleEdgeSelection) – The edges to remove.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord without those edges.

remove_edges_from_group(edge_indices, group_index)[source]#

Removes the selected edges from a group, keeping the edges themselves.

Parameters:
  • edge_indices (MultipleEdgeSelection) – The edges to remove.

  • group_index (SingleGroupSelection) – The group the edges leave.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord without those edges in the group.

remove_groups(group_indices)[source]#

Removes the selected groups, keeping their members ungrouped.

Parameters:

group_indices (MultipleGroupSelection) – The groups to remove.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord without those groups.

remove_node_attributes(node_indices, attribute_names)[source]#

Removes the named attributes from the selected nodes.

Parameters:
  • node_indices (MultipleNodeSelection) – The nodes to remove the attributes from.

  • attribute_names (Iterable[AttributeName]) – The names of the attributes to remove.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord without those attributes.

remove_nodes(node_indices)[source]#

Removes the selected nodes and the edges attached to them.

Parameters:

node_indices (MultipleNodeSelection) – The nodes to remove.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord without those nodes.

remove_nodes_from_group(node_indices, group_index)[source]#

Removes the selected nodes from a group, keeping the nodes themselves.

Parameters:
  • node_indices (MultipleNodeSelection) – The nodes to remove.

  • group_index (SingleGroupSelection) – The group the nodes leave.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord without those nodes in the group.

remove_plugin(name)[source]#

Detaches the plugin attached under the given name.

Parameters:

name (PluginName) – The name the plugin is attached under.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord without that plugin.

replace_edge_attributes(edge_indices, attributes)[source]#

Replaces all attributes of the selected edges with the given ones.

Parameters:
  • edge_indices (MultipleEdgeSelection) – The edges to replace the attributes of.

  • attributes (Attributes) – The attributes the edges end up with.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord with the attributes replaced.

replace_node_attributes(node_indices, attributes)[source]#

Replaces all attributes of the selected nodes with the given ones.

Parameters:
  • node_indices (MultipleNodeSelection) – The nodes to replace the attributes of.

  • attributes (Attributes) – The attributes the nodes end up with.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord with the attributes replaced.

property schema: Schema#

The schema the GraphRecord validates against.

Returns:

Schema – The schema of the GraphRecord.

set_edge_attributes(edge_indices, attributes)[source]#

Sets the given attributes on the selected edges, keeping the others.

Parameters:
  • edge_indices (MultipleEdgeSelection) – The edges to set the attributes on.

  • attributes (Attributes) – The attributes to set.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord with the attributes set.

set_node_attributes(node_indices, attributes)[source]#

Sets the given attributes on the selected nodes, keeping the others.

Parameters:
  • node_indices (MultipleNodeSelection) – The nodes to set the attributes on.

  • attributes (Attributes) – The attributes to set.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord with the attributes set.

set_schema(schema)[source]#

Validates the GraphRecord against the given schema and adopts it.

Parameters:

schema (Schema) – The schema to adopt.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord carrying the schema.

to_arrow()[source]#

Exports the GraphRecord to Arrow record batches, partitioned by group.

Return type:

Export[RecordBatch]

Returns:

Export[RecordBatch]

The node and edge tables of every group and of

the ungrouped part.

to_pandas()[source]#

Exports the GraphRecord to Pandas DataFrames, partitioned by group.

Return type:

Export[DataFrame]

Returns:

Export[pd.DataFrame]

The node and edge tables of every group and of

the ungrouped part.

to_polars()[source]#

Exports the GraphRecord to Polars DataFrames, partitioned by group.

Return type:

Export[DataFrame]

Returns:

Export[pl.DataFrame]

The node and edge tables of every group and of

the ungrouped part.

to_ron(path)[source]#

Writes the GraphRecord to a RON file.

Parameters:

path (Union[str, os.PathLike[str]]) – The path of the file to write.

Return type:

None

unfreeze_schema()[source]#

Lets the schema grow with the data written to the GraphRecord again.

Return type:

GraphRecord

Returns:

GraphRecord – A GraphRecord with an unfrozen schema.

classmethod with_schema(schema)[source]#

Creates an empty GraphRecord that validates against the given schema.

Parameters:

schema (Schema) – The schema the GraphRecord validates against.

Return type:

GraphRecord

Returns:

GraphRecord – An empty GraphRecord carrying the schema.