Skip to content

Commit 8e04cfe

Browse files
committed
feat: attribute handler now checks whether the 'attr' argument is an empty list to remind us that it's not fully implemented yet
1 parent f0f3079 commit 8e04cfe

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

src/codegen/internal_lib.py.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ from .errors import handle_igraph_error_t
99
from .types import (
1010
FILE,
1111
igraph_attribute_combination_t,
12+
igraph_attribute_record_t,
1213
igraph_attribute_record_list_t,
1314
igraph_attribute_table_t,
1415
igraph_bool_t,
@@ -553,6 +554,14 @@ igraph_attribute_combination_query = _lib.igraph_attribute_combination_query
553554
igraph_attribute_combination_query.restype = handle_igraph_error_t
554555
igraph_attribute_combination_query.argtypes = [POINTER(igraph_attribute_combination_t), c_char_p, POINTER(c_int), POINTER(c_void_p)]
555556

557+
igraph_attribute_record_list_get_ptr = _lib.igraph_attribute_record_list_get_ptr
558+
igraph_attribute_record_list_get_ptr.restype = POINTER(igraph_attribute_record_t)
559+
igraph_attribute_record_list_get_ptr.argtypes = [POINTER(igraph_attribute_record_list_t), igraph_integer_t]
560+
561+
igraph_attribute_record_list_size = _lib.igraph_attribute_record_list_size
562+
igraph_attribute_record_list_size.restype = igraph_integer_t
563+
igraph_attribute_record_list_size.argtypes = [POINTER(igraph_attribute_record_list_t)]
564+
556565
# Error handling and interruptions
557566

558567
igraph_error = _lib.igraph_error

src/igraph_ctypes/_internal/attributes/handler.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from igraph_ctypes._internal.functions import igraph_ecount, igraph_vcount
1515
from igraph_ctypes._internal.lib import (
1616
igraph_attribute_combination_query,
17+
igraph_attribute_record_list_size,
1718
igraph_error,
1819
igraph_es_as_vector,
1920
igraph_vector_resize,
@@ -117,6 +118,9 @@ def init(self, graph, attr):
117118
assign_storage_to_graph(graph, DictAttributeStorage())
118119
self._indices = _VectorInt.create(0)
119120

121+
if attr and igraph_attribute_record_list_size(attr) != 0:
122+
raise RuntimeError("attribute initialization not implemented yet")
123+
120124
def destroy(self, graph) -> None:
121125
storage = get_storage_from_graph(graph)
122126
if storage:
@@ -148,12 +152,8 @@ def copy(
148152
assign_storage_to_graph(to, new_storage)
149153

150154
def add_vertices(self, graph, n: int, attr) -> None:
151-
# attr will only ever be NULL here so raise an error if it is not
152-
if attr:
153-
raise RuntimeError(
154-
"add_vertices() attribute handler called with non-null attr; "
155-
"this is most likely a bug"
156-
) # pragma: no cover
155+
if attr and igraph_attribute_record_list_size(attr) != 0:
156+
raise RuntimeError("attribute initialization not implemented yet")
157157

158158
# Extend the existing attribute containers
159159
get_storage_from_graph(graph).add_vertices(graph, n)
@@ -172,12 +172,8 @@ def combine_vertices(self, graph, to, mapping, combinations):
172172
assert not _are_pointers_equal(graph, to)
173173

174174
def add_edges(self, graph, edges, attr) -> None:
175-
# attr will only ever be NULL here so raise an error if it is not
176-
if attr:
177-
raise RuntimeError(
178-
"add_edges() attribute handler called with non-null attr; "
179-
"this is most likely a bug"
180-
) # pragma: no cover
175+
if attr and igraph_attribute_record_list_size(attr) != 0:
176+
raise RuntimeError("attribute initialization not implemented yet")
181177

182178
# Extend the existing attribute containers
183179
edge_array = igraph_vector_int_t_to_numpy_array_view(edges).reshape((-1, 2))

src/igraph_ctypes/_internal/lib.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .types import (
1010
FILE,
1111
igraph_attribute_combination_t,
12+
igraph_attribute_record_t,
1213
igraph_attribute_record_list_t,
1314
igraph_attribute_table_t,
1415
igraph_bool_t,
@@ -553,6 +554,14 @@ def _load_libc():
553554
igraph_attribute_combination_query.restype = handle_igraph_error_t
554555
igraph_attribute_combination_query.argtypes = [POINTER(igraph_attribute_combination_t), c_char_p, POINTER(c_int), POINTER(c_void_p)]
555556

557+
igraph_attribute_record_list_get_ptr = _lib.igraph_attribute_record_list_get_ptr
558+
igraph_attribute_record_list_get_ptr.restype = POINTER(igraph_attribute_record_t)
559+
igraph_attribute_record_list_get_ptr.argtypes = [POINTER(igraph_attribute_record_list_t), igraph_integer_t]
560+
561+
igraph_attribute_record_list_size = _lib.igraph_attribute_record_list_size
562+
igraph_attribute_record_list_size.restype = igraph_integer_t
563+
igraph_attribute_record_list_size.argtypes = [POINTER(igraph_attribute_record_list_t)]
564+
556565
# Error handling and interruptions
557566

558567
igraph_error = _lib.igraph_error

src/igraph_ctypes/_internal/types.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ class igraph_rng_t(Structure):
475475

476476

477477
p_attribute_combination_t = POINTER(igraph_attribute_combination_t)
478+
p_attribute_record_list_t = POINTER(igraph_attribute_record_list_t)
478479
p_igraph_t = POINTER(igraph_t)
479480
p_strvector_t = POINTER(igraph_strvector_t)
480481
p_vector_t = POINTER(igraph_vector_t)
@@ -488,7 +489,7 @@ class igraph_attribute_table_t(Structure):
488489
"""ctypes representation of ``igraph_attribute_table_t``"""
489490

490491
TYPES = {
491-
"init": CFUNCTYPE(igraph_error_t, p_igraph_t, p_vector_ptr_t),
492+
"init": CFUNCTYPE(igraph_error_t, p_igraph_t, p_attribute_record_list_t),
492493
"destroy": CFUNCTYPE(None, p_igraph_t),
493494
"copy": CFUNCTYPE(
494495
igraph_error_t,
@@ -499,7 +500,7 @@ class igraph_attribute_table_t(Structure):
499500
igraph_bool_t,
500501
),
501502
"add_vertices": CFUNCTYPE(
502-
igraph_error_t, p_igraph_t, igraph_integer_t, p_vector_ptr_t
503+
igraph_error_t, p_igraph_t, igraph_integer_t, p_attribute_record_list_t
503504
),
504505
"permute_vertices": CFUNCTYPE(
505506
igraph_error_t, p_igraph_t, p_igraph_t, p_vector_int_t
@@ -512,7 +513,7 @@ class igraph_attribute_table_t(Structure):
512513
p_attribute_combination_t,
513514
),
514515
"add_edges": CFUNCTYPE(
515-
igraph_error_t, p_igraph_t, p_vector_int_t, p_vector_ptr_t
516+
igraph_error_t, p_igraph_t, p_vector_int_t, p_attribute_record_list_t
516517
),
517518
"permute_edges": CFUNCTYPE(
518519
igraph_error_t, p_igraph_t, p_igraph_t, p_vector_int_t

0 commit comments

Comments
 (0)