[Numpy-discussion] hashing dtypes, new variation, old theme

Robert Kern robert.kern at gmail.com
Thu Mar 17 17:35:27 EDT 2011


On Wed, Mar 16, 2011 at 15:21, Mark Wiebe <mwwiebe at gmail.com> wrote:

> That sounds like a good fix to me. Whenever objects compare equal, they
> should hash to the same value.

There is a limit to how far we can actually satisfy this requirement.
For the implementation of np.dtype.__eq__(), we coerce the other
argument to a dtype object.

[~]
|1> np.dtype(int) == int
True

[~]
|2> np.dtype(int) == 'i4'
True

[~]
|3> hash(int) != hash('i4')
True


As long as we define np.dtype.__eq__() in that way, we cannot satisfy
the requirement. The best we can do is make sure that for all true
dtype objects, if they compare equal then they hash equal. So you
could make a well-behaved dict with true dtypes as keys, but not
dtypes and "dtype-coercable" objects.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco



More information about the NumPy-Discussion mailing list