diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 037ab900e6150..c7548ab0ffd4f 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1200,7 +1200,7 @@ def to_sql(self, name, con, flavor=None, schema=None, if_exists='fail', if_exists=if_exists, index=index, index_label=index_label, chunksize=chunksize, dtype=dtype) - def to_pickle(self, path): + def to_pickle(self, path, protocol): """ Pickle (serialize) object to input file path. @@ -1210,7 +1210,7 @@ def to_pickle(self, path): File path """ from pandas.io.pickle import to_pickle - return to_pickle(self, path) + return to_pickle(self, path, protocol) def to_clipboard(self, excel=None, sep=None, **kwargs): """ diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index 2358c296f782e..d65687f08731f 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -6,7 +6,7 @@ from pandas.types.common import is_datetime64_dtype, _NS_DTYPE -def to_pickle(obj, path): +def to_pickle(obj, path, protocol=pkl.HIGHEST_PROTOCOL): """ Pickle (serialize) object to input file path @@ -17,7 +17,7 @@ def to_pickle(obj, path): File path """ with open(path, 'wb') as f: - pkl.dump(obj, f, protocol=pkl.HIGHEST_PROTOCOL) + pkl.dump(obj, f, protocol=protocol) def read_pickle(path):