DataFrames
DataFrame conversion helpers from annnet.io.dataframe_io.
annnet.io.dataframe_io
Classes
Functions
to_dataframes(graph, *, include_slices=True, include_hyperedges=True, explode_hyperedges=False, public_only=True)
Export graph to Polars DataFrames.
Returns a dictionary of DataFrames representing different aspects of the graph: - 'nodes': Vertex IDs and attributes - 'edges': Binary edges with source, target, weight, directed, attributes - 'hyperedges': Hyperedges with head/tail sets (if include_hyperedges=True) - 'slices': slice membership (if include_slices=True) - 'slice_weights': Per-slice edge weights (if include_slices=True)
Note: Output is always Polars because hyperedges use List types which aren't universally supported across dataframe libraries.
Args: graph: AnnNet instance to export include_slices: Include slice membership tables include_hyperedges: Include hyperedge table explode_hyperedges: If True, explode hyperedges to one row per endpoint public_only: If True, filter out attributes starting with '__'
Returns: Dictionary mapping table names to Polars DataFrames
from_dataframes(nodes=None, edges=None, hyperedges=None, slices=None, slice_weights=None, *, directed=None, exploded_hyperedges=False)
Import graph from any DataFrame (Pandas, Polars, PyArrow, etc.).
Accepts DataFrames in the format produced by to_dataframes():
Nodes DataFrame (optional): - Required: vertex_id - Optional: any attribute columns
Edges DataFrame (optional): - Required: source, target - Optional: edge_id, weight, directed, edge_type, attribute columns
Hyperedges DataFrame (optional): - Compact format: edge_id, directed, weight, head (list), tail (list), members (list) - Exploded format: edge_id, vertex_id, role, weight, directed
slices DataFrame (optional): - Required: slice_id, edge_id
slice_weights DataFrame (optional): - Required: slice_id, edge_id, weight
Args: nodes: DataFrame with vertex_id and attributes (Pandas/Polars/PyArrow/etc.) edges: DataFrame with binary edges hyperedges: DataFrame with hyperedges slices: DataFrame with slice membership slice_weights: DataFrame with per-slice edge weights directed: Default directedness (None = mixed graph) exploded_hyperedges: If True, hyperedges DataFrame is in exploded format
Returns: AnnNet instance