medrecords.medrecord.MedRecord#
- class MedRecord[source]#
Bases:
objectA GraphRecord with built-in medical data handling.
Methods
__init__()Initializes an empty MedRecord.
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 MedRecord holds an edge with the given index.
contains_group(group_index)Checks whether the MedRecord holds a group with the given index.
contains_node(node_index)Checks whether the MedRecord holds a node with the given index.
difference(other)Removes everything the other MedRecord also holds.
edge(edge_index)Views a single edge.
Counts the edges of the MedRecord.
Lists the indices of all edges.
edges()Starts a query over the edges of the MedRecord.
export(writer)Exports the MedRecord through a writer.
Stops the schema from growing with the data written to the MedRecord.
from_graphrecord(graphrecord)Creates a MedRecord around an existing GraphRecord.
from_ron(path)Reads a MedRecord from a RON file.
group(group_index)Views a single group.
Counts the groups of the MedRecord.
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 MedRecord.
intersect(other)Keeps what this MedRecord 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 MedRecord into this one.
node(node_index)Views a single node.
Counts the nodes of the MedRecord.
Lists the indices of all nodes.
nodes()Starts a query over the nodes of the MedRecord.
overview([truncate_details])Summarizes the contents of the MedRecord.
query(expression)Binds an expression to the MedRecord.
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 MedRecord against the given schema and adopts it.
to_arrow()Exports the MedRecord to Arrow record batches, partitioned by group.
Exports the MedRecord to Pandas DataFrames, partitioned by group.
Exports the MedRecord to Polars DataFrames, partitioned by group.
to_ron(path)Writes the MedRecord to a RON file.
Lets the schema grow with the data written to the MedRecord again.
with_schema(schema)Creates an empty MedRecord that validates against the given schema.
Attributes
The GraphRecord the MedRecord holds.
The plugins attached to the MedRecord, by the name they are attached under.
The names of the plugins attached to the MedRecord.
The schema the MedRecord validates against.
- __copy__()[source]#
Copies the MedRecord.
- Return type:
- Returns:
MedRecord – A MedRecord holding the same contents.
- __deepcopy__(memo=None)[source]#
Deep copies the MedRecord.
- Parameters:
memo (Optional[Dict[int, object]]) – The objects copied so far.
- Return type:
- Returns:
MedRecord – A MedRecord holding the same contents.
- __eq__(other)[source]#
Compares the MedRecord 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 MedRecord to what pickle needs to restore it.
- Return type:
Tuple[Callable[[GraphRecord],MedRecord],Tuple[GraphRecord]]- Returns:
Tuple[Callable[[GraphRecord], MedRecord], Tuple[GraphRecord]] –
- The
callable that restores the MedRecord and its arguments.
- __repr__()[source]#
Returns the string representation of the MedRecord.
- Return type:
str- Returns:
str – The overview of the MedRecord.
- 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:
MedRecord
- Returns:
MedRecord – A MedRecord 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:
MedRecord
- Returns:
MedRecord – A MedRecord containing the added edge.
- add_edges(source)[source]#
Adds the edges of the given source.
- Parameters:
source (EdgeSource) – The edges to add.
- Return type:
MedRecord
- Returns:
MedRecord – A MedRecord 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:
MedRecord
- Returns:
MedRecord – A MedRecord 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:
MedRecord
- Returns:
MedRecord – A MedRecord 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:
MedRecord
- Returns:
MedRecord – A MedRecord 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:
MedRecord
- Returns:
MedRecord – A MedRecord 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:
MedRecord
- Returns:
MedRecord – A MedRecord containing the added node.
- add_nodes(source)[source]#
Adds the nodes of the given source.
- Parameters:
source (NodeSource) – The nodes to add.
- Return type:
MedRecord
- Returns:
MedRecord – A MedRecord 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:
MedRecord
- Returns:
MedRecord – A MedRecord 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:
MedRecord
- Returns:
MedRecord – A MedRecord 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:
- Returns:
MedRecord – A MedRecord with the plugin attached.
- clear()[source]#
Removes all nodes, edges and groups, keeping the schema and the plugins.
- Return type:
- Returns:
MedRecord – An empty MedRecord.
- compact()[source]#
Reclaims the space that removed nodes and edges still occupy.
- Return type:
- Returns:
MedRecord – A MedRecord holding the same contents, compacted.
- contains_edge(edge_index)[source]#
Checks whether the MedRecord 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 MedRecord 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 MedRecord 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.
- 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 MedRecord holds it.
- edge_count()[source]#
Counts the edges of the MedRecord.
- 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 MedRecord.
- Return type:
Expression[Bound,Indexed[EdgeIndex,Unit],Multiple[Unordered]]- Returns:
EdgesSeries – A series of all edges, bound to this MedRecord.
- export(writer)[source]#
Exports the MedRecord through a writer.
- Parameters:
writer (Writer[T]) – The writer to export through.
- Return type:
TypeVar(T)- Returns:
T – What the writer handed back.
- freeze_schema()[source]#
Stops the schema from growing with the data written to the MedRecord.
- Return type:
- Returns:
MedRecord – A MedRecord with a frozen schema.
- classmethod from_graphrecord(graphrecord)[source]#
Creates a MedRecord around an existing GraphRecord.
- Parameters:
graphrecord (GraphRecord) – The GraphRecord to wrap.
- Return type:
- Returns:
MedRecord – A MedRecord holding the contents of the GraphRecord.
- classmethod from_ron(path)[source]#
Reads a MedRecord from a RON file.
- Parameters:
path (Union[str, os.PathLike[str]]) – The path of the file to read.
- Return type:
- Returns:
MedRecord – The MedRecord stored in the file.
- property graphrecord: GraphRecord#
The GraphRecord the MedRecord holds.
- Returns:
GraphRecord – The GraphRecord holding the contents of the MedRecord.
- 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 MedRecord holds it.
- group_count()[source]#
Counts the groups of the MedRecord.
- 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 MedRecord.
- Return type:
Expression[Bound,Indexed[GroupIndex,Unit],Multiple[Unordered]]- Returns:
GroupsSeries – A series of all groups, bound to this MedRecord.
- keep_edges(edge_indices)[source]#
Keeps only the selected edges.
- Parameters:
edge_indices (MultipleEdgeSelection) – The edges to keep.
- Return type:
MedRecord
- Returns:
MedRecord – A MedRecord 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:
MedRecord
- Returns:
MedRecord – A MedRecord 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:
MedRecord
- Returns:
MedRecord – A MedRecord holding only those nodes.
- 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 MedRecord holds it.
- node_count()[source]#
Counts the nodes of the MedRecord.
- 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 MedRecord.
- Return type:
Expression[Bound,Indexed[NodeIndex,Unit],Multiple[Unordered]]- Returns:
NodesSeries – A series of all nodes, bound to this MedRecord.
- overview(truncate_details=80)[source]#
Summarizes the contents of the MedRecord.
- 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 MedRecord, 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 MedRecord.
- Returns:
List[PluginName] – The name of every attached plugin.
- query(expression)[source]#
Binds an expression to the MedRecord.
- 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 MedRecord.
- 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:
MedRecord
- Returns:
MedRecord – A MedRecord without those attributes.
- remove_edges(edge_indices)[source]#
Removes the selected edges.
- Parameters:
edge_indices (MultipleEdgeSelection) – The edges to remove.
- Return type:
MedRecord
- Returns:
MedRecord – A MedRecord 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:
MedRecord
- Returns:
MedRecord – A MedRecord 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:
MedRecord
- Returns:
MedRecord – A MedRecord 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:
MedRecord
- Returns:
MedRecord – A MedRecord 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:
MedRecord
- Returns:
MedRecord – A MedRecord 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:
MedRecord
- Returns:
MedRecord – A MedRecord 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:
- Returns:
MedRecord – A MedRecord 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:
MedRecord
- Returns:
MedRecord – A MedRecord 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:
MedRecord
- Returns:
MedRecord – A MedRecord with the attributes replaced.
- property schema: Schema#
The schema the MedRecord validates against.
- Returns:
Schema – The schema of the MedRecord.
- 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:
MedRecord
- Returns:
MedRecord – A MedRecord 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:
MedRecord
- Returns:
MedRecord – A MedRecord with the attributes set.
- set_schema(schema)[source]#
Validates the MedRecord against the given schema and adopts it.
- Parameters:
schema (Schema) – The schema to adopt.
- Return type:
- Returns:
MedRecord – A MedRecord carrying the schema.
- to_arrow()[source]#
Exports the MedRecord 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 MedRecord 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 MedRecord 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 MedRecord to a RON file.
- Parameters:
path (Union[str, os.PathLike[str]]) – The path of the file to write.
- Return type:
None