Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected ValueError when calling set_vertex() #27399

Closed
Rithesh17 mannequin opened this issue Mar 2, 2019 · 20 comments
Closed

Expected ValueError when calling set_vertex() #27399

Rithesh17 mannequin opened this issue Mar 2, 2019 · 20 comments

Comments

@Rithesh17
Copy link
Mannequin

Rithesh17 mannequin commented Mar 2, 2019

This is the issue discussed in the comments section of the ticket #14708:

sage: g = Graph()
sage: g.set_vertex('foo', 'bar')
sage: g.get_vertices()
{}

We should have expected a ValueError in the set_vertex() method. Also, on continuing,

sage: g.add_vertex('foo')
sage: g.get_vertices()
{'foo': 'bar'}

Which shouldn't have happened

Component: graph theory

Author: Rithesh K

Branch/Commit: 94ab6e8

Reviewer: David Coudert

Issue created by migration from https://trac.sagemath.org/ticket/27399

@Rithesh17 Rithesh17 mannequin added this to the sage-8.7 milestone Mar 2, 2019
@Rithesh17 Rithesh17 mannequin added c: graph theory labels Mar 2, 2019
@Rithesh17
Copy link
Mannequin Author

Rithesh17 mannequin commented Mar 2, 2019

New commits:

0ff156fPolyhedron documen modified
bba6a4aPolyhedron document modified.
32c1045set_vertices module in generic_graph.py modified

@Rithesh17
Copy link
Mannequin Author

Rithesh17 mannequin commented Mar 2, 2019

Branch: u/gh-Rithesh17/set_vertices-modified

@Rithesh17
Copy link
Mannequin Author

Rithesh17 mannequin commented Mar 2, 2019

Commit: 32c1045

@Rithesh17 Rithesh17 mannequin added the s: needs review label Mar 2, 2019
@fchapoton
Copy link
Contributor

comment:2

The branch is not clean, but it is mixed up with another branch.

@Rithesh17
Copy link
Mannequin Author

Rithesh17 mannequin commented Mar 2, 2019

New commits:

8ac6371set_vertex method in generic_graph.py modified

@Rithesh17
Copy link
Mannequin Author

Rithesh17 mannequin commented Mar 2, 2019

Changed commit from 32c1045 to 8ac6371

@Rithesh17
Copy link
Mannequin Author

Rithesh17 mannequin commented Mar 2, 2019

@Rithesh17 Rithesh17 mannequin self-assigned this Mar 2, 2019
@dcoudert
Copy link
Contributor

dcoudert commented Mar 3, 2019

comment:4

Welcome to Sagemath!

The following changes are needed in your patch:

  • don't use not self._backend.has_vertex(vertex) but not self.has_vertex(vertex) or vertex not in self
  • the error message is too long. You can reduce it as in method delete_vertex.
  • the error message is for vertex 4 in the doctest, not 1
    so you must do:
-            ValueError: vertex (1) not in the graph.
-            Please use add_vertex() method to add the vertex to the graph before setting it to the object.
+            ValueError: vertex (4) not in the graph

and

-        if not self._backend.has_vertex(vertex):
-            raise ValueError('vertex (%s) not in the graph.\nPlease use add_vertex() method to add the vertex to the graph before setting it to the object.'%str(vertex))
+        if vertex not in self:
+            raise ValueError('vertex (%s) not in the graph'%str(vertex))

To check that the changes you do are OK, you must run the doctests using for instance

sage -btp --long src/sage/graphs/generic_graph.py

@Rithesh17
Copy link
Mannequin Author

Rithesh17 mannequin commented Mar 3, 2019

@Rithesh17
Copy link
Mannequin Author

Rithesh17 mannequin commented Mar 3, 2019

Changed commit from 8ac6371 to dae0b72

@Rithesh17
Copy link
Mannequin Author

Rithesh17 mannequin commented Mar 3, 2019

comment:5

Thank you for the review. I have adopted all the suggestions provided.

I ran the doctests and this was the output:

Running doctests with ID 2019-03-04-00-34-10-23cf6891.
Git branch: set_vertex-mod
Using --optional=dochtml,gfortran,memlimit,mpir,python2,sage
Doctesting 1 file using 4 threads.
sage -t --long src/sage/graphs/generic_graph.py
    [3288 tests, 37.88 s]
----------------------------------------------------------------------
All tests passed!
----------------------------------------------------------------------
Total time for all tests: 38.8 seconds
    cpu time: 32.1 seconds
    cumulative wall time: 37.9 seconds


New commits:

feec578set_vertex method modified
dae0b72set_vertex method modified

@dcoudert
Copy link
Contributor

dcoudert commented Mar 4, 2019

comment:6

A minor issue: remove the . at the end of 'vertex (%s) not in the graph.' and of course in the doctest.

This is PEP8.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 4, 2019

Branch pushed to git repo; I updated commit sha1. New commits:

8ac6371set_vertex method in generic_graph.py modified
6582adbset_vertex method modified
34b1f60set_vertex method modified

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 4, 2019

Changed commit from dae0b72 to 34b1f60

@dcoudert
Copy link
Contributor

dcoudert commented Mar 5, 2019

Reviewer: David Coudert

@dcoudert
Copy link
Contributor

dcoudert commented Mar 5, 2019

comment:8

Further small remarks:

-            sage: T.set_vertex(4, graphs.DodecahedralGraph())
+            sage: T.set_vertex(4, 'foo')

There is no need to build the graph here as we just want to show that it is not possible to set label of a non existing vertex. Running all doctests is long, so when we can illustrate an issue with a smaller/faster example, it's always better.

-            raise ValueError('vertex (%s) not in the graph'%str(vertex))
+            raise ValueError('vertex (%s) not in the graph' % str(vertex))

this is also PEP8.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 5, 2019

Branch pushed to git repo; I updated commit sha1. New commits:

9ce02e6set_vertex method modified
94ab6e8set_vertex method modified

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 5, 2019

Changed commit from 34b1f60 to 94ab6e8

@dcoudert
Copy link
Contributor

dcoudert commented Mar 6, 2019

comment:10

For me this patch is good to go.

@vbraun
Copy link
Member

vbraun commented Mar 7, 2019

Changed branch from u/gh-Rithesh17/set_vertex-mod to 94ab6e8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants