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 )
@@ -45,31 +47,37 @@ def load_reduce(self):
45
47
except :
46
48
pass
47
49
50
+ # unknown exception, re-raise
48
51
if getattr (self , 'is_verbose' , None ):
49
52
print (sys .exc_info ())
50
53
print (func , args )
51
54
raise
52
55
53
- stack [- 1 ] = value
54
56
55
-
56
- # if classes are moved, provide compat here
57
+ # If classes are moved, provide compat here.
57
58
_class_locations_map = {
58
59
59
60
# 15477
60
- ('pandas.core.base' , 'FrozenNDArray' ): ('pandas.indexes.frozen' , 'FrozenNDArray' ),
61
- ('pandas.core.base' , 'FrozenList' ): ('pandas.indexes.frozen' , 'FrozenList' ),
61
+ ('pandas.core.base' , 'FrozenNDArray' ):
62
+ ('pandas.indexes.frozen' , 'FrozenNDArray' ),
63
+ ('pandas.core.base' , 'FrozenList' ):
64
+ ('pandas.indexes.frozen' , 'FrozenList' ),
62
65
63
66
# 10890
64
- ('pandas.core.series' , 'TimeSeries' ): ('pandas.core.series' , 'Series' ),
65
- ('pandas.sparse.series' , 'SparseTimeSeries' ): ('pandas.sparse.series' , 'SparseSeries' ),
67
+ ('pandas.core.series' , 'TimeSeries' ):
68
+ ('pandas.core.series' , 'Series' ),
69
+ ('pandas.sparse.series' , 'SparseTimeSeries' ):
70
+ ('pandas.sparse.series' , 'SparseSeries' ),
66
71
67
72
# 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' ),
73
+ ('pandas._sparse' , 'BlockIndex' ):
74
+ ('pandas.sparse.libsparse' , 'BlockIndex' ),
75
+ ('pandas.tslib' , 'Timestamp' ):
76
+ ('pandas._libs.tslib' , 'Timestamp' ),
77
+ ('pandas.tslib' , '__nat_unpickle' ):
78
+ ('pandas._libs.tslib' , '__nat_unpickle' ),
71
79
('pandas._period' , 'Period' ): ('pandas._libs.period' , 'Period' )
72
- }
80
+ }
73
81
74
82
75
83
# our Unpickler sub-class to override methods and some dispatcher
@@ -112,6 +120,8 @@ def load_newobj(self):
112
120
obj = cls .__new__ (cls , * args )
113
121
114
122
self .stack [- 1 ] = obj
123
+
124
+
115
125
Unpickler .dispatch [pkl .NEWOBJ [0 ]] = load_newobj
116
126
117
127
@@ -126,6 +136,8 @@ def load_newobj_ex(self):
126
136
else :
127
137
obj = cls .__new__ (cls , * args , ** kwargs )
128
138
self .append (obj )
139
+
140
+
129
141
try :
130
142
Unpickler .dispatch [pkl .NEWOBJ_EX [0 ]] = load_newobj_ex
131
143
except :
0 commit comments