vinci1it2000 / formulas

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

Regarding the import of the model with from_dict after to_dict, the default value defined by the override is not the same as the normal result #134

Closed toca-Y closed 3 months ago

toca-Y commented 3 months ago

Is your feature request related to a problem? Please describe. When converting to_dict to from_dict, the mapped cell value does not change when the defined name overrides the default value

Additional context

import formulas

# it's formulas/test/test_files/excel.xlsx
fpath, dir_output = '../excel.xlsx', 'output'  # doctest: +SKIP
xl_model = formulas.ExcelModel().loads(fpath).finish()
xl_model2 = formulas.ExcelModel().from_dict(xl_model.to_dict())

# INPUT_A=A2, INPUT_B=A3 (They are defining names in the excel file.)
input_ = {
    "'[excel.xlsx]'!INPUT_A": 7,  # To overwrite the default value. default is 2
    "'[excel.xlsx]'!INPUT_B": 3,  # To overwrite the default value. default is 6
}

# B3=A2+A3
output = [
    "'[excel.xlsx]DATA'!B2", "'[excel.xlsx]DATA'!C2", "'[excel.xlsx]DATA'!C4"
]

res1 = xl_model.calculate(inputs=input_, outputs=output)
res2 = xl_model2.calculate(inputs=input_, outputs=output)

print("xl_model B2:",
      res1.get("'[excel.xlsx]DATA'!B2").value[0, 0])  # xl_model B2: 10.0

print("xl_model2 B2:",
      res2.get("'[excel.xlsx]DATA'!B2").value[0, 0])  # xl_model2 B2: 8.0

If this result is the same, it's perfect, thanks (I'm sorry if my description is incorrect)

vinci1it2000 commented 3 months ago

Thank you for your discovery! I've addressed the bug and it will be incorporated into the upcoming release. In the meantime, to resolve your issue, you can install my development version.

toca-Y commented 3 months ago

Thank you for your discovery! I've addressed the bug and it will be incorporated into the upcoming release. In the meantime, to resolve your issue, you can install my development version.

Thank you!I have got the development version right and the test is available. but i have other issue. I'll sort it out for you later