1- """ support pre 0.12 series pickle compatibility """
2-
3- # flake8: noqa
1+ """
2+ Support pre-0.12 series pickle compatibility.
3+ """
44
55import sys
6- import pandas
6+ import pandas # noqa
77import copy
88import pickle as pkl
99from pandas import compat , Index
10- from pandas .compat import u , string_types
10+ from pandas .compat import u , string_types # noqa
1111
1212
1313def load_reduce (self ):
@@ -16,25 +16,27 @@ def load_reduce(self):
1616 func = stack [- 1 ]
1717
1818 if type (args [0 ]) is type :
19- n = args [0 ].__name__
19+ n = args [0 ].__name__ # noqa
2020
2121 try :
2222 stack [- 1 ] = func (* args )
2323 return
2424 except Exception as e :
2525
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'
2830
29- if '_reconstruct: First argument must be a sub-type of ndarray' in str (e ):
31+ if msg in str (e ):
3032 try :
3133 cls = args [0 ]
3234 stack [- 1 ] = object .__new__ (cls )
3335 return
3436 except :
3537 pass
3638
37- # try to reencode the arguments
39+ # try to re-encode the arguments
3840 if getattr (self , 'encoding' , None ) is not None :
3941 args = tuple ([arg .encode (self .encoding )
4042 if isinstance (arg , string_types )
@@ -45,31 +47,37 @@ def load_reduce(self):
4547 except :
4648 pass
4749
50+ # unknown exception, re-raise
4851 if getattr (self , 'is_verbose' , None ):
4952 print (sys .exc_info ())
5053 print (func , args )
5154 raise
5255
53- stack [- 1 ] = value
5456
55-
56- # if classes are moved, provide compat here
57+ # If classes are moved, provide compat here.
5758_class_locations_map = {
5859
5960 # 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' ),
6265
6366 # 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' ),
6671
6772 # 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' ),
7179 ('pandas._period' , 'Period' ): ('pandas._libs.period' , 'Period' )
72- }
80+ }
7381
7482
7583# our Unpickler sub-class to override methods and some dispatcher
@@ -112,6 +120,8 @@ def load_newobj(self):
112120 obj = cls .__new__ (cls , * args )
113121
114122 self .stack [- 1 ] = obj
123+
124+
115125Unpickler .dispatch [pkl .NEWOBJ [0 ]] = load_newobj
116126
117127
@@ -126,6 +136,8 @@ def load_newobj_ex(self):
126136 else :
127137 obj = cls .__new__ (cls , * args , ** kwargs )
128138 self .append (obj )
139+
140+
129141try :
130142 Unpickler .dispatch [pkl .NEWOBJ_EX [0 ]] = load_newobj_ex
131143except :
0 commit comments