Skip to content

Commit 988cf7e

Browse files
committed
Make pickle_compat.py flake8-able
1 parent 05e067a commit 988cf7e

File tree

1 file changed

+32
-21
lines changed

1 file changed

+32
-21
lines changed

pandas/compat/pickle_compat.py

+32-21
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
""" support pre 0.12 series pickle compatibility """
2-
3-
# flake8: noqa
1+
"""
2+
Support pre-0.12 series pickle compatibility.
3+
"""
44

55
import sys
6-
import pandas
6+
import pandas # noqa
77
import copy
88
import pickle as pkl
99
from pandas import compat, Index
10-
from pandas.compat import u, string_types
10+
from pandas.compat import u, string_types # noqa
1111

1212

1313
def 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)
@@ -50,26 +52,31 @@ def load_reduce(self):
5052
print(func, args)
5153
raise
5254

53-
stack[-1] = value
5455

55-
56-
# if classes are moved, provide compat here
56+
# If classes are moved, provide compat here.
5757
_class_locations_map = {
5858

5959
# 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'),
6264

6365
# 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'),
6670

6771
# 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'),
7178
('pandas._period', 'Period'): ('pandas._libs.period', 'Period')
72-
}
79+
}
7380

7481

7582
# our Unpickler sub-class to override methods and some dispatcher
@@ -112,6 +119,8 @@ def load_newobj(self):
112119
obj = cls.__new__(cls, *args)
113120

114121
self.stack[-1] = obj
122+
123+
115124
Unpickler.dispatch[pkl.NEWOBJ[0]] = load_newobj
116125

117126

@@ -126,6 +135,8 @@ def load_newobj_ex(self):
126135
else:
127136
obj = cls.__new__(cls, *args, **kwargs)
128137
self.append(obj)
138+
139+
129140
try:
130141
Unpickler.dispatch[pkl.NEWOBJ_EX[0]] = load_newobj_ex
131142
except:

0 commit comments

Comments
 (0)