[NumPy-Tickets] [NumPy] #1702: dtype truth value is False

NumPy Trac numpy-tickets@scipy....
Wed Dec 29 18:09:16 CST 2010


#1702: dtype truth value is False
------------------------+---------------------------------------------------
 Reporter:  pv          |       Owner:  somebody
     Type:  defect      |      Status:  new     
 Priority:  normal      |   Milestone:  2.0.0   
Component:  numpy.core  |     Version:  1.5.0   
 Keywords:              |  
------------------------+---------------------------------------------------

Comment(by jpeel):

 The reason that a dtype like in the ticket description is False is because
 a dtype is a mapping (it is also a sequence). When PyObject_IsTrue is
 called in the dtype, it first registers as a mapping and uses the
 mp_length to determine if the object is True. The mp_length of a dtype is
 currently equal to the length of the names tuple of the descriptor. This
 means that

 {{{ bool(np.dtype([('f0','i8')])) }}}

 will be True because it's length will be 1 (it has a field name). However,

 {{{ bool(np.dtype('i8'))}}}

 will be False because there is no field name. This could be changed if we
 did something like assign a field name even if there is only one type
 passed in. Personally, I don't think that it is worthwhile to do so, but
 maybe someone else sees greater value to it.

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1702#comment:2>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list