Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/api/serialization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ Serialization

rustworkx.node_link_json
rustworkx.read_graphml
rustworkx.write_graphml
rustworkx.from_node_link_json_file
rustworkx.parse_node_link_json
9 changes: 9 additions & 0 deletions releasenotes/notes/write_graphml-624c10b6f7592ee1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
features:
- |
Added a new function :func:`~rustworkx.write_graphml` that writes
a list of rustworkx graph objects to a file in GraphML format.
other:
- |
When graphs read with :func:`~rustworkx.read_graphml` include IDs,
these IDs are now stored in the graph attributes.
6 changes: 6 additions & 0 deletions rustworkx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2279,3 +2279,9 @@ def single_source_all_shortest_paths(
For most use cases, consider using `dijkstra_shortest_paths` for a single shortest path, which runs much faster.
"""
raise TypeError(f"Invalid Input Type {type(graph)} for graph")


@_rustworkx_dispatch
def write_graphml(graph, path, /, keys, compression):
""" """
raise TypeError(f"Invalid Input Type {type(graph)} for graph")
10 changes: 10 additions & 0 deletions rustworkx/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ from .rustworkx import directed_barabasi_albert_graph as directed_barabasi_alber
from .rustworkx import undirected_random_bipartite_graph as undirected_random_bipartite_graph
from .rustworkx import directed_random_bipartite_graph as directed_random_bipartite_graph
from .rustworkx import read_graphml as read_graphml
from .rustworkx import graph_write_graphml as graph_write_graphml
from .rustworkx import digraph_write_graphml as digraph_write_graphml
from .rustworkx import GraphMLKey as GraphMLKey
from .rustworkx import digraph_node_link_json as digraph_node_link_json
from .rustworkx import graph_node_link_json as graph_node_link_json
from .rustworkx import from_node_link_json_file as from_node_link_json_file
Expand Down Expand Up @@ -662,3 +665,10 @@ def is_bipartite(graph: PyGraph[_S, _T] | PyDiGraph[_S, _T]) -> bool: ...
def condensation(
graph: PyDiGraph | PyGraph, /, sccs: list[int] | None = ...
) -> PyDiGraph | PyGraph: ...
def write_graphml(
graph: PyGraph | PyDiGraph,
path: str,
/,
keys: list[GraphMLKey] | None = ...,
compression: str | None = ...,
) -> None: ...
38 changes: 38 additions & 0 deletions rustworkx/rustworkx.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,30 @@ class ColoringStrategy:
Saturation: Any
IndependentSet: Any

@final
class GraphMLDomain:
Node: GraphMLDomain
Edge: GraphMLDomain
Graph: GraphMLDomain
All: GraphMLDomain

@final
class GraphMLType:
Boolean: GraphMLType
Int: GraphMLType
Float: GraphMLType
Double: GraphMLType
String: GraphMLType
Long: GraphMLType

@final
class GraphMLKey:
id: str
domain: GraphMLDomain
name: str
ty: GraphMLType
default: Any

# Cartesian product

def digraph_cartesian_product(
Expand Down Expand Up @@ -685,6 +709,20 @@ def read_graphml(
/,
compression: str | None = ...,
) -> list[PyGraph | PyDiGraph]: ...
def graph_write_graphml(
graph: PyGraph,
path: str,
/,
keys: list[GraphMLKey] | None = ...,
compression: str | None = ...,
) -> None: ...
def digraph_write_graphml(
graph: PyDiGraph,
path: str,
/,
keys: list[GraphMLKey] | None = ...,
compression: str | None = ...,
) -> None: ...
def digraph_node_link_json(
graph: PyDiGraph[_S, _T],
/,
Expand Down
Loading
Loading