ampl / amplpy

Python API for AMPL
https://amplpy.ampl.com
BSD 3-Clause "New" or "Revised" License
66 stars 19 forks source link

Skip param assignment when values is an empty dict #29

Closed ytakashina closed 4 years ago

ytakashina commented 4 years ago

With the current implementation of Parameter.setValues(), you will get an exception when you set empty values to a parameter (e.g., when you unit-test your model on some simple data).

        if isinstance(values, dict):
>           indices, values = list(zip(*values.items()))
E           ValueError: not enough values to unpack (expected 2, got 0)

This patch help avoid the exception by skipping assignment when the given values are empty.

fdabrandao commented 4 years ago

Thanks! This corner case had not gone unnoticed.