Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When there is no argument for a function, Koala exits. #232

Open
eiso opened this issue Aug 20, 2019 · 3 comments
Open

When there is no argument for a function, Koala exits. #232

eiso opened this issue Aug 20, 2019 · 3 comments
Labels

Comments

@eiso
Copy link
Contributor

eiso commented Aug 20, 2019

I ran into the issue that if a function is not passed an argument, koala is unable to accept it. Please find a reproducible case below with the function TODAY() which exists in excellib.py.

Modify example/basic.py (line 24):

from __future__ import print_function

from koala.ExcelCompiler import ExcelCompiler
from koala.Spreadsheet import Spreadsheet

filename = "./examples/basic.xlsx"

print(filename)

### Graph Generation ###
c = ExcelCompiler(filename)
sp = c.gen_graph()

## Graph Serialization ###
print("Serializing to disk...")
sp.dump(filename.replace("xlsx", "gzip"))

### Graph Loading ###
print("Reading from disk...")
sp = Spreadsheet.load(filename.replace("xlsx", "gzip"))

### Graph Evaluation ###
#sp.set_value('Sheet1!A1', 10)
sp.cell_set_formula('Sheet1!A1', formula='=TODAY()')

print('New D1 value: %s' % str(sp.evaluate('Sheet1!D1')))

Output:

$ python3 examples/basic.py
./examples/basic.xlsx
Serializing to disk...
Reading from disk...
Graph loading done, 120 nodes, 111 edges, 120 cellmap entries
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/networkx/classes/digraph.py", line 837, in predecessors
    return iter(self._pred[n])
KeyError: <koala.ast.astnodes.FunctionNode object at 0x121edddd0>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "examples/basic.py", line 24, in <module>
    sp.cell_set_formula('Sheet1!A1', formula='=TODAY()')
  File "/Users/x/koala/koala/Spreadsheet.py", line 318, in cell_set_formula
    cellmap, G = graph_from_seeds(seeds, self)
  File "/Users/x/koala/koala/ast/__init__.py", line 473, in graph_from_seeds
    pystr, ast = cell2code(c1, names)
  File "/Users/x/koala/koala/ast/__init__.py", line 374, in cell2code
    code = root.emit(ast, context=sheet)
  File "/Users/x/koala/koala/ast/astnodes.py", line 301, in emit
    args = self.children(ast)
  File "/Users/x/koala/koala/ast/astnodes.py", line 44, in children
    args = ast.predecessors(self)
  File "/usr/local/lib/python3.7/site-packages/networkx/classes/digraph.py", line 839, in predecessors
    raise NetworkXError("The node %s is not in the digraph." % (n,))
networkx.exception.NetworkXError: The node TODAY is not in the digraph.

This can be bypassed by adding the following try/except on line 300 in ast/astnodes.py:

try:
    args = self.children(ast)
except:
    args = ''
@danielsjf
Copy link
Collaborator

@eiso, thanks a lot for reporting this. I think it is the same problem as #149. Your solution seems quite elegant and feel free to submit it as a PR. If all the other tests pass, this seems like a nice fix.

@danielsjf
Copy link
Collaborator

danielsjf commented Aug 21, 2019

I've seen that the PI functions solves it via astnodes.py:

elif fun == "pi":

Maybe we should remove this code once you update the code. I like your generic approach better.

@danielsjf
Copy link
Collaborator

I would still like to add a test for this so I'll keep it open for the time being. I'm waiting for #231 to be merged. However, the functionality should work now.

@danielsjf danielsjf added the Bug label Sep 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants