SDXorg / pysd

System Dynamics Modeling in Python
http://pysd.readthedocs.org/
MIT License
349 stars 89 forks source link

Issue when parsing initial values passed through the CLI #395

Closed rogersamso closed 1 year ago

rogersamso commented 1 year ago

When passing initial values on the command line (e.g. "Stock:1.1"), the full argument is parsed with the split_vars function, in the parser.py module.

However, the code in split_vars function looks like this:

        if '=' in string:
            # new variable value
            var, value = string.split('=')
            type = 'param'

        if ':' in string:
            # initial time value
            var, value = string.split(':')
            type = 'initial'

        if value.strip().isnumeric():
            # value is float
            return {var.strip(): (type, float(value))}

The problem is that the isnumeric() method only returns True if it's a positive integer. For floats or negative values, it will return False.

I will add a fix for this in the new PR. This Issue is just to keep track of things that were fixed.

enekomartinmartinez commented 1 year ago

Thanks for reporting and working on that!