From 03f9faa15eaa223d8f6f5525e4fb59b0aed5f8a5 Mon Sep 17 00:00:00 2001 From: Tamas Nepusz Date: Wed, 14 Feb 2024 11:52:59 +0100 Subject: [PATCH] refactor: Graph.are_connected() was renamed to Graph.are_adjacent() --- CHANGELOG.md | 6 ++++++ doc/source/analysis.rst | 2 +- src/_igraph/graphobject.c | 14 +++++++------- src/igraph/__init__.py | 8 ++++++++ tests/test_attributes.py | 2 +- tests/test_structural.py | 2 +- 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32d6c5702..891995ccd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ allows the user to strip the `g_`, `v_` and `e_` prefixes from GraphML files written by igraph. +### Changed + +- `Graph.are_connected()` has now been renamed to `Graph.are_adjacent()`, + following up a similar change in the C core. The old name of the function + is deprecated but will be kept around until at least 0.12.0. + ## [0.11.4] ### Added diff --git a/doc/source/analysis.rst b/doc/source/analysis.rst index 943f719cc..bb911efad 100644 --- a/doc/source/analysis.rst +++ b/doc/source/analysis.rst @@ -63,7 +63,7 @@ To get the vertices at the two ends of an edge, use :attr:`Edge.source` and :att >>> v1, v2 = e.source, e.target Vice versa, to get the edge if from the source and target vertices, you can use :meth:`Graph.get_eid` or, for multiple pairs of source/targets, -:meth:`Graph.get_eids`. The boolean version, asking whether two vertices are directly connected, is :meth:`Graph.are_connected`. +:meth:`Graph.get_eids`. The boolean version, asking whether two vertices are directly connected, is :meth:`Graph.are_adjacent`. To get the edges incident on a vertex, you can use :meth:`Vertex.incident`, :meth:`Vertex.out_edges` and :meth:`Vertex.in_edges`. The three are equivalent on undirected graphs but not directed ones of course:: diff --git a/src/_igraph/graphobject.c b/src/_igraph/graphobject.c index 488a55740..c79b4b479 100644 --- a/src/_igraph/graphobject.c +++ b/src/_igraph/graphobject.c @@ -1445,10 +1445,10 @@ PyObject *igraphmodule_Graph_is_biconnected(igraphmodule_GraphObject *self, PyOb /** \ingroup python_interface_graph * \brief Decides whether there is an edge from a given vertex to an other one. * \return Py_True if the vertices are directly connected, Py_False otherwise - * \sa igraph_are_connected + * \sa igraph_are_adjacent */ -PyObject *igraphmodule_Graph_are_connected(igraphmodule_GraphObject * self, - PyObject * args, PyObject * kwds) +PyObject *igraphmodule_Graph_are_adjacent(igraphmodule_GraphObject * self, + PyObject * args, PyObject * kwds) { static char *kwlist[] = { "v1", "v2", NULL }; PyObject *v1, *v2; @@ -1464,7 +1464,7 @@ PyObject *igraphmodule_Graph_are_connected(igraphmodule_GraphObject * self, if (igraphmodule_PyObject_to_vid(v2, &idx2, &self->g)) return NULL; - if (igraph_are_connected(&self->g, idx1, idx2, &res)) + if (igraph_are_adjacent(&self->g, idx1, idx2, &res)) return igraphmodule_handle_igraph_error(); if (res) @@ -14554,10 +14554,10 @@ struct PyMethodDef igraphmodule_Graph_methods[] = { // STRUCTURAL PROPERTIES OF GRAPHS // ///////////////////////////////////// - // interface to igraph_are_connected - {"are_connected", (PyCFunction) igraphmodule_Graph_are_connected, + // interface to igraph_are_adjacent + {"are_adjacent", (PyCFunction) igraphmodule_Graph_are_adjacent, METH_VARARGS | METH_KEYWORDS, - "are_connected(v1, v2)\n--\n\n" + "are_adjacent(v1, v2)\n--\n\n" "Decides whether two given vertices are directly connected.\n\n" "@param v1: the ID or name of the first vertex\n" "@param v2: the ID or name of the second vertex\n" diff --git a/src/igraph/__init__.py b/src/igraph/__init__.py index c0997aa8c..7f0e328b7 100644 --- a/src/igraph/__init__.py +++ b/src/igraph/__init__.py @@ -948,6 +948,14 @@ def Incidence(cls, *args, **kwds): deprecated("Graph.Incidence() is deprecated; use Graph.Biadjacency() instead") return cls.Biadjacency(*args, **kwds) + def are_connected(self, *args, **kwds): + """Deprecated alias to L{Graph.are_adjacent()}.""" + deprecated( + "Graph.are_connected() is deprecated; use Graph.are_adjacent() " + "instead" + ) + return self.are_adjacent(*args, **kwds) + def get_incidence(self, *args, **kwds): """Deprecated alias to L{Graph.get_biadjacency()}.""" deprecated( diff --git a/tests/test_attributes.py b/tests/test_attributes.py index 4b6683d32..1299cada9 100644 --- a/tests/test_attributes.py +++ b/tests/test_attributes.py @@ -112,7 +112,7 @@ def testVertexNameIndexingBug196(self): g.add_vertices([a, b]) g.add_edges([(a, b)]) self.assertEqual(g.ecount(), 1) - self.assertTrue(g.are_connected(a, b)) + self.assertTrue(g.are_adjacent(a, b)) def testInvalidAttributeNames(self): g = Graph.Famous("bull") diff --git a/tests/test_structural.py b/tests/test_structural.py index 5ad20648c..bfda0f2e5 100644 --- a/tests/test_structural.py +++ b/tests/test_structural.py @@ -994,7 +994,7 @@ def testGetAllSimplePaths(self): self.assertEqual(15, path[-1]) curr = path[0] for next in path[1:]: - self.assertTrue(g.are_connected(curr, next)) + self.assertTrue(g.are_adjacent(curr, next)) curr = next def testPathLengthHist(self):