Skip to content
Merged
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
4 changes: 4 additions & 0 deletions src/tracksdata/graph/_base_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1704,6 +1704,7 @@ def to_geff(
self,
geff_store: StoreLike,
geff_metadata: geff.GeffMetadata | None = None,
overwrite: bool = False,
zarr_format: Literal[2, 3] = 3,
) -> None:
"""
Expand All @@ -1718,6 +1719,8 @@ def to_geff(
It automatically generates the metadata with:
- axes: time (t) and spatial axes ((z), y, x)
- tracklet node property: tracklet_id
overwrite : bool
Whether to overwrite the geff data directory if it exists.
zarr_format : Literal[2, 3]
The zarr format to write the graph to.
Defaults to 3.
Expand Down Expand Up @@ -1795,6 +1798,7 @@ def to_geff(
edge_ids=edge_ids.astype(np.uint64),
edge_props=edge_dict,
metadata=geff_metadata,
overwrite=overwrite,
zarr_format=zarr_format,
)

Expand Down
21 changes: 21 additions & 0 deletions src/tracksdata/graph/_test/test_graph_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -2376,6 +2376,27 @@ def test_geff_roundtrip(graph_backend: BaseGraph) -> None:
)


def test_geff_overwrite(graph_backend: BaseGraph, tmp_path: Path) -> None:
"""Test that to_geff overwrites existing data in the store."""
_fill_mock_geff_graph(graph_backend)

geff_path = tmp_path / "test_overwrite.geff"

# First write
graph_backend.to_geff(geff_store=geff_path)

# Try to write again without overwrite - should raise error
with pytest.raises(FileExistsError):
graph_backend.to_geff(geff_store=geff_path, overwrite=False)

# Now with overwrite=True it should work
graph_backend.to_geff(geff_store=geff_path, overwrite=True)

geff_graph, _ = IndexedRXGraph.from_geff(geff_path)

assert geff_graph.num_nodes() == 3


def test_geff_with_keymapping(graph_backend: BaseGraph) -> None:
"""Test geff roundtrip."""

Expand Down
Loading