diff --git a/src/tracksdata/graph/_base_graph.py b/src/tracksdata/graph/_base_graph.py index b384bdbb..9b14e389 100644 --- a/src/tracksdata/graph/_base_graph.py +++ b/src/tracksdata/graph/_base_graph.py @@ -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: """ @@ -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. @@ -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, ) diff --git a/src/tracksdata/graph/_test/test_graph_backends.py b/src/tracksdata/graph/_test/test_graph_backends.py index fc52fe59..241081c6 100644 --- a/src/tracksdata/graph/_test/test_graph_backends.py +++ b/src/tracksdata/graph/_test/test_graph_backends.py @@ -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."""