Opened 3 years ago

Closed 3 years ago

#28874 closed enhancement (fixed)

Meaningful errors for immutable graphs

Reported by: gh-kliem Owned by:
Priority: major Milestone: sage-9.0
Component: graph theory Keywords: graphs, immutable, error messages
Cc: Dima Pasechnik Merged in:
Authors: Jonathan Kliem Reviewers: Travis Scrimshaw
Report Upstream: N/A Work issues:
Branch: b8b70e8 (Commits, GitHub, GitLab) Commit: b8b70e8a09b40b61092ebd6e972748731de11538
Dependencies: Stopgaps:

Status badges

Description

Currently, immutable graphs have meaningless error messages, e.g.

sage: G = Graph(immutable=True)
sage: G.add_edge(1,2)
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-6-86491c12b8ed> in <module>()
----> 1 G.add_edge(Integer(1),Integer(2))

/srv/public/shared/sage-8.9/local/lib/python2.7/site-packages/sage/graphs/generic_graph.pyc in add_edge(self, u, v, label)
  10834                     pass
  10835 
> 10836         self._backend.add_edge(u, v, label, self._directed)
  10837 
  10838     def add_edges(self, edges, loops=True):

/srv/public/shared/sage-8.9/local/lib/python2.7/site-packages/sage/graphs/base/graph_backends.pyx in sage.graphs.base.graph_backends.GenericGraphBackend.add_edge (build/cythonized/sage/graphs/base/graph_backends.c:1693)()
    101             NotImplementedError
    102          """
--> 103         raise NotImplementedError()
    104 
    105     def add_edges(self, edges, directed):

NotImplementedError: 

This might make it hard to figure out the underlying problem, e.g. when a cached method returns an immutable graph and the user isn't aware of it.

We add methods to the static sparse backend, that give an error just like is done for matrices or vectors

ValueError: graph is immutable; please change a copy instead (use function copy())

We also replace the old messages

ValueError: thou shalt not add a vertex to an immutable graph

for the one that points out a resolution for the user.

Change History (3)

comment:1 Changed 3 years ago by gh-kliem

Branch: public/28874
Commit: b8b70e8a09b40b61092ebd6e972748731de11538
Status: newneeds_review

New commits:

b8b70e8more meaningful errors for immutable graphs

comment:2 Changed 3 years ago by Travis Scrimshaw

Cc: Dima Pasechnik added
Reviewers: Travis Scrimshaw
Status: needs_reviewpositive_review

LGTM.

comment:3 Changed 3 years ago by Volker Braun

Branch: public/28874b8b70e8a09b40b61092ebd6e972748731de11538
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.