Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions src/tracksdata/graph/_graph_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,11 @@ def _add_edge_local(self, source_id: int, target_id: int) -> int:
if c in df.columns
]
attrs = df.filter(pl.col(DEFAULT_ATTR_KEYS.EDGE_ID) == parent_edge_id).drop(drop_cols).rows(named=True)[0]
# A rustworkx-family root shares its payload, EDGE_ID included; other backends
# hand back a plain dict, so stamp the root edge id explicitly (as `bulk_add_edges`
# does). Otherwise the local edge keeps the -1 placeholder and disagrees with
# `_edge_map_to_root`, so reads by edge id find no row.
attrs[DEFAULT_ATTR_KEYS.EDGE_ID] = parent_edge_id

local_edge_id = self.rx_graph.add_edge(
self._map_to_local(source_id),
Expand Down
17 changes: 17 additions & 0 deletions src/tracksdata/graph/_test/test_subgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,23 @@ def test_add_edge_to_view_basic(graph_backend: BaseGraph) -> None:
assert row["weight"].item() == 0.5


def test_add_edge_to_view_keeps_edge_id(graph_backend: BaseGraph) -> None:
"""A revived edge's local row must carry the root edge id, so reads by id work."""
graph_backend.add_edge_attr_key("weight", pl.Float64)

n0 = graph_backend.add_node({"t": 0})
n1 = graph_backend.add_node({"t": 1})
root_edge_id = graph_backend.add_edge(n0, n1, {"weight": 1.5})

view = graph_backend.filter().subgraph()
view.remove_edge_from_view(n0, n1)
view.add_edge_to_view(n0, n1)

assert view.edge_id(n0, n1) == root_edge_id
assert view.edge_attrs(attr_keys=["weight"])[DEFAULT_ATTR_KEYS.EDGE_ID].to_list() == [root_edge_id]
assert view.edges[root_edge_id]["weight"] == 1.5


def test_add_edge_to_view_validation(graph_backend: BaseGraph) -> None:
"""Bad inputs raise ValueError; sync=False raises RuntimeError."""
graph_backend.add_node_attr_key("x", pl.Float64)
Expand Down
Loading