pycel
pycel copied to clipboard
Formula Parsing Error
What actually happened
[Please include the full traceback if there was an exception]
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.11/site-packages/pycel/excelformula.py", line 923, in eval_func
excel_formula.compiled_lambda())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/pycel/excelformula.py", line 948, in
What was expected to happen
If I cast x to string before calling lower, I get the right output
Problem description
[If needed, this should explain why the current behavior is a problem and why the expected output is a better solution]
Evaluation is failing when it shouldn't be
Code Sample
# Your code here
workbook = openpyxl.load_workbook(tmp_xlsx)
workbook_compiler = ExcelCompiler(excel=workbook)
workbook_compiler.evaluate(get_cell_coordinate(cell, sheet_name))
[If possible, include a minimal, complete, and verifiable example to help us identify the issue. This also helps check that the issue is not with your own code]
Environment
[Pycel Version, Python Version and OS used. Also any other environment details that you think might be relevant]
Python 3.11 Pycel 1.0b30
I monkey patched build_wildcard_re
in my code which solved my issues, but really didn't get too deep into the weeds here because I just need my thing to work
# ========= Start Monkey Patch =========
QUESTION_MARK_RE = re.compile(r'\?(?<!~)')
STAR_RE = re.compile(r'\*(?<!~)')
def build_wildcard_re_fixed(lookup_value):
regex = QUESTION_MARK_RE.sub('.', STAR_RE.sub('.*', lookup_value))
if regex != lookup_value:
# this will be a regex match"""
compiled = re.compile(f'^{regex.lower()}$')
return lambda x: x is not None and compiled.match(str(x).lower()) is not None
else:
return None
excelutil.build_wildcard_re = build_wildcard_re_fixed
# ========= End Monkey Patch =========