Skip to content

Commit 3756cd4

Browse files
author
Release Manager
committed
gh-39271: return correct error message when trying to add/delete vertex/edge from a static graph Fixes #39270. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #39271 Reported by: David Coudert Reviewer(s): Travis Scrimshaw
2 parents ff96023 + afb015f commit 3756cd4

File tree

1 file changed

+94
-7
lines changed

1 file changed

+94
-7
lines changed

src/sage/graphs/base/static_sparse_backend.pyx

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,28 @@ cdef class StaticSparseBackend(CGraphBackend):
557557
"""
558558
return v in self._vertex_to_int
559559

560+
def add_vertex(self, object v):
561+
r"""
562+
Add a vertex to the graph. No way
563+
564+
INPUT:
565+
566+
- ``v`` -- a vertex (or not?)
567+
568+
TESTS::
569+
570+
sage: from sage.graphs.base.static_sparse_backend import StaticSparseBackend
571+
sage: g = StaticSparseBackend(graphs.PetersenGraph())
572+
sage: g.add_vertex(123)
573+
Traceback (most recent call last):
574+
...
575+
ValueError: graph is immutable; please change a copy instead (use function copy())
576+
"""
577+
raise ValueError("graph is immutable; please change a copy instead (use function copy())")
578+
560579
cpdef add_edge(self, object u, object v, object l, bint directed):
561580
r"""
562-
Set edge label. No way.
581+
Add an edge to the graph. No way.
563582
564583
TESTS::
565584
@@ -572,9 +591,13 @@ cdef class StaticSparseBackend(CGraphBackend):
572591
"""
573592
raise ValueError("graph is immutable; please change a copy instead (use function copy())")
574593

575-
def add_edges(self, edges, directed):
594+
def add_edges(self, edges, directed, remove_loops=False):
576595
r"""
577-
Set edge label. No way.
596+
Add edges to the graph. No way.
597+
598+
INPUT:
599+
600+
- ``edges`` -- a list of edges (or not?)
578601
579602
TESTS::
580603
@@ -589,7 +612,11 @@ cdef class StaticSparseBackend(CGraphBackend):
589612

590613
def add_vertices(self, vertices):
591614
r"""
592-
Set edge label. No way.
615+
Add vertices to the graph. No way.
616+
617+
INPUT:
618+
619+
- ``vertices`` -- a list of vertices (or not?)
593620
594621
TESTS::
595622
@@ -602,15 +629,75 @@ cdef class StaticSparseBackend(CGraphBackend):
602629
"""
603630
raise ValueError("graph is immutable; please change a copy instead (use function copy())")
604631

605-
cpdef del_edge(self, object u, object v, object l, bint directed):
632+
def del_vertex(self, object v):
606633
r"""
607-
Set edge label. No way.
634+
Delete a vertex from the graph. No way
635+
636+
INPUT:
637+
638+
- ``v`` -- a vertex (or not?)
608639
609640
TESTS::
610641
611642
sage: from sage.graphs.base.static_sparse_backend import StaticSparseBackend
612643
sage: g = StaticSparseBackend(graphs.PetersenGraph())
613-
sage: g.set_edge_label(1,2,3,True)
644+
sage: g.del_vertex(123)
645+
Traceback (most recent call last):
646+
...
647+
ValueError: graph is immutable; please change a copy instead (use function copy())
648+
649+
Check that :issue:`39270` is fixed::
650+
651+
sage: g.del_vertex('a')
652+
Traceback (most recent call last):
653+
...
654+
ValueError: graph is immutable; please change a copy instead (use function copy())
655+
"""
656+
raise ValueError("graph is immutable; please change a copy instead (use function copy())")
657+
658+
def del_vertices(self, vertices):
659+
r"""
660+
Delete vertices from the graph. No way
661+
662+
INPUT:
663+
664+
- ``vertices`` -- a list of vertices (or not?)
665+
666+
TESTS::
667+
668+
sage: from sage.graphs.base.static_sparse_backend import StaticSparseBackend
669+
sage: g = StaticSparseBackend(graphs.PetersenGraph())
670+
sage: g.del_vertices([123, 234])
671+
Traceback (most recent call last):
672+
...
673+
ValueError: graph is immutable; please change a copy instead (use function copy())
674+
"""
675+
raise ValueError("graph is immutable; please change a copy instead (use function copy())")
676+
677+
def del_edge(self, object u, object v, object l, bint directed):
678+
r"""
679+
Delete an edge of the graph. No way.
680+
681+
TESTS::
682+
683+
sage: from sage.graphs.base.static_sparse_backend import StaticSparseBackend
684+
sage: g = StaticSparseBackend(graphs.PetersenGraph())
685+
sage: g.del_edge(1,2,3,True)
686+
Traceback (most recent call last):
687+
...
688+
ValueError: graph is immutable; please change a copy instead (use function copy())
689+
"""
690+
raise ValueError("graph is immutable; please change a copy instead (use function copy())")
691+
692+
def del_edges(self, edges, directed):
693+
r"""
694+
Delete edges of the graph. No way.
695+
696+
TESTS::
697+
698+
sage: from sage.graphs.base.static_sparse_backend import StaticSparseBackend
699+
sage: g = StaticSparseBackend(graphs.PetersenGraph())
700+
sage: g.del_edges([[1,2,3]], True)
614701
Traceback (most recent call last):
615702
...
616703
ValueError: graph is immutable; please change a copy instead (use function copy())

0 commit comments

Comments
 (0)