Skip to content

Commit

Permalink
fix: revert the commit that prevented the addition of vertices with i…
Browse files Browse the repository at this point in the history
…nteger names, refs #693
  • Loading branch information
ntamas committed Jul 13, 2023
1 parent c7ca7b6 commit 66470fb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

- `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.

- 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.

### Fixed

- Fixed a minor memory leak in `Graph.decompose()`.
Expand Down
10 changes: 9 additions & 1 deletion src/igraph/basic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from igraph._igraph import GraphBase
from igraph.seq import EdgeSeq
from igraph.utils import deprecated


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

vid = graph.vcount()
graph.add_vertices(1)
Expand Down
5 changes: 3 additions & 2 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ def testAddVertex(self):
self.assertTrue("name" in g.vertex_attributes())
self.assertEqual(g.vs["name"], [None, "foo"])

self.assertRaises(TypeError, g.add_vertex, 3)

vertex = g.add_vertex("3")
self.assertTrue(g.vcount() == 3 and g.ecount() == 0)
self.assertEqual(2, vertex.index)
Expand All @@ -141,6 +139,9 @@ def testAddVertex(self):
self.assertEqual(g.vs["spam"], [None] * 4 + ["cheese"])
self.assertEqual(g.vs["ham"], [None] * 4 + [42])

with self.assertWarns(DeprecationWarning, msg="integers as vertex names"):
g.add_vertex(42)

def testAddVertices(self):
g = Graph()
g.add_vertices(2)
Expand Down

0 comments on commit 66470fb

Please sign in to comment.