@@ -171,25 +171,22 @@ def read_pickle(
171
171
172
172
# 1) try standard library Pickle
173
173
# 2) try pickle_compat (older pandas version) to handle subclass changes
174
-
175
- excs_to_catch = (AttributeError , ImportError , ModuleNotFoundError )
174
+ # 3) try pickle_compat with latin-1 encoding upon a UnicodeDecodeError
176
175
177
176
try :
178
- with warnings .catch_warnings (record = True ):
179
- # We want to silence any warnings about, e.g. moved modules.
180
- warnings .simplefilter ("ignore" , Warning )
181
- return pickle .load (f )
182
- except excs_to_catch :
183
- # e.g.
184
- # "No module named 'pandas.core.sparse.series'"
185
- # "Can't get attribute '__nat_unpickle' on <module 'pandas._libs.tslib"
177
+ excs_to_catch = (AttributeError , ImportError , ModuleNotFoundError )
186
178
try :
179
+ with warnings .catch_warnings (record = True ):
180
+ # We want to silence any warnings about, e.g. moved modules.
181
+ warnings .simplefilter ("ignore" , Warning )
182
+ return pickle .load (f )
183
+ except excs_to_catch :
184
+ # e.g.
185
+ # "No module named 'pandas.core.sparse.series'"
186
+ # "Can't get attribute '__nat_unpickle' on <module 'pandas._libs.tslib"
187
187
return pc .load (f , encoding = None )
188
- except UnicodeDecodeError :
189
- # e.g. can occur for files written in py27; see GH#28645 and GH#31988
190
- return pc .load (f , encoding = "latin-1" )
191
188
except UnicodeDecodeError :
192
- # e.g. can occur for files written in py27; see GH#28645
189
+ # e.g. can occur for files written in py27; see GH#28645 and GH#31988
193
190
return pc .load (f , encoding = "latin-1" )
194
191
finally :
195
192
f .close ()
0 commit comments