[Numpy-discussion] FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.

Nathaniel Smith njs at pobox.com
Wed Apr 8 14:30:11 EDT 2015


On Apr 8, 2015 2:16 PM, "Andreas Hilboll" <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'?

-n
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150408/28301e1d/attachment.html>


More information about the NumPy-Discussion mailing list