1
1
""" ipc format compat """
2
2
3
3
from pandas .types .generic import ABCIndexClass , ABCSeries , ABCDataFrame
4
- from pandas .compat import BytesIO , string_types
4
+ from pandas .compat import string_types , cPickle
5
5
from pandas ._libs .lib import is_string_array , is_unicode_array
6
6
from pandas .types .common import is_object_dtype
7
7
@@ -82,18 +82,18 @@ def to_ipc(obj, engine='infer'):
82
82
def _to_pyarrow (df ):
83
83
""" helper routine to return via pyarrow """
84
84
pyarrow = _try_import ()
85
- return pyarrow .write_ipc (df )
85
+ d = pyarrow .write_ipc (df )
86
+ d ['engine' ] = 'pyarrow'
87
+ return d
86
88
87
89
88
90
def _to_pickle (obj ):
89
91
""" helper routine to return a pickle of an object """
90
- from pandas import to_pickle
91
- db = BytesIO ()
92
- to_pickle (obj , db )
93
- return db .getvalue ()
92
+ d = {'engine' : 'pickle' , 'data' : cPickle .dumps (obj )}
93
+ return d
94
94
95
95
96
- def read_ipc (db , engine = 'infer' ):
96
+ def read_ipc (db ):
97
97
"""
98
98
Load a pyarrow ipc format object from the file dict-of-bytes
99
99
@@ -102,21 +102,20 @@ def read_ipc(db, engine='infer'):
102
102
Parameters
103
103
----------
104
104
dict-of-meta-and-bytes : a dictionary of meta data & bytes
105
- engine : string, optional
106
- string to indicate the engine {'infer', 'pickle', 'pyarrow'}
107
- 'infer' will pick an engine based upon performance considerations
108
105
109
106
Returns
110
107
-------
111
- DataFrame
108
+ Pandas Object
112
109
113
110
"""
111
+ engine = db ['engine' ]
112
+
114
113
if engine == 'pickle' :
115
- return _read_pickle (db )
114
+ return _read_pickle (db [ 'data' ] )
116
115
try :
117
- return _read_pyarrow (db )
116
+ return _read_pyarrow (db [ 'data' ] )
118
117
except : # pragma
119
- return _read_pickle (db )
118
+ return _read_pickle (db [ 'data' ] )
120
119
121
120
122
121
def _read_pyarrow (db ):
@@ -127,7 +126,4 @@ def _read_pyarrow(db):
127
126
128
127
def _read_pickle (db ):
129
128
""" helper to return via pickle """
130
- from pandas import read_pickle
131
-
132
- db = BytesIO (db )
133
- return read_pickle (db )
129
+ return cPickle .loads (db )
0 commit comments