Skip to content

Commit 66470fb

Browse files
committed
fix: revert the commit that prevented the addition of vertices with integer names, refs #693
1 parent c7ca7b6 commit 66470fb

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
- `Graph.get_incidence()` is now deprecated in favour of `Graph.get_biadjacency()` as it returns the _bipartite adjacency_ matrix of a graph and not its incidence matrix. (The previous name was a mistake). Future versions might re-introduce `Graph.get_incidence()` to return the incidence matrix of a graph.
1010

11+
- Reverted the change in 0.10.5 that prevented adding vertices with integers as vertex names. Now we show a deprecation warning instead, and the addition of vertices with integer names will be prevented from version 0.11.0 only.
12+
1113
### Fixed
1214

1315
- Fixed a minor memory leak in `Graph.decompose()`.

src/igraph/basic.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from igraph._igraph import GraphBase
22
from igraph.seq import EdgeSeq
3+
from igraph.utils import deprecated
34

45

56
def _add_edge(graph, source, target, **kwds):
@@ -58,7 +59,14 @@ def _add_vertex(graph, name=None, **kwds):
5859
to avoid the overhead of creating t.
5960
"""
6061
if isinstance(name, int):
61-
raise TypeError("cannot use integers as vertex names; use strings instead")
62+
# raise TypeError("cannot use integers as vertex names; use strings instead")
63+
deprecated(
64+
"You are using integers as vertex names. This is discouraged because "
65+
"most igraph functions interpret integers as vertex _IDs_ and strings "
66+
"as vertex names. For sake of consistency, convert your vertex "
67+
"names to strings before assigning them. Future versions from igraph "
68+
"0.11.0 will disallow integers as vertex names."
69+
)
6270

6371
vid = graph.vcount()
6472
graph.add_vertices(1)

tests/test_basic.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ def testAddVertex(self):
120120
self.assertTrue("name" in g.vertex_attributes())
121121
self.assertEqual(g.vs["name"], [None, "foo"])
122122

123-
self.assertRaises(TypeError, g.add_vertex, 3)
124-
125123
vertex = g.add_vertex("3")
126124
self.assertTrue(g.vcount() == 3 and g.ecount() == 0)
127125
self.assertEqual(2, vertex.index)
@@ -141,6 +139,9 @@ def testAddVertex(self):
141139
self.assertEqual(g.vs["spam"], [None] * 4 + ["cheese"])
142140
self.assertEqual(g.vs["ham"], [None] * 4 + [42])
143141

142+
with self.assertWarns(DeprecationWarning, msg="integers as vertex names"):
143+
g.add_vertex(42)
144+
144145
def testAddVertices(self):
145146
g = Graph()
146147
g.add_vertices(2)

0 commit comments

Comments
 (0)