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

Formula parsing error #158

Open
jt269 opened this issue Jun 14, 2023 · 0 comments
Open

Formula parsing error #158

jt269 opened this issue Jun 14, 2023 · 0 comments

Comments

@jt269
Copy link

jt269 commented Jun 14, 2023

I have a spreadsheet with lots of range calculations (Sumif).

This is an example Excel formula:

=IF($Q13=0,0,IF(OR($D13>X$7,X$11<IF($D13=$X$3,$AI$2,$U12)),0,MAX(0,MIN($T13,$Q13-SUM($W13:W13),$S13-IF($D13>=$X$3,SUMIF($D$12:$D12,">="&$X$3,X$12:X12),SUMIF($D$12:$D12,"<"&$X$3,X$12:X12))))))

When Pycel tries to parse the function I get this error:

TypeError: unsupported operand type(s) for +: 'int' and 'str'

Traceback error:

Traceback (most recent call last):
  File "C:\Users\jtown\AppData\Local\Programs\Python\Python311\Lib\site-packages\pycel\excelformula.py", line 923, in eval_func
    excel_formula.compiled_lambda())
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\jtown\AppData\Local\Programs\Python\Python311\Lib\site-packages\pycel\excelformula.py", line 948, in <lambda>
    ### Traceback will show this line if not loaded from a text file
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\jtown\AppData\Local\Programs\Python\Python311\Lib\site-packages\pycel\excelcompiler.py", line 782, in _evaluate_range
    data = tuple(
           ^^^^^^
  File "C:\Users\jtown\AppData\Local\Programs\Python\Python311\Lib\site-packages\pycel\excelcompiler.py", line 783, in <genexpr>
    tuple(self._evaluate(addr.address) for addr in row)
  File "C:\Users\jtown\AppData\Local\Programs\Python\Python311\Lib\site-packages\pycel\excelcompiler.py", line 783, in <genexpr>
    tuple(self._evaluate(addr.address) for addr in row)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\jtown\AppData\Local\Programs\Python\Python311\Lib\site-packages\pycel\excelcompiler.py", line 809, in _evaluate
    value = self.eval(cell)
            ^^^^^^^^^^^^^^^
  File "C:\Users\jtown\AppData\Local\Programs\Python\Python311\Lib\site-packages\pycel\excelcompiler.py", line 172, in _eval
    return eval_ctx(
           ^^^^^^^^^
  File "C:\Users\jtown\AppData\Local\Programs\Python\Python311\Lib\site-packages\pycel\excelformula.py", line 934, in eval_func
    error_logger('error', f"{address}{excel_formula.python_code}",
  File "C:\Users\jtown\AppData\Local\Programs\Python\Python311\Lib\site-packages\pycel\excelformula.py", line 877, in error_logger
    raise exc(error_msg)
pycel.excelformula.FormulaEvalError: Traceback (most recent call last):
  File "C:\Users\jtown\AppData\Local\Programs\Python\Python311\Lib\site-packages\pycel\excelformula.py", line 923, in eval_func
    excel_formula.compiled_lambda())
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\jtown\AppData\Local\Programs\Python\Python311\Lib\site-packages\pycel\excelformula.py", line 948, in <lambda>
    ### Traceback will show this line if not loaded from a text file

  File "C:\Users\jtown\AppData\Local\Programs\Python\Python311\Lib\site-packages\pycel\excellib.py", line 333, in sumif
    return sumifs(sum_range, rng, criteria)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\jtown\AppData\Local\Programs\Python\Python311\Lib\site-packages\pycel\excellib.py", line 348, in sumifs
    return sum(_numerics(
           ^^^^^^^^^^^^^^
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Eval: BS4 Schedule!X14: if_(_C_("BS4 Schedule!Q14") == 0, 0, if_(or_(_C_("BS4 Schedule!D14") > _C_("BS4 Schedule!X7"), _C_("BS4 Schedule!X11") < if_(_C_("BS4 Schedule!D14") == _C_("BS4 Schedule!X3"), _C_("BS4 Schedule!AI2"), _C_("BS4 Schedule!U13"))), 0, max_(0, min_(_C_("BS4 Schedule!T14"), _C_("BS4 Schedule!Q14") - sum_(_C_("BS4 Schedule!W14")), _C_("BS4 Schedule!S14") - if_(_C_("BS4 Schedule!D14") >= _C_("BS4 Schedule!X3"), sumif(_R_("BS4 Schedule!D12:D13"), ">=" & _C_("BS4 Schedule!X3"), _R_("BS4 Schedule!X12:X13")), sumif(_R_("BS4 Schedule!D12:D13"), "<" & _C_("BS4 Schedule!X3"), _R_("BS4 Schedule!X12:X13")))))))
Eval: BS4 Schedule!X9: sum_(_R_("BS4 Schedule!X13:X47"))
Eval: BS4 Schedule!X249: _C_("BS4 Schedule!X9")
Eval: BS4 Schedule!W250: sumproduct(_R_("BS4 Schedule!X249:EB249"), _R_("BS4 Schedule!X250:EB250"))
Eval: Sheet1!D1: _C_("BS4 Schedule!W250")

Environment

Pycel Version most recent from PyPi, Python Version 3.11 and Windows 10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant