无法打开使用pickle创建的文件。

huangapple go评论101阅读模式
英文:

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( &quot;doublesplit_list.p&quot;, &quot;wb&quot; ))

Then I tried to use

    doublesplit_list = pickle.load(open(&#39;doublesplit_list.p&#39;, &#39;rb&#39;))

And then I got

TypeError                                 Traceback (most recent call last)
Input In [22], in &lt;cell line: 1&gt;()
----&gt; 1 doublesplit_list = pickle.load(open(&#39;doublesplit_list.p&#39;, &#39;rb&#39;))

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.

huangapple
  • 本文由 发表于 2023年3月7日 10:11:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/75657473.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定