[pypy-issue] [issue1390] pickle creates invalid output on numpypy ndarray objects instead of crashing

Andrew McNabb tracker at bugs.pypy.org
Fri Feb 8 21:40:47 CET 2013


New submission from Andrew McNabb <amcnabb at mcnabbs.org>:

Ordinarily, pickling a numpypy ndarray object fails because this isn't implemented 
yet, which makes perfect sense:

>>>> pickle.dumps(A)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/lib64/pypy-1.9/lib-python/2.7/pickle.py", line 1417, in dumps
    Pickler(file, protocol).dump(obj)
  File "/usr/lib64/pypy-1.9/lib-python/2.7/pickle.py", line 224, in dump
    self.save(obj)
  File "/usr/lib64/pypy-1.9/lib-python/2.7/pickle.py", line 306, in save
    rv = reduce(self.proto)
  File "/usr/lib64/pypy-1.9/lib-python/2.7/copy_reg.py", line 70, in _reduce_ex
    raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle ndarray objects
>>>>

However, pickling with protocol version -1 looks like it succeeds:

>>>> pickle.dumps(A, -1)
'\x80\x02cnumpypy\nndarray\nq\x00)\x81q\x01.'
>>>>

However, the output of this is basically gibberish and can't be loaded with loads. It 
might be better for dumps to crash than to give an invalid output.

----------
messages: 5265
nosy: amcnabb, pypy-issue
priority: bug
status: unread
title: pickle creates invalid output on numpypy ndarray objects instead of crashing

________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue1390>
________________________________________


More information about the pypy-issue mailing list