[Numpy-discussion] Possible negative impact of future change to None comparison

Benjamin Root ben.v.root at gmail.com
Thu Apr 28 13:50:10 EDT 2016

Working on closing out some bug reports at work, and I ran into one about
comparisons to 'None' will result in elementwise object comparison in the
future. Now, I totally get the idea behind the change, and I am not here to
argue that decision. However, I have come across a situation where the
change might have an unexpected negative consequence.

Consider the following:

        p = Pool(min(len(tiles), maxprocs))
        res = p.map(_wrap_tilesum, izip(repeat(args.varname),

        (tiles, tile_start_dates, tile_end_dates,
                tile_lons, tile_lats) = zip(*res)

        if None in tiles:
            logging.critical("At least one tile was invalid. Aborting")
            raise Exception("Invalid data retrieved!")

Essentailly, in the nominal case, "tiles" would be a list of numpy arrays.
However, my error handling is such that if one of my subprocesses errors
out, then it returns a None instead of a numpy array. So, all I am doing is
testing to see if any of the items in the "tiles" list is None. I have zero
desire to actually compare None with the elements in the arrays that
happens to be in the list.

Of course, I can rewrite this if statement as `any(tile is None for tile in
tiles)`, but that isn't my point. Is `if None in tiles:` an unreasonable

Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20160428/4bc450fc/attachment.html>

More information about the NumPy-Discussion mailing list