internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: networkx/networkx

Issue:
change in pandas breaks doctest in python 3.6
It looks like that the recent change in pandas: https://github.com/pandas-dev/pandas/pull/19884 is breaking one of the doctest in python 3.6.

I'm not sure what would be the best solution here since py2 and py3 behave differently and the difference is not crucial at all. One way to fix this would be use an `OrderedDict` but it feels like an overkill.

```
======================================================================
FAIL: to_pandas_edgelist (networkx.convert_matrix)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/python/3.6.3/lib/python3.6/doctest.py", line 2199, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for networkx.convert_matrix.to_pandas_edgelist
  File "/home/travis/venv/lib/python3.6/site-packages/networkx/convert_matrix.py", line 192, in to_pandas_edgelist
----------------------------------------------------------------------
File "/home/travis/venv/lib/python3.6/site-packages/networkx/convert_matrix.py", line 221, in networkx.convert_matrix.to_pandas_edgelist
Failed example:
    df
Expected:
       cost source target  weight
    0     1      A      B       7
    1     9      C      E      10
Got:
      source target  weight  cost
    0      A      B       7     1
    1      C      E      10     9
```


Discussion:

Resolving patch:
diff --git a/networkx/convert_matrix.py b/networkx/convert_matrix.py
--- a/networkx/convert_matrix.py
+++ b/networkx/convert_matrix.py
@@ -218,10 +218,10 @@ def to_pandas_edgelist(G, source='source', target='target', nodelist=None,
     >>> G = nx.Graph([('A', 'B', {'cost': 1, 'weight': 7}),
     ...               ('C', 'E', {'cost': 9, 'weight': 10})])
     >>> df = nx.to_pandas_edgelist(G, nodelist=['A', 'C'])
-    >>> df
-       cost source target  weight
-    0     1      A      B       7
-    1     9      C      E      10
+    >>> df[['source', 'target', 'cost', 'weight']]
+      source target  cost  weight
+    0      A      B     1       7
+    1      C      E     9      10
 
     """
     import pandas as pd
@@ -290,7 +290,7 @@ def from_pandas_edgelist(df, source='source', target='target', edge_attr=None,
     >>> df = pd.DataFrame(ints, columns=['weight', 'cost'])
     >>> df[0] = a
     >>> df['b'] = b
-    >>> df
+    >>> df[['weight', 'cost', 0, 'b']]
        weight  cost  0  b
     0       4     7  A  D
     1       7     1  B  A


Test patch:
Repository: networkx/networkx

Issue:
min_cost_flow does not throw an exception when the graph is disconnected
According to the docs ([here](https://networkx.github.io/documentation/stable/reference/algorithms/generated/networkx.algorithms.flow.min_cost_flow.html)), `min_cost_flow` is supposed to throw an exception if the source vertex is not connected to destination vertex. 
On the contrary, the following code is stuck in an infinite loop:

```
G = nx.DiGraph()
G.add_nodes_from(range(5), demand=0)
G.node[4]['demand'] = -13
G.node[3]['demand'] = 13

edges = [
(0, 2, {'capacity': 20, 'weight': 0.1}),
(0, 3, {'capacity': 20, 'weight': 0.1}),
(2, 1, {'capacity': 20, 'weight': 0.1})]
G.add_edges_from(edges)
flowDict = nx.min_cost_flow(G)
```

Is this a bug?
I am using version 2.1


Discussion:
Thanks for this bug report!  I can verify that an infinite loop occurs with this example.

In the method that looks for cycles when 1 edge is found, the edge is duplicated (line #388) when it shouldn't be.  I'll put a PR in shortly.


Resolving patch:
diff --git a/networkx/algorithms/flow/networksimplex.py b/networkx/algorithms/flow/networksimplex.py
--- a/networkx/algorithms/flow/networksimplex.py
+++ b/networkx/algorithms/flow/networksimplex.py
@@ -385,7 +385,8 @@ def find_cycle(i, p, q):
         Wn, We = trace_path(p, w)
         Wn.reverse()
         We.reverse()
-        We.append(i)
+        if We != [i]:
+            We.append(i)
         WnR, WeR = trace_path(q, w)
         del WnR[-1]
         Wn += WnR


Test patch:
diff --git a/networkx/algorithms/flow/tests/test_mincost.py b/networkx/algorithms/flow/tests/test_mincost.py
--- a/networkx/algorithms/flow/tests/test_mincost.py
+++ b/networkx/algorithms/flow/tests/test_mincost.py
@@ -321,6 +321,18 @@ def test_digon(self):
         assert_equal(H, soln)
         assert_equal(nx.cost_of_flow(G, H), 2857140)
 
+    def test_deadend(self):
+        """Check if one-node cycles are handled properly. Taken from ticket
+        #2906 from @sshraven."""
+        G = nx.DiGraph()
+
+        G.add_nodes_from(range(5), demand=0)
+        G.node[4]['demand'] = -13
+        G.node[3]['demand'] = 13
+
+        G.add_edges_from([(0,2), (0, 3), (2, 1)], capacity=20, weight=0.1)
+        assert_raises(nx.NetworkXUnfeasible, nx.min_cost_flow, G)
+
     def test_infinite_capacity_neg_digon(self):
         """An infinite capacity negative cost digon results in an unbounded
         instance."""
Repository: networkx/networkx

Issue:
Computed but unused line in DegreeSequenceRandomGraph
norm in `phase2()` of class `DegreeSequenceRandomGraph` is computed but unused.
```
norm = float(max(self.remaining_degree.values()))**2
```
in
```
    def phase2(self):
        # choose remaining nodes uniformly at random and use rejection sampling
        while len(self.remaining_degree) >= 2 * self.dmax:
            norm = float(max(self.remaining_degree.values()))**2
            while True:
                u, v = sorted(random.sample(self.remaining_degree.keys(), 2))
                if self.graph.has_edge(u, v):
                    continue
                if random.random() < self.q(u, v):
                    break
            if random.random() < self.p(u, v):  # accept edge
                self.graph.add_edge(u, v)
```
[code](https://networkx.github.io/documentation/stable/_modules/networkx/generators/degree_seq.html#random_degree_sequence_graph)


Discussion:

Resolving patch:
diff --git a/networkx/algorithms/approximation/dominating_set.py b/networkx/algorithms/approximation/dominating_set.py
--- a/networkx/algorithms/approximation/dominating_set.py
+++ b/networkx/algorithms/approximation/dominating_set.py
@@ -38,7 +38,7 @@ def min_weighted_dominating_set(G, weight=None):
         Undirected graph.
 
     weight : string
-        The node attribute storing the weight of an edge. If provided,
+        The node attribute storing the weight of an node. If provided,
         the node attribute with this key must be a number for each
         node. If not provided, each node is assumed to have weight one.
 
diff --git a/networkx/generators/degree_seq.py b/networkx/generators/degree_seq.py
--- a/networkx/generators/degree_seq.py
+++ b/networkx/generators/degree_seq.py
@@ -116,7 +116,7 @@ def _configuration_model(deg_sequence, create_using, directed=False,
         return G
     # Build a list of available degree-repeated nodes.  For example,
     # for degree sequence [3, 2, 1, 1, 1], the "stub list" is
-    # initially [1, 1, 1, 2, 2, 3, 4, 5], that is, node 1 has degree
+    # initially [0, 0, 0, 1, 1, 2, 3, 4], that is, node 0 has degree
     # 3 and thus is repeated 3 times, etc.
     #
     # Also, shuffle the stub list in order to get a random sequence of
@@ -837,7 +837,6 @@ def phase1(self):
     def phase2(self):
         # choose remaining nodes uniformly at random and use rejection sampling
         while len(self.remaining_degree) >= 2 * self.dmax:
-            norm = float(max(self.remaining_degree.values()))**2
             while True:
                 u, v = sorted(random.sample(self.remaining_degree.keys(), 2))
                 if self.graph.has_edge(u, v):


Test patch:
Repository: networkx/networkx

Issue:
Travis nbconvert giving error
We are building the docs on Travis and converting the examples to Jupyter notebooks for the gallery. (This is using python2.7).  It started showing [a new error this weekend](https://travis-ci.org/networkx/networkx/jobs/396510217)  It looks like libpng is not behaving nicely. I'm not sure where to look for answers to this one.


Discussion:
@jarrodmillman do you have time to look at the travis doc-build errors that started about 3 days ago? Even some quick tips on how to go about debugging it would be really helpful.  Thanks!   :)
I'll take a look later today (at this and a couple other outstanding items).

Resolving patch:
diff --git a/networkx/generators/random_graphs.py b/networkx/generators/random_graphs.py
--- a/networkx/generators/random_graphs.py
+++ b/networkx/generators/random_graphs.py
@@ -470,6 +470,11 @@ def connected_watts_strogatz_graph(n, k, p, tries=100, seed=None):
     newman_watts_strogatz_graph()
     watts_strogatz_graph()
 
+    References
+    ----------
+    .. [1] Duncan J. Watts and Steven H. Strogatz,
+       Collective dynamics of small-world networks,
+       Nature, 393, pp. 440--442, 1998.
     """
     for i in range(tries):
         G = watts_strogatz_graph(n, k, p, seed)


Test patch:
Repository: networkx/networkx

Issue:
`view_pygraphviz` fails for a `path` that is `str`
In the following, `view_pygraphviz` works fine:

    import networkx
    G = networkx.generators.trees.random_tree(100)
    networkx.drawing.nx_agraph.view_pygraphviz(G, prog="dot", args="-Nshape=box");

But when you try to specify the `path` which is supposed to be a `str`...

    import networkx
    G = networkx.generators.trees.random_tree(100)
    networkx.drawing.nx_agraph.view_pygraphviz(G, path="mytest.png", prog="dot", args="-Nshape=box");

...it raises `TypeError: write() argument must be str, not bytes` from within `pygraphviz/agraph::draw()`.

Now, if you:

    import networkx
    G = networkx.generators.trees.random_tree(100)
    A = networkx.drawing.nx_agraph.to_agraph(G)
    A.draw("mytest.png", prog="dot")

This will work fine, minus of course the specific formatting (graph, edge, node appearance) that `networkx` adds in `view_pygraphviz`.

Therefore, the "problem" must be in `view_pygraphviz`.

After a bit of experimentation, it turns out that this works:

    import networkx
    G = networkx.generators.trees.random_tree(100)
    networkx.drawing.nx_agraph.view_pygraphviz(G, path=open("mytest.png", "w+b"), prog="dot", args="-Nshape=box");

The hint to pass a file descriptor rather than a `str` was obtained from [the documentation](https://github.com/networkx/networkx/blob/master/networkx/drawing/nx_agraph.py#L425), specifically *"# Assume the decorator worked and it is a file-object."*.

Is this a bug? If not, which decorator does this function hint at?

**EDIT:**

Netowrkx version 2.1, Python version 3.5.2


Discussion:
The decorator is ```open_file``` (it appears in the line before the function signature ```def ...``` with an ```@``` in front.  The decorator is defined in ```networkx/utils/decorators.py``` and opens the file if needed, or passes the file object through otherwise.

You have clearly found a work-around for the error. But it'd be nice to fix this...

In looking at both this code and the code for pygraphviz, it looks like we should have the decorator specify mode ```'w+b'```.  But I'm not close to machines that can easily test whether this works for the different cases and versions of OS/python/etc.  Can you easily verify that changing the 'w' to 'w+b' in the ```@nx.utils.open_file``` decorator fixes this bug?

Resolving patch:
diff --git a/networkx/drawing/nx_agraph.py b/networkx/drawing/nx_agraph.py
--- a/networkx/drawing/nx_agraph.py
+++ b/networkx/drawing/nx_agraph.py
@@ -301,7 +301,7 @@ def pygraphviz_layout(G, prog='neato', root=None, args=''):
     return node_pos
 
 
-@nx.utils.open_file(5, 'w')
+@nx.utils.open_file(5, 'w+b')
 def view_pygraphviz(G, edgelabel=None, prog='dot', args='',
                     suffix='', path=None):
     """Views the graph G using the specified layout algorithm.


Test patch:
Repository: networkx/networkx

Issue:
eigenvector_centrality() docstring needs rewording
The docstring for eigenvector_centrality() refers to the cluster centrality of a node i and then proceeds to give an equation for the vector of cluster centrality for all nodes. Suggest rewording similar to the katz_similarity() method.


Discussion:
```katz_similarity``` also gives an equation for the vector (actually an equation giving one element of the vector in terms of all the others). But some improvement to the docs seems simple and easy to do. Would you like to take a shot at making the equation for eigenvector_centrality easier to read?

Resolving patch:
diff --git a/networkx/algorithms/centrality/eigenvector.py b/networkx/algorithms/centrality/eigenvector.py
--- a/networkx/algorithms/centrality/eigenvector.py
+++ b/networkx/algorithms/centrality/eigenvector.py
@@ -28,16 +28,16 @@ def eigenvector_centrality(G, max_iter=100, tol=1.0e-6, nstart=None,
 
     Eigenvector centrality computes the centrality for a node based on the
     centrality of its neighbors. The eigenvector centrality for node $i$ is
+    the $i$-th element of the vector $x$ defined by the equation
 
     .. math::
 
         Ax = \lambda x
 
     where $A$ is the adjacency matrix of the graph `G` with eigenvalue
-    $\lambda$. By virtue of the Perron–Frobenius theorem, there is
-    a unique and positive solution if $\lambda$ is the largest
-    eigenvalue associated with the eigenvector of the adjacency matrix
-    $A$ ([2]_).
+    $\lambda$. By virtue of the Perron–Frobenius theorem, there is a unique
+    solution $x$, all of whose entries are positive, if $\lambda$ is the
+    largest eigenvalue of the adjacency matrix $A$ ([2]_).
 
     Parameters
     ----------


Test patch:
Repository: networkx/networkx

Issue:
G.predecessors(node) documentation could benefit from additional explanation
I'm on a _tree_ network similar to this toy,

    [('total_fruits', 'apples'),
     ('total_fruits_and_vegetables', 'total_fruits'),
     ('total_fruits_and_vegetables', 'total_vegetables'),
     ('total_vegetables', 'carrot')]

To find the root node I'm using this solution on StackOverflow: [NetworkX find root_node for a particular node in a directed graph](https://stackoverflow.com/a/47191030/343215). This solution works, but I think the documentation could be clearer. 

The documentation for predecessor [networkx.DiGraph.predecessors](https://networkx.github.io/documentation/stable/reference/classes/generated/networkx.DiGraph.predecessors.html) says: 

> DiGraph.predecessors(n)[source]
> Return an iterator over predecessor nodes of n.

For my tree I expected G.predecessors(node) output to return _all_ of the predecessors to the root,

    [n for n in G.predecessors('apples')]
    >>> ['apples', ''total_fruits', 'total_fruits_and_vegetables']

But what I get:

    [n for n in G.predecessors('apples')]
    >>>['total_fruits']

Finally, I realized _nodes_ refers to the predecessors one level or edge from the node parameter, because the network may not be a tree. 

In this edge case I'm asking if maybe the documentation could benefit further description.


Discussion:
Yes -- and that docstring is really VERY minimal...  It doesn't even say what the input or output arguments are. There may be others in that category like ```G.successors``` but I haven't checked.
Pull requests would be helpful...

Resolving patch:
diff --git a/networkx/classes/digraph.py b/networkx/classes/digraph.py
--- a/networkx/classes/digraph.py
+++ b/networkx/classes/digraph.py
@@ -769,6 +769,25 @@ def has_predecessor(self, u, v):
     def successors(self, n):
         """Return an iterator over successor nodes of n.
 
+        A successor of n is a node m such that there exists a directed
+        edge from n to m.
+
+        Parameters
+        ----------
+        n : node
+           A node in the graph
+
+        Raises
+        -------
+        NetworkXError
+           If n is not in the graph.
+
+        See Also
+        --------
+        predecessors
+
+        Notes
+        -----
         neighbors() and successors() are the same.
         """
         try:
@@ -780,7 +799,25 @@ def successors(self, n):
     neighbors = successors
 
     def predecessors(self, n):
-        """Return an iterator over predecessor nodes of n."""
+        """Return an iterator over predecessor nodes of n.
+
+        A predecessor of n is a node m such that there exists a directed
+        edge from m to n.
+
+        Parameters
+        ----------
+        n : node
+           A node in the graph
+
+        Raises
+        -------
+        NetworkXError
+           If n is not in the graph.
+
+        See Also
+        --------
+        successors
+        """
         try:
             return iter(self._pred[n])
         except KeyError:


Test patch:
Repository: networkx/networkx

Issue:
Double import
I noticed that in `networkx/algorithms/__init__.py`the statement `from networkx.algorithms.triads import *` occurs twice. Is there any reason for this or is this just a blunder?


Discussion:
That's a blunder...  probably happened when we alphabetized the list a little while ago.

Resolving patch:
diff --git a/networkx/algorithms/__init__.py b/networkx/algorithms/__init__.py
--- a/networkx/algorithms/__init__.py
+++ b/networkx/algorithms/__init__.py
@@ -40,7 +40,6 @@
 from networkx.algorithms.smallworld import *
 from networkx.algorithms.smetric import *
 from networkx.algorithms.structuralholes import *
-from networkx.algorithms.triads import *
 from networkx.algorithms.sparsifiers import *
 from networkx.algorithms.swap import *
 from networkx.algorithms.traversal import *


Test patch:
Repository: networkx/networkx

Issue:
Default color for draw_networkx() is not colorblind-safe
Currently black labels on red background, which can't be read by some red-green colorblind individuals (including myself). The safest would be to go with a blue color. Any objections?


Discussion:
That seems good to me.

Here's a plug for a project related to this stuff that needs some energy: -- there is a package called GraVE which integrates ideas and code from Matplotlib and NetworkX to ease and enable better drawing.   https://github.com/networkx/grave


Resolving patch:
diff --git a/networkx/drawing/nx_pylab.py b/networkx/drawing/nx_pylab.py
--- a/networkx/drawing/nx_pylab.py
+++ b/networkx/drawing/nx_pylab.py
@@ -179,7 +179,7 @@ def draw_networkx(G, pos=None, arrows=True, with_labels=True, **kwds):
        Size of nodes.  If an array is specified it must be the
        same length as nodelist.
 
-    node_color : color string, or array of floats, (default='r')
+    node_color : color string, or array of floats, (default='#1f78b4')
        Node color. Can be a single color format string,
        or a  sequence of colors with the same length as nodelist.
        If numeric values are specified they will be mapped to
@@ -284,7 +284,7 @@ def draw_networkx(G, pos=None, arrows=True, with_labels=True, **kwds):
 def draw_networkx_nodes(G, pos,
                         nodelist=None,
                         node_size=300,
-                        node_color='r',
+                        node_color='#1f78b4',
                         node_shape='o',
                         alpha=1.0,
                         cmap=None,
@@ -319,7 +319,7 @@ def draw_networkx_nodes(G, pos,
        same length as nodelist.
 
     node_color : color string, or array of floats
-       Node color. Can be a single color format string (default='r'),
+       Node color. Can be a single color format string (default='#1f78b4'),
        or a  sequence of colors with the same length as nodelist.
        If numeric values are specified they will be mapped to
        colors using the cmap and vmin,vmax parameters.  See


Test patch:
Repository: networkx/networkx

Issue:
Remove axis ticks and tick labels from default network visualization
The axis ticks are districting and in most cases unnecessary.


Discussion:

Resolving patch:
diff --git a/networkx/drawing/nx_pylab.py b/networkx/drawing/nx_pylab.py
--- a/networkx/drawing/nx_pylab.py
+++ b/networkx/drawing/nx_pylab.py
@@ -412,6 +412,13 @@ def draw_networkx_nodes(G, pos,
                                  linewidths=linewidths,
                                  edgecolors=edgecolors,
                                  label=label)
+    plt.tick_params(
+        axis='both',
+        which='both',
+        bottom=False,
+        left=False,
+        labelbottom=False,
+        labelleft=False)
 
     node_collection.set_zorder(2)
     return node_collection
@@ -702,6 +709,14 @@ def to_marker_edge(marker_size, marker):
     ax.update_datalim(corners)
     ax.autoscale_view()
 
+    plt.tick_params(
+        axis='both',
+        which='both',
+        bottom=False,
+        left=False,
+        labelbottom=False,
+        labelleft=False)
+
     return arrow_collection
 
 
@@ -808,6 +823,14 @@ def draw_networkx_labels(G, pos,
                     clip_on=True,
                     )
         text_items[n] = t
+        
+    plt.tick_params(
+        axis='both',
+        which='both',
+        bottom=False,
+        left=False,
+        labelbottom=False,
+        labelleft=False)
 
     return text_items
 
@@ -954,6 +977,14 @@ def draw_networkx_edge_labels(G, pos,
                     )
         text_items[(n1, n2)] = t
 
+    plt.tick_params(
+        axis='both',
+        which='both',
+        bottom=False,
+        left=False,
+        labelbottom=False,
+        labelleft=False)
+
     return text_items
 
 


Test patch:
Repository: networkx/networkx

Issue:
Deprecationwarning in digraph.py 'ReverseView is deprecated. Use reverse_view instead'
```
  /usr/local/lib/python3.7/site-packages/networkx/classes/digraph.py:1186: DeprecationWarning: ReverseView is deprecated. Use reverse_view instead
    return nx.graphviews.ReverseView(self)
```

This is from networkx 2.2, I checked the current source and I see the issue is still in master, now on line [1201](https://github.com/networkx/networkx/blob/master/networkx/classes/digraph.py#L1201)



Discussion:

Resolving patch:
diff --git a/networkx/classes/digraph.py b/networkx/classes/digraph.py
--- a/networkx/classes/digraph.py
+++ b/networkx/classes/digraph.py
@@ -1198,4 +1198,4 @@ def reverse(self, copy=True):
             H.add_edges_from((v, u, deepcopy(d)) for u, v, d
                              in self.edges(data=True))
             return H
-        return nx.graphviews.ReverseView(self)
+        return nx.graphviews.reverse_view(self)


Test patch:
Repository: networkx/networkx

Issue:
Bug in networkx/algorithms/shortest_paths/unweighted.py
Line 415/416 of **networkc/algorithms/shortest_paths/unweighted.py** reads

`    if target not in G:
        raise nx.NodeNotFound("Target {} not in G".format(source))`

should read 

`    if target not in G:
        raise nx.NodeNotFound("Target {} not in G".format(target))`



Discussion:

Resolving patch:
diff --git a/networkx/algorithms/shortest_paths/unweighted.py b/networkx/algorithms/shortest_paths/unweighted.py
--- a/networkx/algorithms/shortest_paths/unweighted.py
+++ b/networkx/algorithms/shortest_paths/unweighted.py
@@ -413,7 +413,7 @@ def single_target_shortest_path(G, target, cutoff=None):
     shortest_path, single_source_shortest_path
     """
     if target not in G:
-        raise nx.NodeNotFound("Target {} not in G".format(source))
+        raise nx.NodeNotFound("Target {} not in G".format(target))
 
     def join(p1, p2):
         return p2 + p1


Test patch: