1

I have a dataframe df with:

Source, Target
aaaa, bbbb
aaaa, cccc
aaaa, dddd
bbbb, cccc
cccc, dddd

and so on.

File "total_edges.csv" (71kb): https://uni-duisburg-essen.sciebo.de/s/WLDD4ytkjekVcIL

I get a graph object and, according to the github issue tracker (https://github.com/igraph/python-igraph/issues/253) the triad nodes/edges but it fails:

import pandas as pd
import igraph as ig

df_edges = pd.read_csv("total_edges.csv")

g = ig.Graph.TupleList(df_edges.itertuples(index=False), directed=True)
tc = g.triad_census()
ffl = ig.Graph.Formula("A --> B --> C, A --> C")
result = g.get_subisomorphisms_lad(ffl, induced=True)
print(result)

Error message (VM with updated Pop_OS x64, Python 3.7.5):

Traceback (most recent call last):
  File "count_triads.py", line 20, in <module>
    ffl = ig.Graph.Formula("A --> B --> C, A --> C")
  File "/home/admin/.local/lib/python3.7/site-packages/igraph/formula.py", line 209, in construct_graph_from_formula
    for start_names, end_names, arrowheads in generate_edges(part):
  File "/home/admin/.local/lib/python3.7/site-packages/igraph/formula.py", line 90, in generate_edges
    raise SyntaxError(msg)
SyntaxError: invalid token found in edge specification: A --> B --> C

How can I mark all nodes in that graph with the triad value (A, B, C, None) for triad type 030T so that I can filter/plot triads and non-triads differently?

Szabolcs
  • 24,728
  • 9
  • 85
  • 174
Vega
  • 2,661
  • 5
  • 24
  • 49

1 Answers1

3

About the error, it looks like you're hit by an issue similar to this issue in the formula parser.

Trying to apply the recent changes or installing the development version of python-igraph may help here.

Davide Fiocco
  • 5,350
  • 5
  • 35
  • 72
  • That's the solution. "sudo pip3 install -U git+https://github.com/igraph/python-igraph.git" on a Linux machine (real or VM) gives the latest python-igraph dev version with all bugfixes. – Vega Oct 24 '19 at 13:45
  • The result in the form of [ [23, 32, 33], [23, 33, 34], [24, 33, 190], [24, 33, 86]] stands for A, B ,C in triad 030T. The numbers map to the igraph node/vertex ids which one gets via "for idx, node in enumerate(g.vs): print(str(idx) + "," + node["name"])". Then mapping the triad ids to the node ids to get a list with all nodes that are part of a triad. – Vega Oct 28 '19 at 14:45
  • After updating my igraph version on Windows it works there as well, seems the bugfix went upstream so no need for a Linux VM anymore. – Vega Jan 18 '20 at 22:13