vinci1it2000 / formulas

Excel formulas interpreter in Python.
https://formulas.readthedocs.io/
European Union Public License 1.1
358 stars 75 forks source link

TypeError: got multiple values for argument #112

Closed skoudoro closed 1 year ago

skoudoro commented 1 year ago

Hi @vinci1it2000,

Thank you for this nice package.

I encounter the error on the title when I do the following:

import formulas
from functools import partial

func = formulas.Parser().ast('=(1 + 1) + B3 / A2')[1].compile()

func2 = partial(func, A2=1)

# This generate the error: TypeError: got multiple values for argument
func2(3)

File /opt/homebrew/Caskroom/miniforge/base/envs/appscript-39-x86/lib/python3.9/site-packages/schedula/utils/dsp.py:1516, in SubDispatchPipe.__call__(self, _stopper, _executor, _sol_name, _verbose, *args, **kw)
   1514 self.solution, key_map = self._init_new_solution(_sol_name, _verbose)
   1515 pipe_append = self._pipe_append()
-> 1516 self._init_workflows(self._parse_inputs(*args, **kw))
   1518 for x, nxt_nds, nxt_dsp in self.pipe:
   1519     v, s = x[-1]

File /opt/homebrew/Caskroom/miniforge/base/envs/appscript-39-x86/lib/python3.9/site-packages/schedula/utils/dsp.py:1295, in SubDispatchFunction._parse_inputs(self, *args, **kw)
   1293         else:
   1294             msg = 'missing a required argument: %r'
-> 1295             raise TypeError(msg % k) from None
   1296 if len(inputs) < len(args):
   1297     raise TypeError('too many positional arguments') from None

However, if I do

func2(B3=3)

it works.

it is problematic when you want to use this function in a scipy optimizer like optimize.newton since I can not pass the keyword (B3=0) for x0 (see the function in the link).

I tried with longer equation and the problem appear always with the first cell (here A2). it is ok with all the other cell.

How can we fix this issue? Thank you for the feedback.

Have a nice winter break

skoudoro commented 1 year ago

Closing, it seems the problem is due to partial and not the formula library. I need to find a way to reorder the arguments.