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

Unexisting functions are not detected if their parameters contain a variable #19

Closed
albertca opened this issue Oct 10, 2018 · 2 comments
Assignees
Labels

Comments

@albertca
Copy link

Describe the bug
The following formula:

func = formulas.Parser().ast('=MYFUNC(1)')[1].compile()

raises DispatcherError: ("Failed DISPATCHING '%s' due to:\n %r", 'MYFUNC', FunctionError('Function not implemented!',))

but:

func = formulas.Parser().ast('=MYFUNC(a)')[1].compile()

does not. It looks like the parser should always be able to detect that the function "MYFUNC" does not exist.

This is using version 0.1.3

@vinci1it2000 vinci1it2000 self-assigned this Oct 15, 2018
@vinci1it2000
Copy link
Owner

compile method

The compile method is trying to pre-calculate all intermediate results of the formula. I'll show you an example:

  >>> import formulas
  >>> builder = formulas.Parser().ast('=MYFUNC((1+2)+a)')[1]
  >>> builder.dsp.plot()

the Parser has generated a Builder with the following Dispatcher:

image

When compile the function, the Builder has generated a new Dispatcher with all pre-calculated outputs (see (1+2)).

 >>> func = builder.compile()
 >>> func.plot()

image

In this case the builder couldn't execute the MYFUNC, because it has has a variable as input. But if you execute the compiled function you will get the same error:

  >>> func(1)
  Traceback (most recent call last):
  ...
  schedula.utils.exc.DispatcherError: ("Failed DISPATCHING '%s' due to:\n  %r", 'MYFUNC', FunctionError('Function not implemented!',))

Error description

In the first case your function has not any variable, so the compile method executes the function MYFUNC raising the error.

While, in the second case, since the function has a variable as input, the compile method cannot execute the function. In any case, you will receive the same error in the first execution of the compiled function.

Detect not implemented functions

If you want to detect not implemented functions, you can do the following:

 >>> [k for k, v in builder.dsp.function_nodes.items() if v['function'] is formulas.functions.not_implemented]
['MYFUNC']

@albertca
Copy link
Author

Thanks a lot for the explanation.

It was very helpful!

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