Skip to content

Commit

Permalink
DOC: Add docstrings to Filter mapping views (#7075)
Browse files Browse the repository at this point in the history
* Update coreviews.py

* Update coreviews.py

* Update coreviews.py

* Update coreviews.py

* Update coreviews.py

* Update coreviews.py

* Update coreviews.py

* Rm summary lines from see-alsos.

---------

Co-authored-by: Ross Barnowski <rossbar@caltech.edu>
  • Loading branch information
akshayamadhuri and rossbar committed Nov 6, 2023
1 parent eb6c4c4 commit 9aa44be
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions networkx/classes/coreviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,18 @@ def __getitem__(self, node):


class FilterAtlas(Mapping): # nodedict, nbrdict, keydict
"""A read-only Mapping of Mappings with filtering criteria for nodes.
It is a view into a dict-of-dict data structure, and it selects only
nodes that meet the criteria defined by ``NODE_OK``.
See Also
========
FilterAdjacency
FilterMultiInner
FilterMultiAdjacency
"""

def __init__(self, d, NODE_OK):
self._atlas = d
self.NODE_OK = NODE_OK
Expand Down Expand Up @@ -293,6 +305,19 @@ def __repr__(self):


class FilterAdjacency(Mapping): # edgedict
"""A read-only Mapping of Mappings with filtering criteria for nodes and edges.
It is a view into a dict-of-dict-of-dict data structure, and it selects nodes
and edges that satisfy specific criteria defined by ``NODE_OK`` and ``EDGE_OK``,
respectively.
See Also
========
FilterAtlas
FilterMultiInner
FilterMultiAdjacency
"""

def __init__(self, d, NODE_OK, EDGE_OK):
self._atlas = d
self.NODE_OK = NODE_OK
Expand Down Expand Up @@ -328,6 +353,18 @@ def __repr__(self):


class FilterMultiInner(FilterAdjacency): # muliedge_seconddict
"""A read-only Mapping of Mappings with filtering criteria for nodes and edges.
It is a view into a dict-of-dict-of-dict-of-dict data structure, and it selects nodes
and edges that meet specific criteria defined by ``NODE_OK`` and ``EDGE_OK``.
See Also
========
FilterAtlas
FilterAdjacency
FilterMultiAdjacency
"""

def __iter__(self):
try: # check that NODE_OK has attr 'nodes'
node_ok_shorter = 2 * len(self.NODE_OK.nodes) < len(self._atlas)
Expand Down Expand Up @@ -357,6 +394,20 @@ def new_node_ok(key):


class FilterMultiAdjacency(FilterAdjacency): # multiedgedict
"""A read-only Mapping of Mappings with filtering criteria
for nodes and edges.
It is a view into a dict-of-dict-of-dict-of-dict data structure,
and it selects nodes and edges that satisfy specific criteria
defined by ``NODE_OK`` and ``EDGE_OK``, respectively.
See Also
========
FilterAtlas
FilterAdjacency
FilterMultiInner
"""

def __getitem__(self, node):
if node in self._atlas and self.NODE_OK(node):

Expand Down

0 comments on commit 9aa44be

Please sign in to comment.