简体   繁体   English

Python酸洗错误:TypeError:对象酸洗未返回列表。 numpy有问题吗?

[英]Python pickling error: TypeError: object pickle not returning list. Issue with numpy?

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). 就像我说的,一个很好(SingleP的实例列表),另一个在取消拾取时给我这个错误(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. 这些属性包括布尔值,元组列表,字符串,整数或numpy.ma.arrays列表。 Some of these arrays have masked numpy.nan. 其中一些数组已屏蔽numpy.nan。

This seems to be a potentially related issue: http://projects.scipy.org/numpy/ticket/897 . 这似乎是一个潜在的相关问题: http : //projects.scipy.org/numpy/ticket/897 In that case, the problem is arrays with an np.object as the array's dtype. 在这种情况下,问题在于将np.object作为数组的dtype。 However, I've been pickling and unpickling numpy.ma.arrays, including arrays that have masked numpy.nan, without problems for quite a while. 但是,我一直在腌制和拆开numpy.ma.arrays,包括屏蔽了numpy.nan的数组,已经有一段时间了。

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 nxmxl dimensions as some attributes, i have a list with n entries, each of which is an mxl array and now it's happy and pickles and unpickles. 我重写了代码的一部分,以便与其将nxmxl维数组作为某些属性,不如将它包含一个具有n个条目的列表,每个条目都是一个mxl数组,现在它很高兴,并且可以腌制和去渍。 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. 遇到了一个非常相似的问题:我重写了脚本,以使np.nan值也被屏蔽(我希望numpy,scipy和matplotlib可以始终如一地处理数组),但这导致pickle.load() 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. 我知道解决方案不多,但似乎可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM