entropy-lab / entropy

BSD 3-Clause "New" or "Revised" License
30 stars 13 forks source link

Fix: ParamStore save_temp() would throw when called twice (with numpy ndarray values) #336

Closed urig closed 2 years ago

urig commented 2 years ago

This PR fixes a bug where if you tried to save_temp() when the ParamStore contained a numpy ndarray with 2 or more values an exception would be raised (ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all())

The cause of the exception was that on the second call to save_temp(), when updating the DB "temp" record, SqlAlchemy compared the Param from the DB with the new Param value using the Param class' __eq__(). This involved a simple == comparison which triggered the exception.

The fix provides a more elaborate implementation of __eq__() that handles ndarrays as special cases and compares them using recommended numpy comparison methods.

github-actions[bot] commented 2 years ago

Unit Test Results

323 tests   317 :heavy_check_mark:  1m 2s :stopwatch:     1 suites      6 :zzz:     1 files        0 :x:

Results for commit f239718d.