Skip to content

Commit 13cdbc6

Browse files
lmeyerovclaude
andcommitted
fix(gfql/index): mypy types (engine cast, Optional node-id idx, show_indexes narrowing)
Index module failed CI lint-types (python-lint-types). Fix: cast engine to resolve_engine in create_index/gfql_explain; use a separate var for the Optional NodeIdIndex (was assigned to an AdjacencyIndex-typed name); assert idx/source/destination not-None in show_indexes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ae2e054 commit 13cdbc6

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

graphistry/compute/gfql/index/api.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from __future__ import annotations
99

1010
import copy
11-
from typing import Any, Optional, Union
11+
from typing import Any, Optional, Union, cast
1212

1313
from graphistry.Engine import EngineAbstract, Engine, resolve_engine
1414
from graphistry.Plottable import Plottable
@@ -86,7 +86,7 @@ def create_index(
8686
O(E log E) once, amortized over later seeded queries.
8787
"""
8888
from dataclasses import replace
89-
eng = resolve_engine(engine, g)
89+
eng = resolve_engine(cast(Any, engine), g)
9090
# Build over frames already in the target engine so the index arrays land on
9191
# the right backend (cupy for cudf, numpy otherwise). No-op when already in-engine.
9292
from graphistry.compute.ComputeMixin import _coerce_input_formats
@@ -112,15 +112,15 @@ def create_index(
112112
node_col = g2._node
113113
assert node_col is not None and g2._nodes is not None
114114
_check_column(column, node_col, kind)
115-
idx = build_node_id_index(g2._nodes, node_col, eng)
116-
if idx is None:
115+
node_idx = build_node_id_index(g2._nodes, node_col, eng)
116+
if node_idx is None:
117117
raise ValueError(
118118
f"Cannot build a {NODE_ID!r} index: node id column {node_col!r} has "
119119
f"duplicate values (a node-id index requires unique ids). Seeded "
120120
f"traversal still works via the un-indexed node materialization path."
121121
)
122-
idx = replace(idx, name=name or index_name(kind, node_col))
123-
registry = registry.with_index(NODE_ID, idx)
122+
node_idx = replace(node_idx, name=name or index_name(kind, node_col))
123+
registry = registry.with_index(NODE_ID, node_idx)
124124
return _attach(g2, registry)
125125

126126
raise ValueError(f"Unknown GFQL index kind: {kind!r}. Expected one of {ALL_KINDS}.")
@@ -149,7 +149,9 @@ def show_indexes(g: Plottable) -> Any:
149149
rows = []
150150
for kind in registry.kinds():
151151
idx = registry.get(kind)
152+
assert idx is not None # iterating registry.kinds() -> present
152153
if kind in ADJ_KINDS:
154+
assert g._source is not None and g._destination is not None
153155
valid = registry.get_valid(kind, g._edges, (g._source, g._destination), idx.engine) is not None
154156
n_keys, n_rows = idx.n_keys, idx.n_edges
155157
else: # NODE_ID

graphistry/compute/gfql/index/explain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
"""
88
from __future__ import annotations
99

10-
from typing import Any, Dict
10+
from typing import Any, Dict, cast
1111

1212
from graphistry.Engine import resolve_engine
1313
from .api import index_trace, get_registry, show_indexes
1414

1515

1616
def gfql_explain(g: Any, query: Any, *, index_policy: str = "use", engine: str = "auto") -> Dict[str, Any]:
17-
eng = resolve_engine(engine, g)
17+
eng = resolve_engine(cast(Any, engine), g)
1818
resident = show_indexes(g)
1919
with index_trace() as steps:
2020
try:

0 commit comments

Comments
 (0)