Skip to content

Commit 6c39bc0

Browse files
committed
Return custom type from wcc.mutate
1 parent 50d88ab commit 6c39bc0

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

graphdatascience/procedure_surface/api/wcc_endpoints.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
from __future__ import annotations
2+
13
from abc import ABC, abstractmethod
4+
from dataclasses import dataclass
25
from typing import Any, List, Optional
36

47
from pandas import DataFrame, Series
@@ -27,7 +30,7 @@ def mutate(
2730
seed_property: Optional[str] = None,
2831
consecutive_ids: Optional[bool] = None,
2932
relationship_weight_property: Optional[str] = None,
30-
) -> Series[Any]:
33+
) -> WccMutateResult:
3134
"""
3235
Executes the WCC algorithm and writes the results to the in-memory graph as node properties.
3336
@@ -82,7 +85,7 @@ def stats(
8285
seed_property: Optional[str] = None,
8386
consecutive_ids: Optional[bool] = None,
8487
relationship_weight_property: Optional[str] = None,
85-
) -> Series[Any]:
88+
) -> Series:
8689
"""
8790
Executes the WCC algorithm and returns statistics.
8891
@@ -195,7 +198,7 @@ def write(
195198
relationship_weight_property: Optional[str] = None,
196199
write_concurrency: Optional[Any] = None,
197200
write_to_result_store: Optional[bool] = None,
198-
) -> Series[Any]:
201+
) -> Series:
199202
"""
200203
Executes the WCC algorithm and writes the results to the Neo4j database.
201204
@@ -240,3 +243,15 @@ def write(
240243
Algorithm metrics and statistics
241244
"""
242245
pass
246+
247+
248+
@dataclass(frozen=True, repr=True)
249+
class WccMutateResult:
250+
component_count: int
251+
component_distribution: dict[str, Any]
252+
pre_processing_millis: int
253+
compute_millis: int
254+
post_processing_millis: int
255+
mutate_millis: int
256+
node_properties_written: int
257+
configuration: dict[str, Any]

graphdatascience/procedure_surface/cypher/wcc_proc_runner.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from ...call_parameters import CallParameters
66
from ...graph.graph_object import Graph
77
from ...query_runner.query_runner import QueryRunner
8-
from ..api.wcc_endpoints import WccEndpoints
8+
from ..api.wcc_endpoints import WccEndpoints, WccMutateResult
99

1010

1111
class WccCypherEndpoints(WccEndpoints):
@@ -32,7 +32,7 @@ def mutate(
3232
seed_property: Optional[str] = None,
3333
consecutive_ids: Optional[bool] = None,
3434
relationship_weight_property: Optional[str] = None,
35-
) -> Series[Any]:
35+
) -> WccMutateResult:
3636
# Build configuration dictionary from parameters
3737
config: dict[str, Any] = {
3838
"mutateProperty": mutate_property,
@@ -66,7 +66,17 @@ def mutate(
6666
params = CallParameters(graph_name=G.name(), config=config)
6767
params.ensure_job_id_in_config()
6868

69-
return self._query_runner.call_procedure(endpoint="gds.wcc.mutate", params=params).squeeze() # type: ignore
69+
cypher_result = self._query_runner.call_procedure(endpoint="gds.wcc.mutate", params=params).squeeze()
70+
71+
return WccMutateResult(
72+
cypher_result["componentCount"],
73+
cypher_result["componentDistribution"],
74+
cypher_result["preProcessingMillis"],
75+
cypher_result["computeMillis"],
76+
cypher_result["postProcessingMillis"],
77+
cypher_result["mutateMillis"],
78+
cypher_result["nodePropertiesWritten"],
79+
)
7080

7181
def stats(
7282
self,
@@ -82,7 +92,7 @@ def stats(
8292
seed_property: Optional[str] = None,
8393
consecutive_ids: Optional[bool] = None,
8494
relationship_weight_property: Optional[str] = None,
85-
) -> Series[Any]:
95+
) -> Series:
8696
# Build configuration dictionary from parameters
8797
config: dict[str, Any] = {}
8898

@@ -185,7 +195,7 @@ def write(
185195
relationship_weight_property: Optional[str] = None,
186196
write_concurrency: Optional[int] = None,
187197
write_to_result_store: Optional[bool] = None,
188-
) -> Series[Any]:
198+
) -> Series:
189199
# Build configuration dictionary from parameters
190200
config: dict[str, Any] = {
191201
"writeProperty": write_property,

0 commit comments

Comments
 (0)