vallettea / koala

Transpose your Excel calculations into python for better performances and scaling.
GNU General Public License v3.0
146 stars 59 forks source link

networkx 2.4 breaks koala #240

Open brianmay opened 5 years ago

brianmay commented 5 years ago

After updating to networkx 2.4, I noticed koala2 0.0.30 is broken:

[...]
  File "/home/brian/.virtualenvs/energy_rating/lib/python3.6/site-packages/koala/ExcelCompiler.py", line 92, in gen_graph
    cellmap, G = graph_from_seeds(seeds, self)
  File "/home/brian/.virtualenvs/energy_rating/lib/python3.6/site-packages/koala/ast/__init__.py", line 473, in graph_from_seeds
    pystr, ast = cell2code(c1, names)
  File "/home/brian/.virtualenvs/energy_rating/lib/python3.6/site-packages/koala/ast/__init__.py", line 374, in cell2code
    code = root.emit(ast, context=sheet)
  File "/home/brian/.virtualenvs/energy_rating/lib/python3.6/site-packages/koala/ast/astnodes.py", line 303, in emit
    args = self.children(ast)
  File "/home/brian/.virtualenvs/energy_rating/lib/python3.6/site-packages/koala/ast/astnodes.py", line 45, in children
    args = sorted(args,key=lambda x: ast.node[x]['pos'])
  File "/home/brian/.virtualenvs/energy_rating/lib/python3.6/site-packages/koala/ast/astnodes.py", line 45, in <lambda>
    args = sorted(args,key=lambda x: ast.node[x]['pos'])
AttributeError: 'DiGraph' object has no attribute 'node'

If this is fixed in a later version, of koala, then do worry about it, just close. However I suspect it may not be.

SlavaKozlov commented 4 years ago

I got the same error in these versions:

koala2=0.0.36 networkx=2.5.

The local fix I put in is to upgrade to the networkx 2.1 interface (made obsolete in networkx 2.4) -- that is, change the node to nodes.

That is, on line 45 of ast/astnodes.py

args = sorted(args,key=lambda x: ast.node[x]['pos'])

to

args = sorted(args,key=lambda x: ast.nodes[x]['pos'])

brianmay commented 4 years ago

A pull request to fix this would be good :-)

If possible, a change that allows koala to continue working with networkx 2.4 preferred, as it means projects don't have to upgrade both packages at the same time.

kmonson commented 4 years ago

I'm working on a pull request for this and the old openpyxl version issue.