[Numpy-discussion] FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
Andreas Hilboll
lists at hilboll.de
Wed Apr 8 14:42:27 EDT 2015
On 08.04.2015 20:30, Nathaniel Smith wrote:
> On Apr 8, 2015 2:16 PM, "Andreas Hilboll" <lists at hilboll.de
> <mailto:lists at hilboll.de>> wrote:
>>
>> Hi all,
>>
>> I'm commonly using function signatures like
>>
>> def myfunc(a, b, c=None):
>> if c is None:
>> # do something ...
>> ...
>>
>> where c is an optional array argument. For some time now, I'm getting a
>>
>> FutureWarning: comparison to `None` will result in an elementwise
>> object comparison in the future
>>
>> from the "c is None" comparison. I'm wondering what would be the best
>> way to do this check in a future-proof way?
>
> As far as I know, you should be getting the warning when you write
> c == None
> and the fix should be to write
> c is None
> instead. (And this is definitely an important fix -- it's basically a
> bug in numpy that the == form ever worked.) Are you certain that you're
> getting warnings from 'c is None'?
My mistake; I was actually doing
if p1 is None == h1 is None:
instead of
if (p1 is None) == (h1 is None):
Sorry for the noise.
-- Andreas.
More information about the NumPy-Discussion
mailing list