Hyperopt: Unintended implicit conversion to bool in SONify

Created on 9 Oct 2019  路  4Comments  路  Source: hyperopt/hyperopt

The conditional expression https://github.com/hyperopt/hyperopt/blob/23a42a34052699bf7433f4a7c0a659cdab87ce54/hyperopt/base.py#L154 was (I presume) intended to catch boolean values, but when arg is e.g a pandas.Series, this test causes a ValueError because arg is implicitly converted to bool:

In [6]: s = pd.Series([0.1, 0.2])

In [7]: s in (True, False)
Traceback (most recent call last):

  File "<ipython-input-7-9fa06f10f888>", line 1, in <module>
    s in (True, False)

  File "C:\Users\Roman\Anaconda3\lib\site-packages\pandas\core\generic.py", line 1576, in __nonzero__
    .format(self.__class__.__name__))

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

I think that it would be better to replace elif arg in (True, False) with elif isinstance(arg, bool).

All 4 comments

I don't think Hyperopt supports Pandas, you'll need to convert to either a List or Dictionary.

I understand, but the change I proposed would result in a correct error being generated. Currently it's a bit confusing.

@katastrofa999 indeed a catastrophe, mind sending a PR?

Done.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MaartenKool picture MaartenKool  路  4Comments

VinodKumar9576 picture VinodKumar9576  路  5Comments

EgorBu picture EgorBu  路  4Comments

MrDominikku picture MrDominikku  路  6Comments

peiyaoli picture peiyaoli  路  4Comments