[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:
>
>
/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/VPython-6.10-py2.7-macosx-10.10-x86_64.egg/visual_common/materials.py:70:
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:

https://github.com/BruceSherwood/vpython-wx/blob/master/src/python/numeric_texture.cpp#L258

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
FutureWarning.

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