refactor(data): replace fragile regex in __inc__ and _get_cat_dim with explicit key sets
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
Research direction
Start in nvalchemi/data/data.py at DataMixin.inc() and compare its current regex behavior with the explicit key sets used by _get_field_level(). Then inspect nvalchemi/data/datapipes/backends/zarr.py at _get_cat_dim(); done means both sites use the agreed explicit index-key set and no longer match unrelated field names by substring.
Written by the indexing model from the issue text.
Description
Context
During the attribute rename work in #56, we added neighbor_list to the regex pattern in DataMixin.__inc__() (nvalchemi/data/data.py:155):
return self.num_nodes if bool(re.search("(index|face|neighbor_list)", key)) else 0
This method determines which fields receive cumulative node-index offsets when batching. The regex approach is implicit and fragile — it matches any field whose name contains the substring, so a field like neighbor_list_shifts would incorrectly match (flagged by @zubatyuk in PR #56 review).
A similar pattern exists in the Zarr backend's _get_cat_dim() (nvalchemi/data/datapipes/backends/zarr.py:231):
if bool(re.search("(index|face)", key)):
return -1
In contrast, _get_field_level() in the same file already does this correctly — it checks membership in AtomicData._default_node_keys, _default_edge_keys, and _default_system_keys.
Proposed fix
Replace both regex sites with explicit set membership, as @zubatyuk suggested:
- Add an
_index_keysClassVar onAtomicData(orDataMixin) containing the canonical set of fields that require node-index offsets (currently{"neighbor_list"}). - Update
__inc__to usekey in self._index_keysinstead of regex. - Update
_get_cat_dimto useAtomicData._index_keys(or an equivalent edge-key set) instead of regex.
This makes the behavior explicit, self-documenting, and safe against substring collisions.
Affected files
nvalchemi/data/data.py—DataMixin.__inc__()nvalchemi/data/datapipes/backends/zarr.py—_get_cat_dim()
Origin
Identified during review of PR #56 (attribute rename). Deferred as out of scope for that PR.
- Dominant language
- Python
- Stars
- 167
- Forks
- 38
- Avg merge
- 8d 15h
- Merged PRs (30d)
- 7
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NVIDIA/nvalchemi-toolkit
-
bug
NVIDIA/nvalchemi-toolkit#173 · 1 assignee ·
-
NVIDIA/nvalchemi-toolkit#172 · 1 assignee ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 45/100
NVIDIA/nvalchemi-toolkit#128 ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 75/100
NVIDIA/nvalchemi-toolkit#100 ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 55/100
NVIDIA/nvalchemi-toolkit#83 · 2 comments ·
All issues in NVIDIA/nvalchemi-toolkit
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100