[Numpy-tickets] [NumPy] #598: incorrect behaviour with ( "%d"%a[i]) on uint64

NumPy numpy-tickets@scipy....
Tue Oct 30 11:44:36 CDT 2007

#598: incorrect behaviour with ( "%d"%a[i]) on uint64
 Reporter:  gregsmith_to  |        Owner:  somebody
     Type:  defect        |       Status:  reopened
 Priority:  normal        |    Milestone:  1.0.4   
Component:  Other         |      Version:  1.0.2   
 Severity:  normal        |   Resolution:          
 Keywords:                |  
Comment (by gregsmith_to):

 I've looked into it more deeply, and it looks to me that numpy is now
 working properly on 1.04, and this undesirable behaviour is due to a
 Python problem. Sorry about the hassle.

 I've been operating on an incorrect assumption about how %d works, and why
 the exception is raised.

 Looking through the python 2.5 source, that exception is raised by "%d"
 etc when {{{PyInt_AsLong}}} fails to convert the object (this is only
 tried when the object is not a python long to begin with). Although
 {{{PyInt_AsLong}}} is capable of converting general objects (it calls the
 'int' conversion if present), it returns a C long, and is therefore not
 capable of handling the uint64 case properly in general (or even uint32 on
 a 32-bit machine). It supports an int conversion which actually produces a
 python Long: if it calls the nb_int conversion method of a type, and that
 returns a python long, it then tries to get the value of that long as a C
 long, and if that fails because the value is out of range the exception is
 raised. So, it looks like in 1.04 "%d" % a[0] will work when the value
 fits in a C long, and raise an exception when it doesn't, which is the
 best available behaviour without fixing Python. And it should work
 properly when Python is fixed, so that %d handles general objects which
 convert to python longs.

 Please close.

Ticket URL: <http://scipy.org/scipy/numpy/ticket/598#comment:6>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.

More information about the Numpy-tickets mailing list