Skip to content

Commit fc05ab9

Browse files
committed
BUG: compat_pickle should not modify global namespace
1 parent 4f9fefc commit fc05ab9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pandas/compat/pickle_compat.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
import numpy as np
55
import pandas
6+
import copy
67
import pickle as pkl
78
from pandas import compat
89
from pandas.compat import u, string_types
@@ -29,7 +30,7 @@ def load_reduce(self):
2930
except:
3031

3132
# try to reencode the arguments
32-
if self.encoding is not None:
33+
if getattr(self,'encoding',None) is not None:
3334
args = tuple([arg.encode(self.encoding)
3435
if isinstance(arg, string_types)
3536
else arg for arg in args])
@@ -39,7 +40,7 @@ def load_reduce(self):
3940
except:
4041
pass
4142

42-
if self.is_verbose:
43+
if getattr(self,'is_verbose',None):
4344
print(sys.exc_info())
4445
print(func, args)
4546
raise
@@ -53,6 +54,7 @@ class Unpickler(pkl._Unpickler):
5354
class Unpickler(pkl.Unpickler):
5455
pass
5556

57+
Unpickler.dispatch = copy.copy(Unpickler.dispatch)
5658
Unpickler.dispatch[pkl.REDUCE[0]] = load_reduce
5759

5860

0 commit comments

Comments
 (0)