[Numpy-discussion] numpy, "H", and struct: numpy bug?

Emanuele Olivetti emanuele at relativita.com
Tue Mar 4 05:22:57 EST 2008


Hi,

this snippet is causing troubles:
---
import struct
import numpy

a=numpy.arange(10).astype('H')
b=struct.pack("<10H",*a)
---
(The module struct simply packs and unpacks data in byte-blobs).

It works OK with python2.4, but gives problems with python2.5.
On my laptop (linux x86_64 on intel core 2 duo) I got this warning:
---
a.py:5: DeprecationWarning: struct integer overflow masking is deprecated
  b=struct.pack("<10H",*a)
---

On another workstation (linux i686 on intel core 2, so a 32 bit OS on 64 bit
architecture) I got warning plus an _error_, when using python2.5 (python2.4
works flawlessly):
---
a.py:5: DeprecationWarning: struct integer overflow masking is deprecated
  b=struct.pack("<10H",*a)
Traceback (most recent call last):
  File "a.py", line 5, in <module>
    b=struct.pack("<10H",*a)
  File "/usr/lib/python2.5/struct.py", line 63, in pack
    return o.pack(*args)
SystemError: ../Objects/longobject.c:322: bad argument to internal function
---

Both computers are ubuntu gutsy 7.10, updated.
Details:
python,  2.5.1-1ubuntu2
numpy, 1:1.0.3-1ubuntu2
Same versions on both machines.

I did some little test _without_ numpy and the struct module seems not
having
problems. Is this a numpy bug?
Note: If you remove "<" from the struct format string then it seems to work
ok.

Regards,

Emanuele





More information about the NumPy-Discussion mailing list