'AttributeError: Can't get attribute 'PandasIndexAdapter' on <module 'xarray.core.indexing'
I am trying to unpickle a file but i get this error while running the following code:
import pickle
import pandas as pd
import numpy
unpickled_df = pd.read_pickle("./ToyData.pickle")
unpickled_df
or
import pickle
# load : get the data from file
data = pickle.load(open('ToyData.pickle', "rb"))
error output:
AttributeError Traceback (most recent call last)
<ipython-input-3-4f30cc427816> in <module>
1 import pickle
2 # load : get the data from file
----> 3 data = pickle.load(open('ToyData.pickle', "rb"))
4 # loads : get the data from var
5 #data = pickle.load(var)
AttributeError: Can't get attribute 'PandasIndexAdapter' on <module 'xarray.core.indexing' from 'C:\\Users\\User\\anaconda3\\lib\\site-packages\\xarray\\core\\indexing.py'>
How can i solve this. I have tried to install xarray, dask and other xarray dependancies using the code below:
python -m pip install "xarray[complete]"
python -m pip install "xarray[io]" # Install optional dependencies for handling I/O
#python -m pip install "xarray[accel]" # Install optional dependencies for accelerating xarray
#python -m pip install "xarray[parallel]" # Install optional dependencies for dask arrays
#python -m pip install "xarray[viz]" # Install optional dependencies for visualization
conda install xarray-0.16.1-py_0
I used anaconda jupyter notebook to run the script above. I am unable to read the pickle file.
Solution 1:[1]
You cannot pickle.load files in a newly updated version of xarray that were made in a previous version of xarray.
This is a known error that has no solution as "pickling is not recommended for long-term storage". https://github.com/pydata/xarray/discussions/5642
.hdf or .json are better alternatives for long-term storage of your data since those are more likely to be supported in future versions.
Solution 2:[2]
I had the same problem with results = torch.load("results.pth.tar")
and get "AttributeError: Can't get attribute 'PandasIndexAdapter' on <module 'xarray.core.indexing'
".
I solve it by changing the version I have on my computer by the version the file.pth.tar was saved with.
In my case the file was saved with xarray version '0.14.1' and on my compter I had '2022.3.0'. I change with pip install xarray==0.14.1
and it works !
If you are able to find the version "ToyData.pickle" is saved with install this version in the environment of your notebook. Otherwise you can try with every single version of xarray (good luck xD) !
I hope it can help !
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 |