[Numpy-discussion] A change with minor compatibility questions

Travis Oliphant teoliphant at gmail.com
Wed Oct 17 11:22:28 EDT 2012

Hey all, 


is  a pull request that changes the hash function for numpy void scalars.   These are the objects returned from fully indexing a structured array:  array[i] if array is a 1-d structured array. 

Currently their hash function just hashes the pointer to the underlying data.    This means that void scalars can be used as keys in a dictionary but the behavior is non-intuitive because another void scalar with the same data but pointing to a different region of memory will hash differently.  

The pull request makes it so that two void scalars with the same data will hash to the same value (using the same algorithm as a tuple hash).    This pull request also only allows read-only scalars to be hashed. 

There is a small chance this will break someone's code if they relied on this behavior.  I don't believe anyone is currently relying on this behavior -- but I've been proven wrong before.   What do people on this list think?   

Should we raise a warning in the next release when a hash function on a void scalar is called or just make the change, put it in the release notes and make a few people change their code if needed.  The problem was identified by a couple of users of NumPy currently which is why I think that people who have tried using numpy void scalars as keys aren't doing it right now but are instead converting them to tuples first. 


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

More information about the NumPy-Discussion mailing list