简体   繁体   English

Python酸洗错误:TypeError:对象酸洗未返回列表

[英]Python pickling error: TypeError: object pickle not returning list

I am aware if this very old question Python pickling error: TypeError: object pickle not returning list. 我知道这个非常老的问题Python酸洗错误:TypeError:对象酸洗不返回列表。 Issue with numpy? numpy有问题吗? but the only answer given is rather obscure. 但是给出的唯一答案是相当晦涩的。

This is the code that reproduces the issue in Python 3.6. 这是重现Python 3.6中问题的代码。

import pickle
from astroquery.irsa import Irsa
from astropy import units as u

# Query region.
table = Irsa.query_region("m31", catalog="fp_psc", spatial="Cone",
                          radius=.5 * u.arcmin)

# Dump table.
with open('table.pkl', 'wb') as f:
    pickle.dump(table, f)

# This is where the issue appears.
with open('table.pkl', 'rb') as f:
    table = pickle.load(f)

When trying to load the pickled data, it fails with: 尝试加载腌制的数据时,失败并显示:

Traceback (most recent call last):
  File "/home/gabriel/Descargas/test.py", line 17, in <module>
    table2 = pickle.load(f)
  File "/home/gabriel/anaconda3/envs/cat-match/lib/python3.6/site-packages/astropy/table/column.py", line 238, in __setstate__
    super_class.__setstate__(self, state)
  File "/home/gabriel/anaconda3/envs/cat-match/lib/python3.6/site-packages/numpy/ma/core.py", line 5869, in __setstate__
    super(MaskedArray, self).__setstate__((shp, typ, isf, raw))
TypeError: object pickle not returning list

How can I get around this? 我该如何解决?


Using conda you can install the requirements in a Python 3 environment with: 使用conda可以通过以下命令在Python 3环境中安装需求:

conda install astropy
conda install -c astropy astroquery

The linked answer mentions numpy masked arrays causing trouble when unpickling them. 链接的答案中提到了numpy掩码数组,这些数组在取消拾取时会引起麻烦。 Given that astropy tables may indeed have masked entries (not every object or position may have a value for, eg, every band or whatever relevant columns), this could indeed be the source of your problem: masked arrays. 考虑到天花乱麻的表可能确实具有掩码条目(并非每个对象或位置可能都有例如每个带或任何相关列的值),这确实可能是问题的根源:掩码数组。

The numpy issue trickers shows that problem as well: Masked array with object dtype doesn't unpickle . numpy问题骗子也显示了该问题: 具有对象 dtype的蒙版数组不会散乱 And that appears to be solved in pull request 8122 . 这似乎在拉取请求8122中已解决。

Scouring the release notes for Numpy 1.12.0 shows this pull request in there. 对Numpy 1.12.0发行说明进行搜索可以在其中看到此拉取请求。 So unless you're already using numpy 1.12, it may be your worth to upgrade numpy. 因此,除非您已经在使用numpy 1.12,否则可能值得升级numpy。

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

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