question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when loading pickled saved df with version < 0.6.3

See original GitHub issue

I’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 or geopandas, I naively tried to grep __item_cache in the gpd code but it wasn’t successful either with 0.6.3 or with 0.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 with 0.6.3 which can be read with 0.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:closed
  • Created 3 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
martinfleiscommented, Jul 2, 2020

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.

0reactions
jorisvandenbosschecommented, Jul 15, 2020

Closed by #1511

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found