Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/pgraph/PGraph.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from abc import ABC
import sys
import warnings
import numpy as np
import matplotlib.pyplot as plt
import copy
Expand Down Expand Up @@ -1582,7 +1583,20 @@ def next(self, vertex):
raise ValueError("shouldnt happen")

def vertices(self):
raise DeprecationWarning("use endpoints instead")
"""
Vertices of an edge (deprecated)

:return: the two vertices of this edge
:rtype: list of Vertex subclass

.. deprecated:: use :attr:`endpoints` instead
"""
warnings.warn(
"vertices() is deprecated, use endpoints instead",
DeprecationWarning,
stacklevel=2,
)
return self.endpoints

@property
def endpoints(self):
Expand Down Expand Up @@ -1673,6 +1687,22 @@ def neighbors(self):
"""
return [e.next(self) for e in self._edgelist]

def adjacent(self):
"""
Neighbours of a vertex (deprecated)

:return: a list of neighbours of this vertex
:rtype: list of Vertex subclass

.. deprecated:: use :meth:`neighbours` instead
"""
warnings.warn(
"adjacent() is deprecated, use neighbours() instead",
DeprecationWarning,
stacklevel=2,
)
return self.neighbours()

def isneighbour(self, vertex):
"""
Test if vertex is a neigbour
Expand Down
26 changes: 26 additions & 0 deletions tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ def test_neighbours(self):
self.assertFalse(v1.isneighbour(v3))
self.assertFalse(v3.isneighbour(v1))

def test_adjacent_deprecated(self):
# adjacent() must still work (same result as neighbours()) but
# emit a DeprecationWarning, not a hard failure
g = UGraph()
v1 = g.add_vertex(name='v1')
v2 = g.add_vertex(name='v2')
v1.connect(v2)

with self.assertWarns(DeprecationWarning):
n = v1.adjacent()
self.assertEqual(n, v1.neighbours())

def test_getitem(self):
g = UGraph()
v1 = g.add_vertex(name='v1')
Expand Down Expand Up @@ -282,6 +294,20 @@ def test_edge2(self):
self.assertTrue(v3 in v1.neighbours())
self.assertFalse(v4 in v1.neighbours())

def test_edge_vertices_deprecated(self):
# vertices() must still work (same result as endpoints) but emit
# a DeprecationWarning, not raise DeprecationWarning as a hard
# failure (raising it aborts the call exactly like a missing
# method would -- no backward compatibility at all)
g = UGraph()
v1 = g.add_vertex(name='v1')
v2 = g.add_vertex(name='v2')
e = v1.connect(v2)

with self.assertWarns(DeprecationWarning):
verts = e.vertices()
self.assertEqual(verts, e.endpoints)

def test_edge3(self):

g = UGraph()
Expand Down
Loading