[Numpy-discussion] Why am I getting a FutureWarning with this code?

Robert Kern robert.kern at gmail.com
Mon Dec 22 11:28:04 EST 2014

On Mon, Dec 22, 2014 at 10:35 AM, Steve Spicklemire <steve at spvi.com> wrote:
> I’m working on visual python (http://vpython.org) which lists numpy among
its dependencies.
> I recently updated my numpy installation to 1.9.1 and I’m now
encountering this error:
FutureWarning: comparison to `None` will result in an elementwise object
comparison in the future.
>   self.__setattr__(key, value)
> Oddly, the code in question looks like this:
>      62 from . import cvisual
>      63 from numpy import array, reshape, fromstring, ubyte, ndarray,
zeros, asarray
>      64 import os.path, math
>      65
>      66 class raw_texture(cvisual.texture):
>      67     def __init__(self, **kwargs):
>      68         cvisual.texture.__init__(self)
>      69         for key, value in kwargs.items():
>      70             self.__setattr__(key, value)

The answer is in the implementation of cvisual.texture somewhere. This is
Boost.Python C++ code, so there's a fair bit of magic going on such that I
can't pinpoint the precise line that's causing this, but I suspect that it
might be this one:


When `data` is assigned, this line checks if the value is None so that it
can raise an error to tell you not to do that (I believe, from the context,
that `py::object()` is the Boost.Python idiom for getting the None
singleton). I *think*, but am not positive, that Boost.Python converts the
C++ == operator into a Python == operation, so that would trigger this

So VPython is the code that needs to be fixed to do an identity comparison
with None rather than an equality comparison.

Robert Kern
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20141222/b0c89f6d/attachment.html>

More information about the NumPy-Discussion mailing list