Skip to content

Commit

Permalink
handling invalid uint64 values
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollman committed Dec 9, 2024
1 parent d85cb1f commit 9c727d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
16 changes: 13 additions & 3 deletions caveclient/chunkedgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,8 +1323,16 @@ def is_valid_nodes(
OverflowError
If any root_id is too large or negative to be represented as np.uint64.
"""
node_ids = np.array(node_ids, dtype=np.int64)
invalid_mask = (node_ids == -1) | (node_ids == 0)
valid_mask = ~invalid_mask

node_ids = root_id_int_list_check(node_ids, make_unique=False)
valid_node_ids = node_ids[valid_mask]

if valid_node_ids.size == 0:
return np.full(node_ids.shape, False, dtype=bool)

valid_node_ids = root_id_int_list_check(valid_node_ids, make_unique=False)

endpoint_mapping = self.default_url_mapping
url = self._endpoints["valid_nodes"].format_map(endpoint_mapping)
Expand All @@ -1349,15 +1357,17 @@ def is_valid_nodes(
)
)

data = {"node_ids": node_ids}
data = {"node_ids": valid_node_ids}
r = handle_response(
self.session.get(
url, data=json.dumps(data, cls=BaseEncoder), params=query_d
)
)
valid_ids = np.array(r["valid_roots"], np.uint64)
result = np.full(node_ids.shape, False, dtype=bool)
result[valid_mask] = np.isin(valid_node_ids, valid_ids)

return np.isin(node_ids, valid_ids)
return result

@_check_version_compatibility(
kwarg_use_constraints={
Expand Down
5 changes: 3 additions & 2 deletions tests/test_chunkedgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,5 +1037,6 @@ def test_is_valid_nodes(self, myclient):
json=return_data,
match=[json_params_matcher(data)],
)
with pytest.raises(OverflowError):
out = myclient.chunkedgraph.is_valid_nodes(query_nodes)

out = myclient.chunkedgraph.is_valid_nodes(query_nodes)
assert not np.any(out)

0 comments on commit 9c727d9

Please sign in to comment.