[Numpy-discussion] Numpy 'None' comparison FutureWarning

Demitri Muna demitri.muna at gmail.com
Sun Sep 21 17:10:03 EDT 2014


I just encountered the following in my code:

FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.

I'm very concerned about this. This is a very common programming pattern (lazy loading):

class A(object):
    def __init__(self):
        self._some_array = None

    def some_array(self):
        if self._some_array == None:
            # perform some expensive setup of array
        return self._some_array

It seems to me that the new behavior will break this pattern. I think that redefining the "==" operator is a little too aggressive here. It strikes me as very nonstandard and not at all obvious to someone reading the code that the comparison is a very special case for numpy objects. Unless there's some aspect I'm missing here, I think an element-wise comparator should be more explicit.


Demitri Muna

Department of Astronomy
Le Ohio State University


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140921/3c8cfc27/attachment.html>

More information about the NumPy-Discussion mailing list