Repository: xgi-org/xgi

Issue:
Issue adding edge attributes
When I run
```python
weights = dict(zip(list(H.edges), np.random.choice([-1, 1], size=m)))
H.set_edge_attributes(weights, name="weight")
```
I get the error `Edge <id> does not exist!` I have an easy fix for this which I will push.

Discussion:
review-notebook-app[bot]: Check out this pull request on&nbsp; <a href="https://app.reviewnb.com/xgi-org/xgi/pull/481"><img align="absmiddle"  alt="ReviewNB" height="28" class="BotMessageButtonImage" src="https://raw.githubusercontent.com/ReviewNB/support/master/images/button_reviewnb.png"/></a> 

 See visual diffs & provide feedback on Jupyter Notebooks. 

---

 <i>Powered by <a href='https://www.reviewnb.com/?utm_source=gh'>ReviewNB</a></i>
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/xgi-org/xgi/pull/481?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xgi-org) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`536f592`)](https://app.codecov.io/gh/xgi-org/xgi/commit/536f5920149d49f5bda9ff4d1c3191451398fccd?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xgi-org) 92.03% compared to head [(`6bc4c4b`)](https://app.codecov.io/gh/xgi-org/xgi/pull/481?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xgi-org) 92.05%.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main     #481      +/-   ##
==========================================
+ Coverage   92.03%   92.05%   +0.02%     
==========================================
  Files          60       60              
  Lines        4392     4392              
==========================================
+ Hits         4042     4043       +1     
+ Misses        350      349       -1     
```


| [Files](https://app.codecov.io/gh/xgi-org/xgi/pull/481?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xgi-org) | Coverage Δ | |
|---|---|---|
| [xgi/core/hypergraph.py](https://app.codecov.io/gh/xgi-org/xgi/pull/481?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xgi-org#diff-eGdpL2NvcmUvaHlwZXJncmFwaC5weQ==) | `93.54% <100.00%> (ø)` | |

... and [1 file with indirect coverage changes](https://app.codecov.io/gh/xgi-org/xgi/pull/481/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xgi-org)


</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/xgi-org/xgi/pull/481?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xgi-org).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xgi-org).


Patch:
diff --git a/docs/source/api/recipes/recipes.ipynb b/docs/source/api/recipes/recipes.ipynb
index c6cdebb..07c3ed5 100644
--- a/docs/source/api/recipes/recipes.ipynb
+++ b/docs/source/api/recipes/recipes.ipynb
@@ -631,7 +631,7 @@
     }
    ],
    "source": [
-    "edge_color = [colors[i-2] for i in H.edges.filterby(\"order\", 1, \"gt\").size.aslist()]\n",
+    "edge_color = [colors[i - 2] for i in H.edges.filterby(\"order\", 1, \"gt\").size.aslist()]\n",
     "\n",
     "xgi.draw(H, pos=pos, dyad_color=link_color, edge_fc=edge_color);"
    ]
@@ -661,7 +661,7 @@
     }
    ],
    "source": [
-    "color_dict = {idx : colors[i-2] for idx, i in H.edges.size.asdict().items()}\n",
+    "color_dict = {idx: colors[i - 2] for idx, i in H.edges.size.asdict().items()}\n",
     "\n",
     "xgi.draw(H, pos=pos, dyad_color=color_dict, edge_fc=color_dict);"
    ]
@@ -692,9 +692,12 @@
    ],
    "source": [
     "from matplotlib.colors import ListedColormap\n",
+    "\n",
     "cmap = ListedColormap(colors[1:])\n",
     "\n",
-    "_, (node_collection, dyad_collection, edge_collection) = xgi.draw(H, pos=pos, dyad_color=link_color, edge_fc_cmap=cmap)\n",
+    "_, (node_collection, dyad_collection, edge_collection) = xgi.draw(\n",
+    "    H, pos=pos, dyad_color=link_color, edge_fc_cmap=cmap\n",
+    ")\n",
     "\n",
     "plt.colorbar(edge_collection, label=\"edges\")\n",
     "\n",
diff --git a/docs/source/api/tutorials/In Depth 2 - Drawing hyperedges.ipynb b/docs/source/api/tutorials/In Depth 2 - Drawing hyperedges.ipynb
index 1f1ffa5..c2d1439 100644
--- a/docs/source/api/tutorials/In Depth 2 - Drawing hyperedges.ipynb
+++ b/docs/source/api/tutorials/In Depth 2 - Drawing hyperedges.ipynb
@@ -447,10 +447,8 @@
    ],
    "source": [
     "ax, (dyad_collection, edge_collection) = xgi.draw_hyperedges(\n",
-    "    H,\n",
-    "    pos=pos,\n",
-    "    dyad_color=[3, 1, 4],\n",
-    "    edge_fc=H.edges.size)\n",
+    "    H, pos=pos, dyad_color=[3, 1, 4], edge_fc=H.edges.size\n",
+    ")\n",
     "\n",
     "ax, node_collection = xgi.draw_nodes(H, pos=pos, node_fc=H.nodes.degree, zorder=3)\n",
     "\n",
@@ -458,9 +456,7 @@
     "plt.colorbar(dyad_collection, label=\"dyads\")\n",
     "plt.colorbar(edge_collection, label=\"edges\")\n",
     "\n",
-    "plt.tight_layout()\n",
-    "\n",
-    "    "
+    "plt.tight_layout()"
    ]
   }
  ],
diff --git a/xgi/core/hypergraph.py b/xgi/core/hypergraph.py
index 3d1539b..d43ed5a 100644
--- a/xgi/core/hypergraph.py
+++ b/xgi/core/hypergraph.py
@@ -862,7 +862,7 @@ class Hypergraph:
             try:
                 for e, value in values.items():
                     try:
-                        self._edge_attr[id][name] = value
+                        self._edge_attr[e][name] = value
                     except IDNotFound:
                         warn(f"Edge {e} does not exist!")
             except AttributeError:


Test patch:
diff --git a/tests/core/test_hypergraph.py b/tests/core/test_hypergraph.py
index dcc7f17..74fbe74 100644
--- a/tests/core/test_hypergraph.py
+++ b/tests/core/test_hypergraph.py
@@ -742,6 +742,18 @@ def test_set_edge_attributes(edgelist1):
         H3.set_edge_attributes({"test": {2: "weight"}})
 
 
+def test_480(edgelist1):
+    H1 = xgi.Hypergraph(edgelist1)
+    attr_dict1 = {
+        0: 1,
+        1: 2,
+        2: 3,
+        3: -1,
+    }
+    H1.set_edge_attributes(attr_dict1, "weight")
+    assert H1.edges.attrs("weight").asdict() == attr_dict1
+
+
 def test_cleanup():
     H = xgi.Hypergraph()
     H.add_edges_from([["a", "b", "c"], ["a", "b", "c"], ["e", "f"]])