spine-tools / Spine-Database-API

Database interface to Spine generic data model
https://www.tools-for-energy-system-modelling.org/
GNU Lesser General Public License v3.0
6 stars 5 forks source link

Handle booleans case insensitively #236

Closed suvayu closed 1 year ago

suvayu commented 1 year ago

Currently only 'true' & 'false' (case sensitive) are accepted as valid booleans (as per the JSON spec). This PR adds a preprocessing step that case insensitively checks if the string/bytes value matches a boolean, if it does, it down cases the value before parsing it to a Python object.

This should be merged after #235, new commits only touch parameter_value.py & tests/test_parameter_value.py

Checklist before merging

soininen commented 1 year ago

from_database() should really care about converting values from their database representation, not user input. We cannot use this function to deal with user input; we may even switch the database representation to something else than JSON in the future breaking the functionality introduced here.

We should rather deal with user input in Toolbox side, converting "true" and "false" case insensitively to Python's True and False in Database editor. Note, that string like yes and no should NOT be converted as there are Tools that require them to remain as-is.

soininen commented 1 year ago

Forgot to mention that we have an issue for this, spine-tools/Spine-Toolbox#2055

suvayu commented 1 year ago

Okay, I'll close this PR then. Maybe tomorrow during the meeting you can point me to the user input code, and I can estimate the effort required for this.