Usiamo pandas Dataframe come contenitore dati principale per i nostri dati di serie storiche. Imballiamo il dataframe in blob binari in un documento mongoDB per l'archiviazione insieme a chiavi per metadati sul blob delle serie temporali.Problema di compatibilità all'indietro di Pandas con pickle 0.14.1 e 0.15.2
Si è verificato un errore durante l'aggiornamento da panda da 0.14.1 a 0.15.2.
Create un blob binario di panda dataframe (0.14.1)
import lz4
import cPickle
bd = lz4.compress(cPickle.dumps(df,cPickle.HIGHEST_PROTOCOL))
Caso Errore: Read indietro nel da MongoDB con i panda 0.15.2
cPickle.loads(lz4.decompress(bd))
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-37-76f7b0b41426> in <module>()
----> 1 cPickle.loads(lz4.decompress(bd))
TypeError: ('_reconstruct: First argument must be a sub-type of ndarray', <built-in function _reconstruct>, (<class 'pandas.core.index.Index'>, (0,), 'b'))
Successo Caso: Leggi di nuovo da mongoDB con panda 0.14.1 senza errori.
questo sembra essere simile a un vecchio filo pila Pandas compiled from source: default pickle behavior changed con un commento utile da https://stackoverflow.com/users/644898/jeff
The error message you are seeing `TypeError: _reconstruct: First argument must be a sub-type of ndarray is that the python default unpickler makes sure that the class hierarchy that was pickled is exactly the same what it is recreating. Since Series has changed between versions this is no longer possible with the default unpickler, (this IMHO is a bug in the way pickle works). In any event, pandas will unpickle pre-0.13 pickles that have Series objects."
Tutte le idee su soluzione o soluzioni?
ricreare errore:
installazione in panda 0.14.1 ENV:
df = pd.DataFrame(np.random.randn(10,10))
cPickle.dump(df,open("cp0141.p","wb"))
cPickle.load(open('cp0141.p','r')) # no error
Creare errore nel panda 0.15.2 ENV:
cPickle.load(open('cp0141.p','r'))
TypeError: ('_reconstruct: First argument must be a sub-type of ndarray', <built-in function_reconstruct>, (<class 'pandas.core.index.Int64Index'>, (0,), 'b'))
+1 !, Ciò che è importante è: Funziona anche quando il pickle non è un dataframe :)! Almeno funzionava nel mio caso e avevo memorizzato come valori una directory contenente chiavi di stringa e Dataframes. – ntg