Skip to content

Commit e0fc0b0

Browse files
committed
feat: vertex and edge attribute maps are now extended if needed
1 parent 980f8d6 commit e0fc0b0

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/igraph_ctypes/_internal/attributes/storage.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def add_vertices(self, graph, n: int) -> None:
3030
raise NotImplementedError
3131

3232
@abstractmethod
33-
def add_edges(self, graph, edges) -> None:
33+
def add_edges(self, graph, edges: IntArray) -> None:
3434
"""Notifies the attribute storage object that the given edges were
3535
added to the graph.
3636
"""
@@ -84,10 +84,13 @@ class DictAttributeStorage(AttributeStorage):
8484
edge_attributes: dict[str, AttributeValueList[Any]] = field(default_factory=dict)
8585

8686
def add_vertices(self, graph, n: int) -> None:
87-
pass
87+
for value_list in self.vertex_attributes.values():
88+
value_list._extend_length(n)
8889

8990
def add_edges(self, graph, edges: IntArray) -> None:
90-
pass
91+
n = edges.shape[0]
92+
for value_list in self.edge_attributes.values():
93+
value_list._extend_length(n)
9194

9295
def clear(self) -> None:
9396
self.graph_attributes.clear()

src/igraph_ctypes/_internal/attributes/value_list.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,14 @@ def _check_boolean_mask(self, index: Sequence[Any]) -> bool:
307307
else:
308308
self._raise_invalid_index_error()
309309

310+
def _extend_length(self, n: int) -> None:
311+
"""Extends the list with a given number of new items at the end, even
312+
if the list is marked as fixed-length.
313+
314+
Do not use this method unless you know what you are doing.
315+
"""
316+
self._items.extend([None] * n) # type: ignore
317+
310318
def _raise_invalid_index_error(self) -> NoReturn:
311319
# Wording of error message similar to NumPy
312320
raise IndexError(

0 commit comments

Comments
 (0)