From 76e3e924e226ae5e21fcbfa310f67a14597d0df3 Mon Sep 17 00:00:00 2001 From: Leo Torres Date: Thu, 28 May 2026 08:40:12 +0200 Subject: [PATCH 1/2] docs: clarify that H.edges[idx] returns attributes, not members A common confusion is that H.edges[0] returns the empty attribute dict rather than the members of edge 0. The behavior is correct but the docstring did not point users at the actual member-access methods. Add an upfront note and concrete examples showing both attribute access and the alternatives (.members, .memberships). Co-Authored-By: Claude Opus 4.7 --- xgi/core/views.py | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/xgi/core/views.py b/xgi/core/views.py index 268edba2..ec0ad7fb 100644 --- a/xgi/core/views.py +++ b/xgi/core/views.py @@ -143,23 +143,43 @@ def __iter__(self): return iter(self._ids) def __getitem__(self, idx): - """Get the attributes of the ID. + """Get the attribute dictionary of the node or edge with the given ID. + + Note that this returns the **attributes** (a dict of metadata), not the + members of an edge or the edges containing a node. If no attributes have + been set, the returned dict is empty. Parameters ---------- idx : hashable - node or edge ID + Node or edge ID. Returns ------- dict - attributes associated to the ID. + Attributes associated with `idx`. Empty if none have been set. Raises ------ - XGIError - If the id is not being kept track of by this view, or if id is not in the - hypergraph, or if id is not hashable. + IDNotFound + If `idx` is not in this view. + + See Also + -------- + :meth:`EdgeView.members` : Get the nodes that make up an edge. + :meth:`NodeView.memberships` : Get the edges containing a node. + + Examples + -------- + >>> import xgi + >>> H = xgi.Hypergraph([[1, 2, 3], [3, 4]]) + >>> H.edges[0] # attribute dict (empty by default) + {} + >>> H.edges.members(0) # the actual members of edge 0 + {1, 2, 3} + >>> H.add_edge([5, 6], idx="e1", color="red") + >>> H.edges["e1"] # attributes set at creation + {'color': 'red'} """ if idx not in self: From 2c92ffb349fd7207322d3bd671295d871b32d87b Mon Sep 17 00:00:00 2001 From: Leo Torres Date: Thu, 28 May 2026 08:58:19 +0200 Subject: [PATCH 2/2] docs: also flag attr-vs-member confusion in NodeView/EdgeView class docs H.nodes? and H.edges? are common discovery moves; surface the attr-vs-member distinction in the class docstrings where users will actually encounter it (per Max's review on #727). Co-Authored-By: Claude Opus 4.7 --- xgi/core/views.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xgi/core/views.py b/xgi/core/views.py index ec0ad7fb..ff8d6ebe 100644 --- a/xgi/core/views.py +++ b/xgi/core/views.py @@ -596,6 +596,9 @@ class NodeView(IDView): `tutorial `_. + Indexing with ``H.nodes[id]`` returns the node's **attribute dictionary**, + not the edges it belongs to. Use :meth:`memberships` for the latter. + """ _id_kind = "node" @@ -708,6 +711,9 @@ class EdgeView(IDView): `tutorial `_. + Indexing with ``H.edges[id]`` returns the edge's **attribute dictionary**, + not its members. Use :meth:`members` for the latter. + """ _id_kind = "edge"