thouis / numpy-trac-migration

numpy Trac to github issues migration
2 stars 3 forks source link

dype comparison with other types raise a TypeError (Trac #1001) #4804

Open numpy-gitbot opened 12 years ago

numpy-gitbot commented 12 years ago

Original ticket http://projects.scipy.org/numpy/ticket/1001 on 2009-02-06 by trac user ashleywalsh, assigned to unknown.

If you compare a dtype with another object for equality a TypeError is raised if the second object cannot be converted to a dtype:

>>> import numpy
>>> numpy.dtype(float) == 'float'
True
>>> numpy.dtype(float) == 'i'
False
>>> numpy.dtype(float) == object()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: data type not understood
>>> numpy.dtype(float) == 'x'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: data type not understood

In my case this caused epydoc to crash because it attempted to compare a dtype that was class attribute with (I think) an object was an attribute of the same name on a super-class.

numpy-gitbot commented 12 years ago

trac user ashleywalsh wrote on 2009-02-06

"was a class attribute" -- and I hassle people in our office who don't use the "preview" on our internal Tracs...

numpy-gitbot commented 12 years ago

Milestone changed to 1.5.1 by atmention:pv on 2010-10-10

numpy-gitbot commented 12 years ago

atmention:mwiebe wrote on 2011-03-24

This is because dtype comparison coerces the other value to a dtype. This behavior actually violates the requirements of the hashing protocol, and should be changed at some point to allow dtypes to be used in dictionaries without the potential for bad behavior.

numpy-gitbot commented 12 years ago

Milestone changed to Unscheduled by atmention:mwiebe on 2011-03-24