英文:
Failed to open a file with pickle
问题
我已将一组Pandas时间戳对的字典保存在pickle文件中,使用以下代码:
pickle.dump(doublesplit_list, open("doublesplit_list.p", "wb"))
然后,我尝试使用以下代码加载它:
doublesplit_list = pickle.load(open('doublesplit_list.p', 'rb'))
然后,我遇到了以下错误:
TypeError Traceback (most recent call last)
Input In [22], in <cell line: 1>()
----> 1 doublesplit_list = pickle.load(open('doublesplit_list.p', 'rb'))
File D:\Porgrams\Conda\lib\site-packages\pandas\_libs\tslibs\timestamps.pyx:132, in pandas._libs.tslibs.timestamps._unpickle_timestamp()
TypeError: _unpickle_timestamp() takes exactly 3 positional arguments (4 given)
我该怎么办?
英文:
I've saved a dictionary of dictionaties of pairs of pandas timestamps in the pickle file with
pickle.dump(doublesplit_list, open( "doublesplit_list.p", "wb" ))
Then I tried to use
doublesplit_list = pickle.load(open('doublesplit_list.p', 'rb'))
And then I got
TypeError Traceback (most recent call last)
Input In [22], in <cell line: 1>()
----> 1 doublesplit_list = pickle.load(open('doublesplit_list.p', 'rb'))
File D:\Porgrams\Conda\lib\site-packages\pandas\_libs\tslibs\timestamps.pyx:132, in pandas._libs.tslibs.timestamps._unpickle_timestamp()
TypeError: _unpickle_timestamp() takes exactly 3 positional arguments (4 given)
What should I do?
答案1
得分: 1
根据错误消息显示,错误发生在pandas\_libs\tslibs\timestamps.pyx
文件的第132行,在_unpickle_timestamp()
的定义中,错误消息告诉您它需要精确的3个位置参数,但提供了4个。
然而,从GitHub 存储库来看,这特定的行是这样的:
def _unpickle_timestamp(value, freq, tz, reso=NPY_FR_ns):
它的确接受4个参数,所以不应该出现错误消息,指出该函数需要精确的3个参数。即使传递了比应有的更多参数,错误消息也应该类似于 TypeError: _unpickle_timestamp() 接受3到4个位置参数(... 给定)
。
我建议您检查一下本地机器上的该文件,看看它是否与GitHub 存储库中的内容匹配。这可能是与以前版本的兼容性问题。
英文:
From what the error message says, the error occurs in \lib\site-packages\pandas\_libs\tslibs\timestamps.pyx
at line 132 in the definition of _unpickle_timestamp()
and the error message for you reads that it takes exactly 3 positional args but 4 were given.
However, from the GitHub repo: that particular line is:
def _unpickle_timestamp(value, freq, tz, reso=NPY_FR_ns):
which does indeed take 4 args so you shouldn't have seen an error like that where it says that function takes exactly 3 args. Even if there was more args passed to it than it should have, the error message should've read like TypeError: _unpickle_timestamp() takes from 3 to 4 positional arguments (... given)
I suggest checking that particular file in your local machine and see if it matches with what is in the GitHub repo. It could be a compatibility issue with a previous version.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论