Error when loading pickled saved df with version < 0.6.3
See original GitHub issueI’m using geopandas for a while and am used to save my gdf as pickle files, and then open it directly with pandas
. I have some old files that I want to open. I guess the files were saved as my pandas version was 0.6.2
, but I’m not sure.
Now that I’m trying to re-open it I get the following error :
AttributeError: 'GeoDataFrame' object has no attribute '_item_cache'
Here is a code sample which makes the problem reproducible :
with geopandas==0.6.3
run
import pandas as pd
import geopandas as gpd
from shapely.geometry import Point
data = [[3, 45, 1], [3.1, 45.2, 1.5], [2.7, 44.5, 2.1]]
data = pd.DataFrame(data, columns=['Longitude', 'Latitude', 'value'])
data['geometry'] = list(zip(data['Longitude'], data['Latitude']))
data['geometry'] = data['geometry'].apply(Point)
data = gpd.GeoDataFrame(data)
data.to_pickle('df.pkl')
And then with geopandas==0.8.0
(or 0.7.0
) try :
import pandas as pd
df = pd.read_pickle('df.pkl')
It should raise the same error.
- I’m not sure if it’s a problem of
pickle
orgeopandas
, I naively tried to grep__item_cache
in the gpd code but it wasn’t successful either with0.6.3
or with0.8.0
- This is troublesome because I have to keep
0.6.3
in the meantime unless someone sees a turnaround (I could make a “clean save” of all my pickled gdf with0.6.3
which can be read with0.8.0
but I don’t know if this is possible) - Maybe my workflow is terrible and then I’ll gladly take some advice !
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
Read a pickle with a different version of pandas - Stack Overflow
Load data with the newest version of python and pandas (python 3.8 and pandas 1.4.1 in my case). import pandas as pd import...
Read more >Changes to the Snowpark Python API
Added a lock to a UDF or UDTF when it is called for the first time per thread. Improved the error message for...
Read more >Data Import : : CHEAT SHEET
to clear the last error. py_last_error() py_save_object(object, filename, pickle = "pickle"). Save and load Python objects with pickle. Also.
Read more >Bug listing with status RESOLVED with resolution OBSOLETE ...
... Bug:165330 - "dev-java/sun-jdk-1.6.0-r1 error while loading shared libraries: libjli.so - /proc is not mounted" status:RESOLVED resolution:OBSOLETE ...
Read more >joblib Documentation - Read the Docs
If you are switching between python versions, you will need to save a different joblib pickle for each python version. Here are a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am not sure if there is a way how to open old pickle in new pandas. Pickle as a format is not meant for a data storage, especially not with compatibility between versions. The nature of pickle itself does not allow that, if there are significant changes to pandas or geopandas in between the versions. These could be under the hood but still makes the pickle file unusable. My recommendation would be to save those pickle files as some standard geospatial data format with 0.6.3 so you can open that in any other version.
Closed by #1511