[Numpy-discussion] longlong format error with Python <= 2.6 in scalartypes.c

Derek Homeier derek at astro.physik.uni-goettingen.de
Thu Aug 4 19:08:51 EDT 2011


Hi,

commits c15a807e and c135371e (thus most immediately addressed to Mark, but I am sending this to the list hoping for more insight on the issue) introduce a test failure with Python 2.5+2.6 on Mac:

FAIL: test_timedelta_scalar_construction (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/derek/lib/python2.6/site-packages/numpy/core/tests/test_datetime.py", line 219, in test_timedelta_scalar_construction
    assert_equal(str(np.timedelta64(3, 's')), '3 seconds')
  File "/Users/derek/lib/python2.6/site-packages/numpy/testing/utils.py", line 313, in assert_equal
    raise AssertionError(msg)
AssertionError: 
Items are not equal:
 ACTUAL: '%lld seconds'
 DESIRED: '3 seconds'

due to the "lld" format passed to PyUString_FromFormat in scalartypes.c. 
In the current npy_common.h I found the comment 
 *      in Python 2.6 the %lld formatter is not supported. In this
 *      case we work around the problem by using the %zd formatter.
though I did not notice that problem when I cleaned up the NPY_LONGLONG_FMT definitions in that file (and it is not entirely clear whether the comment only pertains to Windows...). Anyway changing the formatters in scalartypes.c to "zd" as well removes the failure and still works with Python 2.7 and 3.2 (at least on Mac OS). However I am wondering if 
a) NPY_[U]LONGLONG_FMT should also be defined conditional to the Python version (and if "%zu" is a valid formatter), and 
b) scalartypes.c should use NPY_LONGLONG_FMT from npy_common.h

I am attaching a patch implementing a), but only the quick and dirty solution to b).

Cheers,
						Derek

-------------- next part --------------
A non-text attachment was scrubbed...
Name: npy_longlong_fmt.patch
Type: application/octet-stream
Size: 2151 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110805/4944ecdb/attachment.obj>


More information about the NumPy-Discussion mailing list