Skip to content

Commit

Permalink
refactor: Graph.are_connected() was renamed to Graph.are_adjacent()
Browse files Browse the repository at this point in the history
  • Loading branch information
ntamas committed Feb 14, 2024
1 parent bafd4a6 commit 03f9faa
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion doc/source/analysis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down
14 changes: 7 additions & 7 deletions src/_igraph/graphobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions src/igraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_structural.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 03f9faa

Please sign in to comment.