1
- """ support pre 0.12 series pickle compatibility """
2
-
3
- # flake8: noqa
1
+ """
2
+ Support pre-0.12 series pickle compatibility.
3
+ """
4
4
5
5
import sys
6
- import pandas
6
+ import pandas # noqa
7
7
import copy
8
8
import pickle as pkl
9
9
from pandas import compat , Index
10
- from pandas .compat import u , string_types
10
+ from pandas .compat import u , string_types # noqa
11
11
12
12
13
13
def load_reduce (self ):
@@ -16,25 +16,27 @@ def load_reduce(self):
16
16
func = stack [- 1 ]
17
17
18
18
if type (args [0 ]) is type :
19
- n = args [0 ].__name__
19
+ n = args [0 ].__name__ # noqa
20
20
21
21
try :
22
22
stack [- 1 ] = func (* args )
23
23
return
24
24
except Exception as e :
25
25
26
- # if we have a deprecated function
27
- # try to replace and try again
26
+ # If we have a deprecated function,
27
+ # try to replace and try again.
28
+
29
+ msg = '_reconstruct: First argument must be a sub-type of ndarray'
28
30
29
- if '_reconstruct: First argument must be a sub-type of ndarray' in str (e ):
31
+ if msg in str (e ):
30
32
try :
31
33
cls = args [0 ]
32
34
stack [- 1 ] = object .__new__ (cls )
33
35
return
34
36
except :
35
37
pass
36
38
37
- # try to reencode the arguments
39
+ # try to re-encode the arguments
38
40
if getattr (self , 'encoding' , None ) is not None :
39
41
args = tuple ([arg .encode (self .encoding )
40
42
if isinstance (arg , string_types )
@@ -50,26 +52,31 @@ def load_reduce(self):
50
52
print (func , args )
51
53
raise
52
54
53
- stack [- 1 ] = value
54
55
55
-
56
- # if classes are moved, provide compat here
56
+ # If classes are moved, provide compat here.
57
57
_class_locations_map = {
58
58
59
59
# 15477
60
- ('pandas.core.base' , 'FrozenNDArray' ): ('pandas.indexes.frozen' , 'FrozenNDArray' ),
61
- ('pandas.core.base' , 'FrozenList' ): ('pandas.indexes.frozen' , 'FrozenList' ),
60
+ ('pandas.core.base' , 'FrozenNDArray' ):
61
+ ('pandas.indexes.frozen' , 'FrozenNDArray' ),
62
+ ('pandas.core.base' , 'FrozenList' ):
63
+ ('pandas.indexes.frozen' , 'FrozenList' ),
62
64
63
65
# 10890
64
- ('pandas.core.series' , 'TimeSeries' ): ('pandas.core.series' , 'Series' ),
65
- ('pandas.sparse.series' , 'SparseTimeSeries' ): ('pandas.sparse.series' , 'SparseSeries' ),
66
+ ('pandas.core.series' , 'TimeSeries' ):
67
+ ('pandas.core.series' , 'Series' ),
68
+ ('pandas.sparse.series' , 'SparseTimeSeries' ):
69
+ ('pandas.sparse.series' , 'SparseSeries' ),
66
70
67
71
# 12588, extensions moving
68
- ('pandas._sparse' , 'BlockIndex' ): ('pandas.sparse.libsparse' , 'BlockIndex' ),
69
- ('pandas.tslib' , 'Timestamp' ): ('pandas._libs.tslib' , 'Timestamp' ),
70
- ('pandas.tslib' , '__nat_unpickle' ): ('pandas._libs.tslib' , '__nat_unpickle' ),
72
+ ('pandas._sparse' , 'BlockIndex' ):
73
+ ('pandas.sparse.libsparse' , 'BlockIndex' ),
74
+ ('pandas.tslib' , 'Timestamp' ):
75
+ ('pandas._libs.tslib' , 'Timestamp' ),
76
+ ('pandas.tslib' , '__nat_unpickle' ):
77
+ ('pandas._libs.tslib' , '__nat_unpickle' ),
71
78
('pandas._period' , 'Period' ): ('pandas._libs.period' , 'Period' )
72
- }
79
+ }
73
80
74
81
75
82
# our Unpickler sub-class to override methods and some dispatcher
@@ -112,6 +119,8 @@ def load_newobj(self):
112
119
obj = cls .__new__ (cls , * args )
113
120
114
121
self .stack [- 1 ] = obj
122
+
123
+
115
124
Unpickler .dispatch [pkl .NEWOBJ [0 ]] = load_newobj
116
125
117
126
@@ -126,6 +135,8 @@ def load_newobj_ex(self):
126
135
else :
127
136
obj = cls .__new__ (cls , * args , ** kwargs )
128
137
self .append (obj )
138
+
139
+
129
140
try :
130
141
Unpickler .dispatch [pkl .NEWOBJ_EX [0 ]] = load_newobj_ex
131
142
except :
0 commit comments