Python酸洗错误:TypeError:对象酸洗未返回列表. numpy有问题吗? [英] Python pickling error: TypeError: object pickle not returning list. Issue with numpy?

查看:94
本文介绍了Python酸洗错误:TypeError:对象酸洗未返回列表. numpy有问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个脚本,该脚本会进行一些数据处理,然后在进行更多处理之前先对结果进行腌制,这样我就可以弄乱用于绘制的最终参数.我正在腌制我创建的两个类的列表.对每个列表进行酸洗都可以,但是对一个列表进行酸洗会返回以下错误:

Traceback (most recent call last):
  File "script.py", line 980, in <module>
    main()
  File "script.py", line 956, in promoter_main
    open(os.path.join(pickle_dir, 'doublep.pickle'), 'rb'))
  File "/usr/lib/python2.6/pickle.py", line 1370, in load
    return Unpickler(file).load()
  File "/usr/lib/python2.6/pickle.py", line 858, in load
    dispatch[key](self)
  File "/usr/lib/python2.6/pickle.py", line 1217, in load_build
    setstate(state)
  File "/home/jmerkin/software/numpy/numpy/ma/core.py", line 5468, in __setstate__
    ndarray.__setstate__(self, (shp, typ, isf, raw))
TypeError: object pickle not returning list

正如我所说,一个很好(SingleP实例的列表),另一个在取消拾取时(DoubleP的实例)给了我这个错误.我犹豫要为该类发布整个代码,因为它很长,但基本上,它有几个填充某些属性的方法.这些属性包括布尔值,元组列表,字符串,整数或numpy.ma.arrays列表.其中一些数组已屏蔽numpy.nan.

这似乎是一个潜在的相关问题: http://projects.scipy.org/numpy /ticket/897 .在这种情况下,问题在于将np.object作为数组的dtype.但是,我一直在腌制和拆开numpy.ma.arrays,包括掩盖numpy.nan的数组,已经有一段时间没有问题了.

我在腌制中缺少一些愚蠢的东西吗?在腌制和尝试腌制之间,我不会更改该对象.


我重写了代码中的某些位,因此我没有一个包含n x m x l维数组作为某些属性,而是拥有一个包含n个条目的列表,每个条目都是一个m x l数组,现在它很高兴并且可以腌制和去渍.我很困惑,但它运行.我不会关闭此问题,因为我的问题仍然存在,为什么我会收到该错误?

解决方案

有一个非常相似的问题:我重写了一个脚本,使np.nan值也被屏蔽(我希望numpy,scipy和matplotlib能够一致地处理数组. ),但这导致pickle.load()阻塞.我摆脱了遮罩的阵列,一切又恢复了.解决的方法似乎是添加和删除蒙版,以使泡菜腌渍.我知道解决方案不多,但似乎可行.

I wrote a script that does a bit of data processing, then pickles the results before doing some more processing so I can fiddle with final parameters for plotting. I am pickling lists of two classes that I've created. Pickling is fine for each list, but unpickling one list returns the following error:

Traceback (most recent call last):
  File "script.py", line 980, in <module>
    main()
  File "script.py", line 956, in promoter_main
    open(os.path.join(pickle_dir, 'doublep.pickle'), 'rb'))
  File "/usr/lib/python2.6/pickle.py", line 1370, in load
    return Unpickler(file).load()
  File "/usr/lib/python2.6/pickle.py", line 858, in load
    dispatch[key](self)
  File "/usr/lib/python2.6/pickle.py", line 1217, in load_build
    setstate(state)
  File "/home/jmerkin/software/numpy/numpy/ma/core.py", line 5468, in __setstate__
    ndarray.__setstate__(self, (shp, typ, isf, raw))
TypeError: object pickle not returning list

As I said, one goes fine (list of instances of SingleP), the other gives me this error when unpickling (instances of DoubleP). I hesitate to post the entire code for the class because it's long, but basically, it has a couple methods that populate some attributes. These attributes consist of either booleans, lists of tuples, strings, ints, or lists of numpy.ma.arrays. Some of these arrays have masked numpy.nan.

This seems to be a potentially related issue: http://projects.scipy.org/numpy/ticket/897. In that case, the problem is arrays with an np.object as the array's dtype. However, I've been pickling and unpickling numpy.ma.arrays, including arrays that have masked numpy.nan, without problems for quite a while.

Am I missing something silly with pickling? I am not changing the object between when it was pickled and when I try to unpickle.


i rewrote bits of the code so that rather than than having an array of n x m x l dimensions as some attributes, i have a list with n entries, each of which is an m x l array and now it's happy and pickles and unpickles. i'm very confused but it runs. i'm not going to close this, because my questions persists, why did i get that error?

解决方案

Had a very similar issue: I rewrote a script so that the np.nan values were masked as well (I wish numpy, scipy and matplotlib could handle arrays consistently) but this caused pickle.load() to baulk. I got rid of the masked arrays and everything worked again. The solution seems to be to add and remove masks to please pickle. Not much of a solution, I know, but it seems to work.

这篇关于Python酸洗错误:TypeError:对象酸洗未返回列表. numpy有问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆