Edge select using _incident on directed graphs

Hi!

I’m using python-igraph to perform graph subsetting/projection on directed graphs, and I was using .select on EdgeSeq to pull out edges of interest.

I found that when using the _incident as the condition, it seems to return equivalent statements to _source_in, which doesn’t seem consistent with my understanding of incidence.

Is this expected, or is this a bug?
And in either case, how should I work around this (I’m assuming using .incidence on each vertex of interest?)

Basic example:

import igraph as ig

edgelist = [
  (0, 1),
  (1, 2),
  (2, 3),
]

G = ig.Graph(edgelist, directed=True)

subset_edges = G.es.select(_incident_eq=(1,))

print(len(subset_edges))
print([(edge.source, edge.target) for edge in subset_edges])

Expected Output:

2
[(0, 1), (1, 2)]

Actual Output:

1
[(1, 2)]

Thank you in advance.

EDIT:

This is on iGraph 0.10.5

Thanks for the report and sorry for the late reply; I was on holiday for most of last week.

This is a bug and I’m working on a fix; I’ll let you know when it lands in the code repository.

This is now fixed in the dev version. It is a one-line fix in src/igraph/seq.py (see the linked commit) so you can either apply this yourself to your copy, or use a workaround like this:

from typing import Iterable

def filter_by_incidence(G: Graph, vs: Iterable[int]):
  candidates = set()
  for v in vs:
      candidates.update(G.incident(v, mode="all"))
  return G.es[sorted(candidates)]