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

Issue:
missing commits
@hagberg , @dschult  I just noticed that there is no ``doc/release/api_1.11.rst``, but there is one here:
  https://github.com/networkx/networkx/tree/v1.11
in ``doc/source/reference/api_1.11.rst``.  It appears this file was never committed on the master branch.

The v1.11 branch is " 59 commits ahead, 1066 commits behind master. "  So it looks like there may be a number of missing commits on master.  For example, this is also missing:
  https://github.com/networkx/networkx/commit/5665c71f3a9aec0325078de2de43537aee03386d
As this shows:
```
$ git lg networkx/drawing/tests/test_agraph.py
* d8ada85 - Make graph attributes work both to/from with agraph  (#2507) (11 days ago) [Dan Schult]
* 7bfb768 - Improve drawing test scripts (typos, newlines, methods) (1 year, 5 months ago) [Michael-E-Rose]
* f5031dd - Adjust imports in drawing layouts with graphviz (1 year, 6 months ago) [Dan Schult]
* 9922ec7 - doc, formatting, and whitespace cleanup (5 years ago) [Aric Hagberg]
* 47565b1 - Handle name in translation between pygraphviz (AGraph) and networkx. Fixes #734 (5 years ago) [Aric Hagberg]
* 3665bc1 - Update tests (6 years ago) [Aric Hagberg]
* d41d15f - More imports cleanup and exceptions fixed. (6 years ago) [Loïc Séguin-C.]
* baceff1 - Added tests for multigraph conversion to/from agraph. Changed from_agraph() so that the tests pass. (8 years ago) [dschult]
* ca6df32 - Convert drawing tests to functional tests and use SkipTest if optional packages are not available. (8 years ago) [aric]

```

I suspect that this was unintentional and that I should go through the missing commits and either cherry-pick the appropriate ones or make a new commit when cherry-picking doesn't work.  I just wanted to check whether I am correct before I go through the effort.  I will make a PR so you can review the commits I grab before merging to master.


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
@@ -1126,3 +1126,7 @@ def setup_module(module):
         import scipy
     except:
         raise SkipTest("SciPy not available")
+    try:
+        import pandas
+    except:
+        raise SkipTest("Pandas not available")


Test patch:
diff --git a/networkx/drawing/tests/test_agraph.py b/networkx/drawing/tests/test_agraph.py
--- a/networkx/drawing/tests/test_agraph.py
+++ b/networkx/drawing/tests/test_agraph.py
@@ -3,6 +3,8 @@
 import tempfile
 from nose import SkipTest
 from nose.tools import assert_true, assert_equal
+from networkx.testing import assert_edges_equal, assert_nodes_equal
+
 import networkx as nx
 
 
@@ -23,8 +25,8 @@ def build_graph(self, G):
         return G
 
     def assert_equal(self, G1, G2):
-        assert_equal(sorted(G1.nodes()), sorted(G2.nodes()))
-        assert_equal(sorted(G1.edges()), sorted(G2.edges()))
+        assert_nodes_equal(G1.nodes(), G2.nodes())
+        assert_edges_equal(G1.edges(), G2.edges())
         assert_equal(G1.graph['metal'], G2.graph['metal'])
 
     def agraph_checks(self, G):
Repository: networkx/networkx

Issue:
fixing a subset of nodes in spring_layout
The following layout works reasonably well,
```
import networkx as nx

G = nx.Graph()
G.add_edges_from([(0,1),(1,2),(2,0),(2,3)])
pos = nx.spring_layout(G)
print(pos)
```
However, the results from run to run are not easily reproduced because the initialization is random.  

To mitigate this we can fix node 0 to (0,0), as follows,
```
init_pos = {0:(0.0, 0.0)}
fixed_pos = [0]
pos = nx.spring_layout(G, pos=init_pos, fixed=fixed_pos)
print(pos)
```
This results in  the following error,
```
networkx/drawing/layout.py:342: RuntimeWarning: divide by zero encountered
```
A work around seems to be to provide initial points to all positions as follows,
```
import random
init_pos = {n:(random.uniform(-1.0, 1.0), random.uniform(-1.0, 1.0)) for n in G}
init_pos[0] = (0.0, 0.0)
fixed_pos = [0]
pos = nx.spring_layout(G, pos=init_pos, fixed=fixed_pos)
print(pos)
```


Discussion:
Interesting...  Thanks for the report. 

Setting the initial position to (1, 1) works.  The strange behavior occurs when setting one node to the origin. That occurs because we find the domain_size by taking the maximum value of all initial positions. Unfortunately, if that maximum value is ```0``` then the domain size is set to zero and all the points are initially put at the same point. That leads to a division by zero exception. 

I think a straightforward fix would be to check if there is only one initial point provided. If so, then set the domain_size to be 1.  

Would someone like to provide a pull request for this?  Thanks!
 

Resolving patch:
diff --git a/networkx/drawing/layout.py b/networkx/drawing/layout.py
--- a/networkx/drawing/layout.py
+++ b/networkx/drawing/layout.py
@@ -298,6 +298,8 @@ def fruchterman_reingold_layout(G, k=None,
     if pos is not None:
         # Determine size of existing domain to adjust initial positions
         dom_size = max(coord for pos_tup in pos.values() for coord in pos_tup)
+        if dom_size == 0:
+            dom_size = 1
         shape = (len(G), dim)
         pos_arr = np.random.random(shape) * dom_size + center
         for i, n in enumerate(G):


Test patch:
diff --git a/networkx/drawing/tests/test_layout.py b/networkx/drawing/tests/test_layout.py
--- a/networkx/drawing/tests/test_layout.py
+++ b/networkx/drawing/tests/test_layout.py
@@ -27,6 +27,18 @@ def setUp(self):
         nx.add_path(self.Gs, 'abcdef')
         self.bigG = nx.grid_2d_graph(25, 25) #bigger than 500 nodes for sparse
 
+    def test_spring_init_pos(self):
+        # Tests GH #2448
+        import math
+        G = nx.Graph()
+        G.add_edges_from([(0, 1), (1, 2), (2, 0), (2, 3)])
+
+        init_pos = {0: (0.0, 0.0)}
+        fixed_pos = [0]
+        pos = nx.fruchterman_reingold_layout(G, pos=init_pos, fixed=fixed_pos)
+        has_nan = any(math.isnan(c) for coords in pos.values() for c in coords)
+        assert_false(has_nan, 'values should not be nan')
+
     def test_smoke_int(self):
         G = self.Gi
         vpos = nx.random_layout(G)
Repository: networkx/networkx

Issue:
`networkx.version` shadows any other module named `version` if imported first
Steps to reproduce:

```
$ pip freeze | grep networkx
networkx==1.11
$ touch version.py
$ python -c 'import version; print(version)'
<module 'version' from '/Users/ben/scratch/version.py'>
$ python -c 'import networkx; import version; print(version)'
<module 'version' from '/Users/ben/.virtualenvs/personal/lib/python3.6/site-packages/networkx/version.py'>
```

Reading the code, it looks like the `release` module is adding the networkx package to `sys.path`, importing version and deleting it again?


Discussion:
Perhaps this may be fixed by moving some of the logic in release.py to setup.py using some static parsing? In one of my modules, my setup.py looks in the __init__.py file and statically parses the value of `__version__`. Here is that code adapted to networkx:

```python
def parse_version():
    """ Statically parse the version number from version.py """
    from os.path import dirname, join
    import ast
    init_fpath = join(dirname(__file__), 'networkx', 'version.py')
    with open(init_fpath) as file_:
        sourcecode = file_.read()
    pt = ast.parse(sourcecode)
    class VersionVisitor(ast.NodeVisitor):
        def visit_Assign(self, node):
            for target in node.targets:
                if target.id == 'version':
                    self.version = node.value.s
    visitor = VersionVisitor()
    visitor.visit(pt)
    return visitor.version
```

The above function assume you are running from `setup.py`. 

If the release.py code isn't actively being used in the networkx module, this may be a good alternative. 

Resolving patch:
diff --git a/networkx/release.py b/networkx/release.py
--- a/networkx/release.py
+++ b/networkx/release.py
@@ -101,9 +101,9 @@ def writefile():
             # This is *good*, and the most likely place users will be when
             # running setup.py. We do not want to overwrite version.py.
             # Grab the version so that setup can use it.
-            sys.path.insert(0, basedir)
+            #sys.path.insert(0, basedir)
             from version import version
-            del sys.path[0]
+            #del sys.path[0]
         else:
             # This is *bad*.  It means the user might have a tarball that
             # does not include version.py.  Let this error raise so we can
@@ -152,7 +152,7 @@ def get_info(dynamic=True):
         # This is where most final releases of NetworkX will be.
         # All info should come from version.py. If it does not exist, then
         # no vcs information will be provided.
-        sys.path.insert(0, basedir)
+        #sys.path.insert(0, basedir)
         try:
             from version import date, date_info, version, version_info, vcs_info
         except ImportError:
@@ -160,7 +160,7 @@ def get_info(dynamic=True):
             vcs_info = (None, (None, None))
         else:
             revision = vcs_info[1][0]
-        del sys.path[0]
+        #del sys.path[0]
 
     if import_failed or (dynamic and not dynamic_failed):
         # We are here if:


Test patch:
Repository: networkx/networkx

Issue:
Parameter 'nodes' is not effective in nx.effective_size()
https://github.com/networkx/networkx/blob/ca839ad24da9ec72abf920eaa33d3fce0a888f4a/networkx/algorithms/structuralholes.py#L144-L162

Parameter variable `nodes` is not used anymore after assigning the default value, which is `G`, at line 145. As another function `nx.constraint()` does in the same file, it seems that for-loops in this code snippet should iterate over `nodes`, not `G`.


Discussion:

Resolving patch:
diff --git a/networkx/algorithms/structuralholes.py b/networkx/algorithms/structuralholes.py
--- a/networkx/algorithms/structuralholes.py
+++ b/networkx/algorithms/structuralholes.py
@@ -97,7 +97,8 @@ def effective_size(G, nodes=None, weight=None):
         undirected graphs when computing neighbors of ``v``.
 
     nodes : container, optional
-        Container of nodes in the graph ``G``.
+        Container of nodes in the graph ``G`` to compute the effective size.
+        If None, the effective size of every node is computed.
 
     weight : None or string, optional
       If None, all edge weights are considered equal.
@@ -145,7 +146,7 @@ def redundancy(G, u, v, weight=None):
         nodes = G
     # Use Borgatti's simplified formula for unweighted and undirected graphs
     if not G.is_directed() and weight is None:
-        for v in G:
+        for v in nodes:
             # Effective size is not defined for isolated nodes
             if len(G[v]) == 0:
                 effective_size[v] = float('nan')
@@ -153,7 +154,7 @@ def redundancy(G, u, v, weight=None):
             E = nx.ego_graph(G, v, center=False, undirected=True)
             effective_size[v] = len(E) - (2 * E.size()) / len(E)
     else:
-        for v in G:
+        for v in nodes:
             # Effective size is not defined for isolated nodes
             if len(G[v]) == 0:
                 effective_size[v] = float('nan')
@@ -186,7 +187,8 @@ def constraint(G, nodes=None, weight=None):
         The graph containing ``v``. This can be either directed or undirected.
 
     nodes : container, optional
-        Container of nodes in the graph ``G``.
+        Container of nodes in the graph ``G`` to compute the constraint. If
+        None, the constraint of every node is computed.
 
     weight : None or string, optional
       If None, all edge weights are considered equal.


Test patch:
Repository: networkx/networkx

Issue:
Readthedocs pain
Readthedocs (RTD) is a pain to work with and keeps having timeout errors.  I started to look into whether we can build the docs on our own and push them to RTD instead of having it built on the site.  It would also make more sense to have the doc build process as part of our CI process, rather than only checked after the fact.

Has there been any discussion about moving away from RTD before (at least the build process)?  If so, was there a reason not to move?  I assume it is too late to move back to hosting the docs on github, but I thought I'd check since it might be easier to do.


Discussion:
When we moved to RTD (from hosting on github) the idea was that it would be simpler engineering than building and pushing docs to github.   If there is a CI approach that is reasonable to maintain that seems like a good path forward.  
I will look into our options then.

Resolving patch:
diff --git a/doc/conf.py b/doc/conf.py
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -199,7 +199,7 @@
 latex_appendices = ['tutorial']
 
 # Intersphinx mapping
-intersphinx_mapping = {'https://docs.python.org/': None,
+intersphinx_mapping = {'https://docs.python.org/2/': None,
                        'https://docs.scipy.org/doc/numpy/': None,
                        }
 


Test patch:
Repository: networkx/networkx

Issue:
Possible syntax error in gml.py (readwrite)
https://github.com/networkx/networkx/blob/e3566e53793cdccc19a8c2ff9c056e0d7b524634/networkx/readwrite/gml.py#L680

I've got an error when I want to write a .gml file from a network using the write_gml() function. At line 680 there is "test" instead of "text" I think. 


Discussion:
Yep, that is a bug.  Thanks for the report.   This is a simple fix.
You're welcome. 
By the way, very great and useful functions !  

Resolving patch:
diff --git a/networkx/readwrite/gml.py b/networkx/readwrite/gml.py
--- a/networkx/readwrite/gml.py
+++ b/networkx/readwrite/gml.py
@@ -677,7 +677,7 @@ def stringize(key, value, ignored_keys, indent, in_list=False):
                 if epos != -1 and text.find('.', 0, epos) == -1:
                     text = text[:epos] + '.' + text[epos:]
                 if key == 'label':
-                    yield indent + key + ' "' + test + '"'
+                    yield indent + key + ' "' + text + '"'
                 else:
                     yield indent + key + ' ' + text
             elif isinstance(value, dict):


Test patch:
diff --git a/networkx/readwrite/tests/test_gml.py b/networkx/readwrite/tests/test_gml.py
--- a/networkx/readwrite/tests/test_gml.py
+++ b/networkx/readwrite/tests/test_gml.py
@@ -278,6 +278,23 @@ def test_unicode_node(self):
 ]"""
         assert_equal(data, answer)
 
+    def test_float_label(self):
+        node = 1.0
+        G = nx.Graph()
+        G.add_node(node)
+        fobj = tempfile.NamedTemporaryFile()
+        nx.write_gml(G, fobj)
+        fobj.seek(0)
+        # Should be bytes in 2.x and 3.x
+        data = fobj.read().strip().decode('ascii')
+        answer = """graph [
+  node [
+    id 0
+    label "1.0"
+  ]
+]"""
+        assert_equal(data, answer)
+
     def test_name(self):
         G = nx.parse_gml('graph [ name "x" node [ id 0 label "x" ] ]')
         assert_equal('x', G.graph['name'])
Repository: networkx/networkx

Issue:
node-mapping bug expected_degree_graph
Hi I used the NX1 expected_degree_graph generator. It has the same interface as the NX2.

https://networkx.github.io/documentation/stable/reference/generated/networkx.generators.degree_seq.expected_degree_graph.html#networkx.generators.degree_seq.expected_degree_graph

But NX2 will not generate the graph correctly. The total number of edge is always 1. No further error message provided. 
Same script works well for NX1. (I downgrade to older version.

```python
D = 10
N = 1000
degree_l = [D for i in range(N)]
G = nx.expected_degree_graph(degree_l, seed=datetime.now(), selfloops=False)
```


Discussion:
That is certainly a bug -- Thanks for the report!

I think it was introduced two years ago in an attempt to make it more simple... but a typo snuck into the mapping on line 429:  ```mapping = {c: v for c, (u, v) in enumerate(order)}```   should be ```mapping = {c: u for c, (u, v) in enumerate(order)}```   Looks like we will need more tests (I haven't looked at them yet).
Yep, that looks like the right fix.

Resolving patch:
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
@@ -426,7 +426,7 @@ def expected_degree_graph(w, seed=None, selfloops=True):
     # weights dictates the order of the (integer) node labels, so we
     # need to remember the permutation applied in the sorting.
     order = sorted(enumerate(w), key=itemgetter(1), reverse=True)
-    mapping = {c: v for c, (u, v) in enumerate(order)}
+    mapping = {c: u for c, (u, v) in enumerate(order)}
     seq = [v for u, v in order]
     last = n
     if not selfloops:


Test patch:
diff --git a/networkx/generators/tests/test_degree_seq.py b/networkx/generators/tests/test_degree_seq.py
--- a/networkx/generators/tests/test_degree_seq.py
+++ b/networkx/generators/tests/test_degree_seq.py
@@ -92,6 +92,8 @@ def test_expected_degree_graph():
     # test that fixed seed delivers the same graph
     deg_seq = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]
     G1 = nx.expected_degree_graph(deg_seq, seed=1000)
+    assert_equal(len(G1), 12)
+
     G2 = nx.expected_degree_graph(deg_seq, seed=1000)
     assert_true(nx.is_isomorphic(G1, G2))
 
@@ -105,6 +107,7 @@ def test_expected_degree_graph_selfloops():
     G1 = nx.expected_degree_graph(deg_seq, seed=1000, selfloops=False)
     G2 = nx.expected_degree_graph(deg_seq, seed=1000, selfloops=False)
     assert_true(nx.is_isomorphic(G1, G2))
+    assert_equal(len(G1), 12)
 
 
 def test_expected_degree_graph_skew():
@@ -112,6 +115,7 @@ def test_expected_degree_graph_skew():
     G1 = nx.expected_degree_graph(deg_seq, seed=1000)
     G2 = nx.expected_degree_graph(deg_seq, seed=1000)
     assert_true(nx.is_isomorphic(G1, G2))
+    assert_equal(len(G1), 5)
 
 
 def test_havel_hakimi_construction():
Repository: networkx/networkx

Issue:
Allow line_graph to apply to multigraph
The code is written for multigraphs and graphs, but recently put an errant restriction on multigraphs.
Line 24 of line.py

See #2814 

Short term fix is to call ```nx.generators.line._lg_undirected```


Discussion:

Resolving patch:
diff --git a/networkx/generators/line.py b/networkx/generators/line.py
--- a/networkx/generators/line.py
+++ b/networkx/generators/line.py
@@ -21,7 +21,6 @@
 __all__ = ['line_graph', 'inverse_line_graph']
 
 
-@not_implemented_for('multigraph')
 def line_graph(G, create_using=None):
     """Returns the line graph of the graph or digraph `G`.
 


Test patch:
Repository: networkx/networkx

Issue:
Please update documentation to reflect changes from 1.X to 2.X - set_node_attributes
Hello,

After having spent a good few hours trying to figure out why the following wouldn't work (copied from the documentation page on set_node_attributes).

>>> G = nx.path_graph(3)
>>> bb = nx.betweenness_centrality(G)  # this is a dictionary
>>> nx.set_node_attributes(G, 'betweenness', bb)

**TypeError: unhashable type: 'dict'**

I had almost managed to convince myself that NetworkX hadn't been updated to work with Python 3.X

Turns out in the migration from NetworkX 1.X to 2.0 the argument order was swapped around to:

nx.set_node_attributes(G, bb, 'betweenness')

Please make an update to the documentation page for set_node_attributes here: 
[http://pelegm-networkx.readthedocs.io/en/latest/reference/generated/networkx.classes.function.set_node_attributes.html](url)

So that poor new users to NetworkX and Python don't have to suffer through this. It shouldn't be a requirement to have to go through this [https://networkx.github.io/documentation/stable/release/migration_guide_from_1.x_to_2.0.html](url)
to get the right format to make it work. 

Many thanks!


Discussion:
Yes -- we should put a note/warning in the docstring for ```set_node_attributes``` that the order was changed between 1.x and 2.x
@achilleasatha Amen! Just went through the same ordeal myself.

Resolving patch:
diff --git a/networkx/classes/function.py b/networkx/classes/function.py
--- a/networkx/classes/function.py
+++ b/networkx/classes/function.py
@@ -585,6 +585,9 @@ def info(G, n=None):
 def set_node_attributes(G, values, name=None):
     """Sets node attributes from a given value or dictionary of values.
 
+    .. Warning:: The call order of arguments `values` and `name`
+        switched between v1.x & v2.x.
+
     Parameters
     ----------
     G : NetworkX Graph
@@ -694,6 +697,9 @@ def get_node_attributes(G, name):
 def set_edge_attributes(G, values, name=None):
     """Sets edge attributes from a given value or dictionary of values.
 
+    .. Warning:: The call order of arguments `values` and `name`
+        switched between v1.x & v2.x.
+
     Parameters
     ----------
     G : NetworkX Graph


Test patch:
Repository: networkx/networkx

Issue:
For LFR Benchmark Graph Generation, the docs do not match the parameter requirements
A user reading the online or inline documentation will read the following potential raised errors when using the LFR benchmark graph generation function:
```
Raises
    ------
    NetworkXError
        If any of the parameters do not meet their upper and lower bounds:

        - ``tau1`` and ``tau2`` must be less than or equal to one.
        - ``mu`` must be in [0, 1].
        - ``max_degree`` must be in {1, ..., *n*}.
        - ``min_community`` and ``max_community`` must be in {0, ...,
          *n*}.

        If not exactly one of ``average_degree`` and ``min_degree`` is
        specified.

        If ``min_degree`` is not specified and a suitable ``min_degree``
        cannot be found.
```

However, this is not how this function behaves. Below, note the inequality checks on tau and tau2:

```
    if not tau1 > 1:
        raise nx.NetworkXError("tau1 must be greater than one")
    if not tau2 > 1:
        raise nx.NetworkXError("tau2 must be greater than one")
```

Either the docs need to be updated to reflect tau1, tau2 > 1 or the inline inequality checks need to be modified to allow tau1 and tau2 to equal 1.


Discussion:
I was looking at the documentation here: https://networkx.github.io/documentation/latest/_modules/networkx/algorithms/community/community_generators.html#LFR_benchmark_graph which upon closer inspection does not match `master`. Looks like no change is needed except for to update the documentation on networkx.github.io, which will happen at release time.

Resolving patch:
diff --git a/networkx/algorithms/community/community_generators.py b/networkx/algorithms/community/community_generators.py
--- a/networkx/algorithms/community/community_generators.py
+++ b/networkx/algorithms/community/community_generators.py
@@ -268,7 +268,7 @@ def LFR_benchmark_graph(n, tau1, tau2, mu, average_degree=None,
     NetworkXError
         If any of the parameters do not meet their upper and lower bounds:
 
-        - ``tau1`` and ``tau2`` must be less than or equal to one.
+        - ``tau1`` and ``tau2`` must be strictly greater than 1.
         - ``mu`` must be in [0, 1].
         - ``max_degree`` must be in {1, ..., *n*}.
         - ``min_community`` and ``max_community`` must be in {0, ...,


Test patch:
Repository: networkx/networkx

Issue:
doc/_static/copybutton.js is missing from PyPI tarball for networkx 2.1
Hello,
`doc/_static/copybutton.js` is currently missing while it's being referred by almost all the HTML webpage.

can you please add it to the PyPI released tarball?

thanks!


Discussion:
I run a diff on pypi release and github release and found more missing files, which may also be the cause of #2941. I'll send a PR later.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -81,6 +81,10 @@
     data.append((dd, glob(os.path.join(pp, "*.gz"))))
     data.append((dd, glob(os.path.join(pp, "*.mbox"))))
     data.append((dd, glob(os.path.join(pp, "*.edgelist"))))
+# add js force examples
+dd = os.path.join(docdirbase, 'examples', 'javascript/force')
+pp = os.path.join('examples', 'javascript/force')
+data.append((dd, glob(os.path.join(pp, "*"))))
 
 # add the tests
 package_data = {


Test patch: