[Numpy-discussion] dtype comparison, hash
Mon Jan 16 23:11:10 CST 2012
On Fri, 30 Dec 2011 20:05:14 +0000, Robert Kern <email@example.com> wrote:
> On Fri, Dec 30, 2011 at 18:57, Andreas Kloeckner
> <firstname.lastname@example.org> wrote:
> > Hi Robert,
> > On Tue, 27 Dec 2011 10:17:41 +0000, Robert Kern <email@example.com> wrote:
> >> On Tue, Dec 27, 2011 at 01:22, Andreas Kloeckner
> >> <firstname.lastname@example.org> wrote:
> >> > Hi all,
> >> >
> >> > Two questions:
> >> >
> >> > - Are dtypes supposed to be comparable (i.e. implement '==', '!=')?
> >> Yes.
> >> > - Are dtypes supposed to be hashable?
> >> Yes, with caveats. Strictly speaking, we violate the condition that
> >> objects that equal each other should hash equal since we define == to
> >> be rather free. Namely,
> >> np.dtype(x) == x
> >> for all objects x that can be converted to a dtype.
> >> np.dtype(float) == np.dtype('float')
> >> np.dtype(float) == float
> >> np.dtype(float) == 'float'
> >> Since hash(float) != hash('float') we cannot implement
> >> np.dtype.__hash__() to follow the stricture that objects that compare
> >> equal should hash equal.
> >> However, if you restrict the domain of objects to just dtypes (i.e.
> >> only consider dicts that use only actual dtype objects as keys instead
> >> of arbitrary mixtures of objects), then the stricture is obeyed. This
> >> is a useful domain that is used internally in numpy.
> >> Is this the problem that you found?
> > Thanks for the reply.
> > It doesn't seem like this is our issue--instead, we're encountering two
> > different dtype objects that claim to be float64, compare as equal, but
> > don't hash to the same value.
> > I've asked the user who encountered the user to investigate, and I'll
> > be back with more detail in a bit.
> I think we've run into this before and tried to fix it. Try to find
> the version of numpy the user has and a minimal example, if you can.
This is what Thomas found:
Hope this helps,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120117/a4c2e34f/attachment.bin
More information about the NumPy-Discussion