Skip to content

DiGraph in_edges returns wrong view when using nbunch #4745

@th1j5

Description

@th1j5

Current Behavior

g.in_edges(nbunch=<node(s)>) returns an InEdgeDataView if nbunch is supplied aka is not None.
Else (nbunch is None), it returns an InEdgeView.

Expected Behavior

g.in_edges(nbunch=<node(s)>) returns an InEdgeView.
This would be more consistent and would enable the chaining of .data() call in all cases.
(It should be noted that this is duplicate behaviour compared by using the parameter data=True)
Moreover, the returned InEdgeDataView doesn't contain any data if not asked (with data=True)

Steps to Reproduce

>>> g = nx.DiGraph()
>>> g.add_edge(1,2,color='blue')
>>> g.in_edges() # == g.in_edges(nbunch=None)
InEdgeView([(1, 2)])
>>> g.in_edges(2) # == g.in_edges(nbunch=2)
InEdgeDataView([(1, 2)])

more observations

>>> g.in_edges().data()
InEdgeDataView([(1, 2, {'color': 'blue'})])
>>> g.in_edges(2)
InEdgeDataView([(1, 2)])
>>> g.in_edges(2, data=True)
InEdgeDataView([(1, 2, {'color': 'blue'})])

Environment

Python version: 3.8.5
NetworkX version: 2.5
Tested in IPython

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions