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

clean graph_plot_js.py, graph_list.py and graph_input.py #26478

Closed
dcoudert opened this issue Oct 12, 2018 · 24 comments
Closed

clean graph_plot_js.py, graph_list.py and graph_input.py #26478

dcoudert opened this issue Oct 12, 2018 · 24 comments

Comments

@dcoudert
Copy link
Contributor

clean the files (PEP8) and simplify some tests

CC: @tscrim

Component: graph theory

Author: David Coudert

Branch/Commit: 2cf89df

Reviewer: Travis Scrimshaw

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

@dcoudert dcoudert added this to the sage-8.4 milestone Oct 12, 2018
@dcoudert
Copy link
Contributor Author

Branch: public/26478_cleaning

@dcoudert
Copy link
Contributor Author

Commit: 8c579b0

@dcoudert
Copy link
Contributor Author

New commits:

bfe7c08clean plot_graph_js.py
874eeb8clean graph_list.py
8c579b0clean graph_input.py

@dcoudert
Copy link
Contributor Author

comment:2

The most significant changes are in graph_input.py as I changed some tests.

@dcoudert

This comment has been minimized.

@tscrim
Copy link
Collaborator

tscrim commented Oct 12, 2018

comment:3

For this change:

-    if not loops and any(u in neighb for u,neighb in six.iteritems(M)):
-        if loops is False:
-            u = next(u for u,neighb in six.iteritems(M) if u in neighb)
-            raise ValueError("The graph was built with loops=False but input M has a loop at {}.".format(u))
-        loops = True
-    if loops is None:
-        loops = False
+    if any(not isinstance(M[u], dict) for u in M):
+        raise ValueError("input dict must be a consistent format")
+
+    if not loops:
+        for u, neighb in six.iteritems(M):
+            if u in neighb:
+                if loops is False:
+                    raise ValueError("the graph was built with loops=False but input M has a loop at {}".format(u))
+                loops = True
+                break
+        if loops is None:
+            loops = False

the any call is actually faster. Granted, your change will result in a faster error, but I think an error message being here is unexpected. Hence it is allowed to be slow. If someone really wants the extra speed and is using that test to separate cases, they should run their own test instead of catching the error (which is faster). So I am inclined to revert this.

Also, strictly speaking, the items for INPUT: are not sentences and do not end in a period (although some of them are sufficiently long with multiple parts that require it). While I was letting this slide when it was previously there, the ones you are adding should not have it.

All of the other changes LGTM.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 13, 2018

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

39aa69dtrac #26478: reviewers comments in graph_input
3826f1etrac #26478: reviewers comments in graph_list
90f89b0trac #26478: reviewers comments in graph_plot_js

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 13, 2018

Changed commit from 8c579b0 to 90f89b0

@dcoudert
Copy link
Contributor Author

comment:5

The following lines are apparently incompatible with Python 3 (see patchbot).

+        if any(u in neighb for u,neighb in six.iteritems(M)):
+                u = next(u for u,neighb in six.iteritems(M) if u in neighb)
+        if any(u in neighb for u, neighb in six.iteritems(D)):
+                u = next(u for u, neighb in six.iteritems(M) if u in neighb)

Is there a special trick or should I turn these lines to for loops ?

@fchapoton
Copy link
Contributor

comment:6

No, no. It's just the patchbot prefering "iteritems" to "six.iteritems". Just change the imports accordingly.

And once again, it is never mandatory to have all green lights from the patchbot, as the patchbot is not smart..

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 13, 2018

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

93ea7bdtrac #26478: fix six import in graph_input.py

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 13, 2018

Changed commit from 90f89b0 to 93ea7bd

@dcoudert
Copy link
Contributor Author

comment:8

Good to know. As I'm not Python 3 expert, I thought it could be something else.

@dcoudert dcoudert modified the milestones: sage-8.4, sage-8.5 Oct 18, 2018
@tscrim
Copy link
Collaborator

tscrim commented Oct 19, 2018

comment:10

Doctest failures:

File "src/sage/graphs/digraph.py", line 399, in sage.graphs.digraph.DiGraph
Failed example:
    D = DiGraph('IRAaDCIIOEOKcPWAo')
Expected:
    Traceback (most recent call last):
    ...
    RuntimeError: The string (IRAaDCIIOEOKcPWAo) seems corrupt: for n = 10, the string is too short.
Got:
    Traceback (most recent call last):
    ...
    RuntimeError: the string (IRAaDCIIOEOKcPWAo) seems corrupt: for n = 10, the string is too short

and similar in graph.py. Once fixed and the patchbot comes back green, then it will be a positive review.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 19, 2018

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

62403cdtrac #26478: fix doctests

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 19, 2018

Changed commit from 93ea7bd to 62403cd

@dcoudert
Copy link
Contributor Author

comment:12

I fixed the doctests. Now waiting for the patchbot.

@tscrim
Copy link
Collaborator

tscrim commented Oct 22, 2018

comment:13

Thanks.

@tscrim
Copy link
Collaborator

tscrim commented Oct 22, 2018

Reviewer: Travis Scrimshaw

@vbraun
Copy link
Member

vbraun commented Oct 22, 2018

comment:14

Merge conflict

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 23, 2018

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

2cf89dftrac #26478: fix merge conflict with 8.5.beta0

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 23, 2018

Changed commit from 62403cd to 2cf89df

@dcoudert
Copy link
Contributor Author

comment:16

I fixed the merge conflict with 8.5.beta0

@vbraun
Copy link
Member

vbraun commented Oct 24, 2018

Changed branch from public/26478_cleaning to 2cf89df

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

4 participants