From 3d6ed4a2e70d316a42ff2be5a5d1867468a01194 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sat, 10 Mar 2018 20:27:31 +0000 Subject: [PATCH 01/30] update docstring and add example --- pandas/io/pickle.py | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index 756096dd0c9ce..b5d578cdb6834 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -16,7 +16,7 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): ---------- obj : any object path : string - File path + File path where the pickled pandas object will be stored. compression : {'infer', 'gzip', 'bz2', 'xz', None}, default 'infer' a string representing the compression to use in the output file @@ -33,7 +33,25 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): .. [1] https://docs.python.org/3/library/pickle.html .. versionadded:: 0.21.0 - + Examples + -------- + >>> original_df = DataFrame({"foo": range(5), "bar": range(5, 10)}) + >>> original_df + bar foo + 0 5 0 + 1 6 1 + 2 7 2 + 3 8 3 + 4 9 4 + >>> original_df.to_pickle("./dummy.pkl") + >>> unpickled_df = read_pickle("./dummy.pkl") + >>> unpickled_df + bar foo + 0 5 0 + 1 6 1 + 2 7 2 + 3 8 3 + 4 9 4 """ path = _stringify_path(path) inferred_compression = _infer_compression(path, compression) @@ -60,7 +78,7 @@ def read_pickle(path, compression='infer'): Parameters ---------- path : string - File path + File path where the pickled object will be loaded. compression : {'infer', 'gzip', 'bz2', 'xz', 'zip', None}, default 'infer' For on-the-fly decompression of on-disk data. If 'infer', then use gzip, bz2, xz or zip if path ends in '.gz', '.bz2', '.xz', @@ -72,6 +90,26 @@ def read_pickle(path, compression='infer'): Returns ------- unpickled : type of object stored in file + + Examples + -------- + >>> original_df = DataFrame({"foo": range(5), "bar": range(5, 10)}) + >>> original_df + bar foo + 0 5 0 + 1 6 1 + 2 7 2 + 3 8 3 + 4 9 4 + >>> original_df.to_pickle("./dummy.pkl") + >>> unpickled_df = read_pickle("./dummy.pkl") + >>> unpickled_df + bar foo + 0 5 0 + 1 6 1 + 2 7 2 + 3 8 3 + 4 9 4 """ path = _stringify_path(path) inferred_compression = _infer_compression(path, compression) From 62a202f82e489fbbaf06a3125624fbafc9e85d87 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sat, 10 Mar 2018 21:10:51 +0000 Subject: [PATCH 02/30] update docstring and add example --- pandas/core/generic.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 9f2112729a503..095ee4d8314c3 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1906,7 +1906,7 @@ def to_pickle(self, path, compression='infer', Parameters ---------- path : string - File path + File path where the pickled pandas object will be stored. compression : {'infer', 'gzip', 'bz2', 'xz', None}, default 'infer' a string representing the compression to use in the output file @@ -1923,6 +1923,25 @@ def to_pickle(self, path, compression='infer', .. [1] https://docs.python.org/3/library/pickle.html .. versionadded:: 0.21.0 + Examples + -------- + >>> original_df = DataFrame({"foo": range(5), "bar": range(5, 10)}) + >>> original_df + bar foo + 0 5 0 + 1 6 1 + 2 7 2 + 3 8 3 + 4 9 4 + >>> original_df.to_pickle("./dummy.pkl") + >>> unpickled_df = read_pickle("./dummy.pkl") + >>> unpickled_df + bar foo + 0 5 0 + 1 6 1 + 2 7 2 + 3 8 3 + 4 9 4 """ from pandas.io.pickle import to_pickle return to_pickle(self, path, compression=compression, From 03fa85b2d3df568be09f39f0a2806399f55e9db4 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sat, 10 Mar 2018 21:41:16 +0000 Subject: [PATCH 03/30] add space --- pandas/io/pickle.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index b5d578cdb6834..1eddd619c726b 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -44,6 +44,7 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): 3 8 3 4 9 4 >>> original_df.to_pickle("./dummy.pkl") + >>> unpickled_df = read_pickle("./dummy.pkl") >>> unpickled_df bar foo @@ -102,6 +103,7 @@ def read_pickle(path, compression='infer'): 3 8 3 4 9 4 >>> original_df.to_pickle("./dummy.pkl") + >>> unpickled_df = read_pickle("./dummy.pkl") >>> unpickled_df bar foo From 3169811d5a9b72e816948466db7384f2e5d96142 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sat, 10 Mar 2018 21:43:18 +0000 Subject: [PATCH 04/30] DataFrame.to_pickle docstring --- pandas/core/frame.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index a66d00fff9714..d62e7738f7b6d 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -78,7 +78,7 @@ from pandas.compat import (range, map, zip, lrange, lmap, lzip, StringIO, u, OrderedDict, raise_with_traceback) from pandas import compat -from pandas.compat import PY36 +from pandas.compat import PY36, cPickle as pkl from pandas.compat.numpy import function as nv from pandas.util._decorators import (Appender, Substitution, rewrite_axis_style_signature) @@ -1602,6 +1602,12 @@ def to_excel(self, excel_writer, sheet_name='Sheet1', na_rep='', startcol=startcol, freeze_panes=freeze_panes, engine=engine) + @Appender(_shared_docs['to_pickle'] % _shared_doc_kwargs) + def to_pickle(self, path, compression='infer', + protocol=pkl.HIGHEST_PROTOCOL): + return super(DataFrame, self).to_pickle(path, compression=compression, + protocol=protocol) + def to_stata(self, fname, convert_dates=None, write_index=True, encoding="latin-1", byteorder=None, time_stamp=None, data_label=None, variable_labels=None): From d014e9742d0956f6280544d50cb87c13d4e3d75b Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sat, 10 Mar 2018 21:44:14 +0000 Subject: [PATCH 05/30] Series.to_pickle docstring --- pandas/core/series.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 069f0372ab6e1..d10cc8aabc6d7 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -54,7 +54,8 @@ from pandas import compat from pandas.io.formats.terminal import get_terminal_size from pandas.compat import ( - zip, u, OrderedDict, StringIO, range, get_range_parameters, PY36) + zip, u, OrderedDict, StringIO, range, get_range_parameters, PY36, + cPickle as pkl) from pandas.compat.numpy import function as nv import pandas.core.ops as ops @@ -2952,6 +2953,12 @@ def to_excel(self, excel_writer, sheet_name='Sheet1', na_rep='', merge_cells=merge_cells, encoding=encoding, inf_rep=inf_rep, verbose=verbose) + @Appender(generic._shared_docs['to_pickle'] % _shared_doc_kwargs) + def to_pickle(self, path, compression='infer', + protocol=pkl.HIGHEST_PROTOCOL): + return super(Series, self).to_pickle(path, compression=compression, + protocol=protocol) + @Appender(generic._shared_docs['isna'] % _shared_doc_kwargs) def isna(self): return super(Series, self).isna() From 202f411a0a0a6fae9e280f3d3c31e1cdb5843166 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sat, 10 Mar 2018 21:46:16 +0000 Subject: [PATCH 06/30] add to_pickle to _shared_docs --- pandas/core/generic.py | 88 +++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 095ee4d8314c3..c5bf335afc7e2 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1652,6 +1652,51 @@ def _repr_latex_(self): strings before writing. """ + _shared_docs['to_pickle'] = """ + Pickle (serialize) %(klass)s object to input file path. + + Parameters + ---------- + path : string + File path where the pickled %(klass)s object will be stored. + compression : {'infer', 'gzip', 'bz2', 'xz', None}, default 'infer' + a string representing the compression to use in the output file + + .. versionadded:: 0.20.0 + protocol : int + Int which indicates which protocol should be used by the pickler, + default HIGHEST_PROTOCOL (see [1], paragraph 12.1.2). The possible + values for this parameter depend on the version of Python. For + Python 2.x, possible values are 0, 1, 2. For Python>=3.0, 3 is a + valid value. For Python >= 3.4, 4 is a valid value.A negative value + for the protocol parameter is equivalent to setting its value to + HIGHEST_PROTOCOL. + + .. [1] https://docs.python.org/3/library/pickle.html + .. versionadded:: 0.21.0 + + Examples + -------- + >>> original_df = DataFrame({"foo": range(5), "bar": range(5, 10)}) + >>> original_df + bar foo + 0 5 0 + 1 6 1 + 2 7 2 + 3 8 3 + 4 9 4 + >>> original_df.to_pickle("./dummy.pkl") + + >>> unpickled_df = read_pickle("./dummy.pkl") + >>> unpickled_df + bar foo + 0 5 0 + 1 6 1 + 2 7 2 + 3 8 3 + 4 9 4 + """ + def to_json(self, path_or_buf=None, orient=None, date_format=None, double_precision=10, force_ascii=True, date_unit='ms', default_handler=None, lines=False, compression=None, @@ -1900,49 +1945,6 @@ def to_sql(self, name, con, schema=None, if_exists='fail', index=True, def to_pickle(self, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): - """ - Pickle (serialize) object to input file path. - - Parameters - ---------- - path : string - File path where the pickled pandas object will be stored. - compression : {'infer', 'gzip', 'bz2', 'xz', None}, default 'infer' - a string representing the compression to use in the output file - - .. versionadded:: 0.20.0 - protocol : int - Int which indicates which protocol should be used by the pickler, - default HIGHEST_PROTOCOL (see [1], paragraph 12.1.2). The possible - values for this parameter depend on the version of Python. For - Python 2.x, possible values are 0, 1, 2. For Python>=3.0, 3 is a - valid value. For Python >= 3.4, 4 is a valid value.A negative value - for the protocol parameter is equivalent to setting its value to - HIGHEST_PROTOCOL. - - .. [1] https://docs.python.org/3/library/pickle.html - .. versionadded:: 0.21.0 - - Examples - -------- - >>> original_df = DataFrame({"foo": range(5), "bar": range(5, 10)}) - >>> original_df - bar foo - 0 5 0 - 1 6 1 - 2 7 2 - 3 8 3 - 4 9 4 - >>> original_df.to_pickle("./dummy.pkl") - >>> unpickled_df = read_pickle("./dummy.pkl") - >>> unpickled_df - bar foo - 0 5 0 - 1 6 1 - 2 7 2 - 3 8 3 - 4 9 4 - """ from pandas.io.pickle import to_pickle return to_pickle(self, path, compression=compression, protocol=protocol) From 05e1bce8a4d0d02caf1ee448e15901cbbe2d83ae Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sat, 10 Mar 2018 21:48:33 +0000 Subject: [PATCH 07/30] move quote --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index c5bf335afc7e2..5b7885ac4d425 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1695,7 +1695,7 @@ def _repr_latex_(self): 2 7 2 3 8 3 4 9 4 - """ + """ def to_json(self, path_or_buf=None, orient=None, date_format=None, double_precision=10, force_ascii=True, date_unit='ms', From f674845451360a5247915297323ba0cb6bc352ac Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sat, 10 Mar 2018 21:49:55 +0000 Subject: [PATCH 08/30] remove blank line --- pandas/io/pickle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index 1eddd619c726b..9b118a0574f4b 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -103,7 +103,7 @@ def read_pickle(path, compression='infer'): 3 8 3 4 9 4 >>> original_df.to_pickle("./dummy.pkl") - + >>> unpickled_df = read_pickle("./dummy.pkl") >>> unpickled_df bar foo From 556adf4703ff5e2f3f52a2c712cc36a09064b457 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sat, 10 Mar 2018 22:15:24 +0000 Subject: [PATCH 09/30] miscellaneous fixes --- pandas/core/generic.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 5b7885ac4d425..fdfb51ef5d85f 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1660,7 +1660,7 @@ def _repr_latex_(self): path : string File path where the pickled %(klass)s object will be stored. compression : {'infer', 'gzip', 'bz2', 'xz', None}, default 'infer' - a string representing the compression to use in the output file + A string representing the compression to use in the output file. .. versionadded:: 0.20.0 protocol : int @@ -1677,24 +1677,25 @@ def _repr_latex_(self): Examples -------- + >>> from pandas import DataFrame, read_pickle >>> original_df = DataFrame({"foo": range(5), "bar": range(5, 10)}) >>> original_df - bar foo - 0 5 0 - 1 6 1 - 2 7 2 - 3 8 3 - 4 9 4 + foo bar + 0 0 5 + 1 1 6 + 2 2 7 + 3 3 8 + 4 4 9 >>> original_df.to_pickle("./dummy.pkl") >>> unpickled_df = read_pickle("./dummy.pkl") >>> unpickled_df - bar foo - 0 5 0 - 1 6 1 - 2 7 2 - 3 8 3 - 4 9 4 + foo bar + 0 0 5 + 1 1 6 + 2 2 7 + 3 3 8 + 4 4 9 """ def to_json(self, path_or_buf=None, orient=None, date_format=None, From 42fcc036acd4491b6e0cbcd4c64b088e11b44a66 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sat, 10 Mar 2018 22:16:04 +0000 Subject: [PATCH 10/30] miscellaneous fixes --- pandas/io/pickle.py | 57 ++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index 9b118a0574f4b..5fa2f6f67e9f7 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -10,15 +10,16 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): """ - Pickle (serialize) object to input file path + Pickle (serialize) object to input file path. Parameters ---------- obj : any object + Any python object. path : string File path where the pickled pandas object will be stored. compression : {'infer', 'gzip', 'bz2', 'xz', None}, default 'infer' - a string representing the compression to use in the output file + A string representing the compression to use in the output file. .. versionadded:: 0.20.0 protocol : int @@ -35,24 +36,25 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): Examples -------- + >>> from pandas import DataFrame, read_pickle >>> original_df = DataFrame({"foo": range(5), "bar": range(5, 10)}) >>> original_df - bar foo - 0 5 0 - 1 6 1 - 2 7 2 - 3 8 3 - 4 9 4 + foo bar + 0 0 5 + 1 1 6 + 2 2 7 + 3 3 8 + 4 4 9 >>> original_df.to_pickle("./dummy.pkl") >>> unpickled_df = read_pickle("./dummy.pkl") >>> unpickled_df - bar foo - 0 5 0 - 1 6 1 - 2 7 2 - 3 8 3 - 4 9 4 + foo bar + 0 0 5 + 1 1 6 + 2 2 7 + 3 3 8 + 4 4 9 """ path = _stringify_path(path) inferred_compression = _infer_compression(path, compression) @@ -71,7 +73,7 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): def read_pickle(path, compression='infer'): """ Load pickled pandas object (or any other pickled object) from the specified - file path + file path. Warning: Loading pickled data received from untrusted sources can be unsafe. See: https://docs.python.org/3/library/pickle.html @@ -94,24 +96,25 @@ def read_pickle(path, compression='infer'): Examples -------- + >>> from pandas import DataFrame, read_pickle >>> original_df = DataFrame({"foo": range(5), "bar": range(5, 10)}) >>> original_df - bar foo - 0 5 0 - 1 6 1 - 2 7 2 - 3 8 3 - 4 9 4 + foo bar + 0 0 5 + 1 1 6 + 2 2 7 + 3 3 8 + 4 4 9 >>> original_df.to_pickle("./dummy.pkl") >>> unpickled_df = read_pickle("./dummy.pkl") >>> unpickled_df - bar foo - 0 5 0 - 1 6 1 - 2 7 2 - 3 8 3 - 4 9 4 + foo bar + 0 0 5 + 1 1 6 + 2 2 7 + 3 3 8 + 4 4 9 """ path = _stringify_path(path) inferred_compression = _infer_compression(path, compression) From e69ea5ce6bc3ccf2269fbfacb026fce9b38fddb4 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sat, 10 Mar 2018 23:00:14 +0000 Subject: [PATCH 11/30] remove import and add See Also --- pandas/core/generic.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index fdfb51ef5d85f..aa6c17e107ea7 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1677,8 +1677,7 @@ def _repr_latex_(self): Examples -------- - >>> from pandas import DataFrame, read_pickle - >>> original_df = DataFrame({"foo": range(5), "bar": range(5, 10)}) + >>> original_df = pd.DataFrame({"foo": range(5), "bar": range(5, 10)}) >>> original_df foo bar 0 0 5 @@ -1688,7 +1687,7 @@ def _repr_latex_(self): 4 4 9 >>> original_df.to_pickle("./dummy.pkl") - >>> unpickled_df = read_pickle("./dummy.pkl") + >>> unpickled_df = pd.read_pickle("./dummy.pkl") >>> unpickled_df foo bar 0 0 5 @@ -1696,6 +1695,10 @@ def _repr_latex_(self): 2 2 7 3 3 8 4 4 9 + + See Also + -------- + pandas.read_pickle """ def to_json(self, path_or_buf=None, orient=None, date_format=None, From f36c6ddf2b4c94cd50dae0f29f9a601dd41161ae Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sat, 10 Mar 2018 23:00:58 +0000 Subject: [PATCH 12/30] remove import and add See Also --- pandas/io/pickle.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index 5fa2f6f67e9f7..daa3ca913c4b4 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -17,7 +17,7 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): obj : any object Any python object. path : string - File path where the pickled pandas object will be stored. + File path where the pickled object will be stored. compression : {'infer', 'gzip', 'bz2', 'xz', None}, default 'infer' A string representing the compression to use in the output file. @@ -36,8 +36,7 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): Examples -------- - >>> from pandas import DataFrame, read_pickle - >>> original_df = DataFrame({"foo": range(5), "bar": range(5, 10)}) + >>> original_df = pd.DataFrame({"foo": range(5), "bar": range(5, 10)}) >>> original_df foo bar 0 0 5 @@ -45,9 +44,9 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): 2 2 7 3 3 8 4 4 9 - >>> original_df.to_pickle("./dummy.pkl") + >>> pd.to_pickle(original_df, "./dummy.pkl") - >>> unpickled_df = read_pickle("./dummy.pkl") + >>> unpickled_df = pd.read_pickle("./dummy.pkl") >>> unpickled_df foo bar 0 0 5 @@ -55,6 +54,13 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): 2 2 7 3 3 8 4 4 9 + + See Also + -------- + pandas.read_pickle + pandas.to_hdf + pandas.to_sql + pandas.to_parquet """ path = _stringify_path(path) inferred_compression = _infer_compression(path, compression) @@ -96,8 +102,7 @@ def read_pickle(path, compression='infer'): Examples -------- - >>> from pandas import DataFrame, read_pickle - >>> original_df = DataFrame({"foo": range(5), "bar": range(5, 10)}) + >>> original_df = pd.DataFrame({"foo": range(5), "bar": range(5, 10)}) >>> original_df foo bar 0 0 5 @@ -105,9 +110,9 @@ def read_pickle(path, compression='infer'): 2 2 7 3 3 8 4 4 9 - >>> original_df.to_pickle("./dummy.pkl") + >>> pd.to_pickle(original_df, "./dummy.pkl") - >>> unpickled_df = read_pickle("./dummy.pkl") + >>> unpickled_df = pd.read_pickle("./dummy.pkl") >>> unpickled_df foo bar 0 0 5 @@ -115,6 +120,13 @@ def read_pickle(path, compression='infer'): 2 2 7 3 3 8 4 4 9 + + See Also + -------- + pandas.to_pickle, + pandas.read_hdf, + pandas.read_sql, + pandas.read_parquet """ path = _stringify_path(path) inferred_compression = _infer_compression(path, compression) From 5f152ed7576df6b82294265b3caa325d9e52af40 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sat, 10 Mar 2018 23:05:22 +0000 Subject: [PATCH 13/30] add more See Also --- pandas/io/pickle.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index daa3ca913c4b4..57946158fc275 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -124,6 +124,8 @@ def read_pickle(path, compression='infer'): See Also -------- pandas.to_pickle, + pandas.DataFrame.to_pickle + pandas.Series.to_pickle pandas.read_hdf, pandas.read_sql, pandas.read_parquet From c6231b0a4a2a2248aa6351538cea686df0952d13 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sun, 11 Mar 2018 00:01:08 +0000 Subject: [PATCH 14/30] use proper warning with embedded hyperlink --- pandas/io/pickle.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index 57946158fc275..43a3fbba5b9dd 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -81,8 +81,10 @@ def read_pickle(path, compression='infer'): Load pickled pandas object (or any other pickled object) from the specified file path. - Warning: Loading pickled data received from untrusted sources can be - unsafe. See: https://docs.python.org/3/library/pickle.html + .. warning:: + + Loading pickled data received from untrusted sources can be + unsafe. See `here `__. Parameters ---------- From 0c3a442c85aa02ae84d0b265b978251898f7fb76 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sun, 11 Mar 2018 01:05:14 +0000 Subject: [PATCH 15/30] remove pandas.to_pickle from See Also --- pandas/io/pickle.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index 43a3fbba5b9dd..982612dee9981 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -125,7 +125,6 @@ def read_pickle(path, compression='infer'): See Also -------- - pandas.to_pickle, pandas.DataFrame.to_pickle pandas.Series.to_pickle pandas.read_hdf, From 709ca74fc01435f002afecb8d0f20adc5ecfcbb9 Mon Sep 17 00:00:00 2001 From: minggli Date: Sun, 11 Mar 2018 13:31:17 +0000 Subject: [PATCH 16/30] remove commas in See Also --- pandas/io/pickle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index 982612dee9981..ed7d044df6f69 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -127,8 +127,8 @@ def read_pickle(path, compression='infer'): -------- pandas.DataFrame.to_pickle pandas.Series.to_pickle - pandas.read_hdf, - pandas.read_sql, + pandas.read_hdf + pandas.read_sql pandas.read_parquet """ path = _stringify_path(path) From c15d454757e50431675a2f37920265bcd6dd4158 Mon Sep 17 00:00:00 2001 From: minggli Date: Sun, 11 Mar 2018 13:50:04 +0000 Subject: [PATCH 17/30] additional output in See Also --- pandas/core/generic.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index aa6c17e107ea7..1732e58393b9c 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1699,6 +1699,9 @@ def _repr_latex_(self): See Also -------- pandas.read_pickle + pandas.to_hdf + pandas.to_sql + pandas.to_parquet """ def to_json(self, path_or_buf=None, orient=None, date_format=None, From b3d9ceebc9d76a0408ef7ae1eab4380cb5c01325 Mon Sep 17 00:00:00 2001 From: minggli Date: Sun, 11 Mar 2018 14:11:01 +0000 Subject: [PATCH 18/30] add descriptions in See Also references --- pandas/core/generic.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 1732e58393b9c..7ed0949a207b1 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1698,10 +1698,11 @@ def _repr_latex_(self): See Also -------- - pandas.read_pickle - pandas.to_hdf - pandas.to_sql - pandas.to_parquet + pandas.read_pickle : Load pickled pandas object (or any other pickled + object) from the specified file path. + pandas.to_hdf : Write the contained data to an HDF5 file using HDFStore. + pandas.to_sql : Write records stored in a DataFrame to a SQL database. + pandas.to_parquet : Write a DataFrame to the binary parquet format. """ def to_json(self, path_or_buf=None, orient=None, date_format=None, From ef19c93fa3251cf3bc7fd3bf21a4018c889b33c3 Mon Sep 17 00:00:00 2001 From: minggli Date: Sun, 11 Mar 2018 14:11:52 +0000 Subject: [PATCH 19/30] add descriptions in See Also references --- pandas/io/pickle.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index ed7d044df6f69..81cbecc55eb93 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -57,10 +57,11 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): See Also -------- - pandas.read_pickle - pandas.to_hdf - pandas.to_sql - pandas.to_parquet + pandas.read_pickle : Load pickled pandas object (or any other pickled + object) from the specified file path. + pandas.to_hdf : Write the contained data to an HDF5 file using HDFStore. + pandas.to_sql : Write records stored in a DataFrame to a SQL database. + pandas.to_parquet : Write a DataFrame to the binary parquet format. """ path = _stringify_path(path) inferred_compression = _infer_compression(path, compression) @@ -125,11 +126,14 @@ def read_pickle(path, compression='infer'): See Also -------- - pandas.DataFrame.to_pickle - pandas.Series.to_pickle - pandas.read_hdf - pandas.read_sql - pandas.read_parquet + pandas.DataFrame.to_pickle : Pickle (serialize) DataFrame object to input + file path. + pandas.Series.to_pickle : Pickle (serialize) Series object to input + file path. + pandas.read_hdf : read from the store, close it if we opened it. + pandas.read_sql : Read SQL query or database table into a DataFrame. + pandas.read_parquet : Load a parquet object from the file path, returning + a DataFrame. """ path = _stringify_path(path) inferred_compression = _infer_compression(path, compression) From 33a9b1f64b17bb2efeec6f042165d46091dcf9bf Mon Sep 17 00:00:00 2001 From: minggli Date: Sun, 11 Mar 2018 15:23:40 +0000 Subject: [PATCH 20/30] correct references and indentation --- pandas/core/generic.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 7ed0949a207b1..c5dbeb37aba81 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1699,10 +1699,13 @@ def _repr_latex_(self): See Also -------- pandas.read_pickle : Load pickled pandas object (or any other pickled - object) from the specified file path. - pandas.to_hdf : Write the contained data to an HDF5 file using HDFStore. - pandas.to_sql : Write records stored in a DataFrame to a SQL database. - pandas.to_parquet : Write a DataFrame to the binary parquet format. + object) from the specified file path. + pandas.DataFrame.to_hdf : Write the contained data to an HDF5 file using + HDFStore. + pandas.DataFrame.to_sql : Write records stored in a DataFrame to a SQL + database. + pandas.DataFrame.to_parquet : Write a DataFrame to the binary parquet + format. """ def to_json(self, path_or_buf=None, orient=None, date_format=None, From 7be8f3b8e08803d254f82beb52f0885ad2b8a269 Mon Sep 17 00:00:00 2001 From: minggli Date: Sun, 11 Mar 2018 15:24:07 +0000 Subject: [PATCH 21/30] correct indentation --- pandas/io/pickle.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index 81cbecc55eb93..cad917cdde567 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -58,10 +58,13 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): See Also -------- pandas.read_pickle : Load pickled pandas object (or any other pickled - object) from the specified file path. - pandas.to_hdf : Write the contained data to an HDF5 file using HDFStore. - pandas.to_sql : Write records stored in a DataFrame to a SQL database. - pandas.to_parquet : Write a DataFrame to the binary parquet format. + object) from the specified file path. + pandas.DataFrame.to_hdf : Write the contained data to an HDF5 file using + HDFStore. + pandas.DataFrame.to_sql : Write records stored in a DataFrame to a SQL + database. + pandas.DataFrame.to_parquet : Write a DataFrame to the binary parquet + format. """ path = _stringify_path(path) inferred_compression = _infer_compression(path, compression) @@ -127,13 +130,13 @@ def read_pickle(path, compression='infer'): See Also -------- pandas.DataFrame.to_pickle : Pickle (serialize) DataFrame object to input - file path. + file path. pandas.Series.to_pickle : Pickle (serialize) Series object to input - file path. + file path. pandas.read_hdf : read from the store, close it if we opened it. pandas.read_sql : Read SQL query or database table into a DataFrame. pandas.read_parquet : Load a parquet object from the file path, returning - a DataFrame. + a DataFrame. """ path = _stringify_path(path) inferred_compression = _infer_compression(path, compression) From d69c73f281cfaeb51d19be5024e0c7fb45a210f4 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Mon, 12 Mar 2018 21:26:50 +0000 Subject: [PATCH 22/30] revert frame --- pandas/core/frame.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index d62e7738f7b6d..a66d00fff9714 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -78,7 +78,7 @@ from pandas.compat import (range, map, zip, lrange, lmap, lzip, StringIO, u, OrderedDict, raise_with_traceback) from pandas import compat -from pandas.compat import PY36, cPickle as pkl +from pandas.compat import PY36 from pandas.compat.numpy import function as nv from pandas.util._decorators import (Appender, Substitution, rewrite_axis_style_signature) @@ -1602,12 +1602,6 @@ def to_excel(self, excel_writer, sheet_name='Sheet1', na_rep='', startcol=startcol, freeze_panes=freeze_panes, engine=engine) - @Appender(_shared_docs['to_pickle'] % _shared_doc_kwargs) - def to_pickle(self, path, compression='infer', - protocol=pkl.HIGHEST_PROTOCOL): - return super(DataFrame, self).to_pickle(path, compression=compression, - protocol=protocol) - def to_stata(self, fname, convert_dates=None, write_index=True, encoding="latin-1", byteorder=None, time_stamp=None, data_label=None, variable_labels=None): From e2af5a30da13dab13c064d6fc1672e9a152375d9 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Mon, 12 Mar 2018 21:27:28 +0000 Subject: [PATCH 23/30] revert series --- pandas/core/series.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index d10cc8aabc6d7..069f0372ab6e1 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -54,8 +54,7 @@ from pandas import compat from pandas.io.formats.terminal import get_terminal_size from pandas.compat import ( - zip, u, OrderedDict, StringIO, range, get_range_parameters, PY36, - cPickle as pkl) + zip, u, OrderedDict, StringIO, range, get_range_parameters, PY36) from pandas.compat.numpy import function as nv import pandas.core.ops as ops @@ -2953,12 +2952,6 @@ def to_excel(self, excel_writer, sheet_name='Sheet1', na_rep='', merge_cells=merge_cells, encoding=encoding, inf_rep=inf_rep, verbose=verbose) - @Appender(generic._shared_docs['to_pickle'] % _shared_doc_kwargs) - def to_pickle(self, path, compression='infer', - protocol=pkl.HIGHEST_PROTOCOL): - return super(Series, self).to_pickle(path, compression=compression, - protocol=protocol) - @Appender(generic._shared_docs['isna'] % _shared_doc_kwargs) def isna(self): return super(Series, self).isna() From 46b73426d41429b555ceefe9914fad5799c2c3cd Mon Sep 17 00:00:00 2001 From: Ming Li Date: Mon, 12 Mar 2018 21:31:15 +0000 Subject: [PATCH 24/30] remove shared_doc, pandas. and add infer description --- pandas/core/generic.py | 111 ++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 56 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index c5dbeb37aba81..eab4545e398cf 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1652,62 +1652,6 @@ def _repr_latex_(self): strings before writing. """ - _shared_docs['to_pickle'] = """ - Pickle (serialize) %(klass)s object to input file path. - - Parameters - ---------- - path : string - File path where the pickled %(klass)s object will be stored. - compression : {'infer', 'gzip', 'bz2', 'xz', None}, default 'infer' - A string representing the compression to use in the output file. - - .. versionadded:: 0.20.0 - protocol : int - Int which indicates which protocol should be used by the pickler, - default HIGHEST_PROTOCOL (see [1], paragraph 12.1.2). The possible - values for this parameter depend on the version of Python. For - Python 2.x, possible values are 0, 1, 2. For Python>=3.0, 3 is a - valid value. For Python >= 3.4, 4 is a valid value.A negative value - for the protocol parameter is equivalent to setting its value to - HIGHEST_PROTOCOL. - - .. [1] https://docs.python.org/3/library/pickle.html - .. versionadded:: 0.21.0 - - Examples - -------- - >>> original_df = pd.DataFrame({"foo": range(5), "bar": range(5, 10)}) - >>> original_df - foo bar - 0 0 5 - 1 1 6 - 2 2 7 - 3 3 8 - 4 4 9 - >>> original_df.to_pickle("./dummy.pkl") - - >>> unpickled_df = pd.read_pickle("./dummy.pkl") - >>> unpickled_df - foo bar - 0 0 5 - 1 1 6 - 2 2 7 - 3 3 8 - 4 4 9 - - See Also - -------- - pandas.read_pickle : Load pickled pandas object (or any other pickled - object) from the specified file path. - pandas.DataFrame.to_hdf : Write the contained data to an HDF5 file using - HDFStore. - pandas.DataFrame.to_sql : Write records stored in a DataFrame to a SQL - database. - pandas.DataFrame.to_parquet : Write a DataFrame to the binary parquet - format. - """ - def to_json(self, path_or_buf=None, orient=None, date_format=None, double_precision=10, force_ascii=True, date_unit='ms', default_handler=None, lines=False, compression=None, @@ -1956,6 +1900,61 @@ def to_sql(self, name, con, schema=None, if_exists='fail', index=True, def to_pickle(self, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): + """ + Pickle (serialize) object to input file path. + + Parameters + ---------- + path : string + File path where the pickled object will be stored. + compression : {'infer', 'gzip', 'bz2', 'xz', None}, default 'infer' + A string representing the compression to use in the output file. By + default, infers from the specified path. + + .. versionadded:: 0.20.0 + protocol : int + Int which indicates which protocol should be used by the pickler, + default HIGHEST_PROTOCOL (see [1], paragraph 12.1.2). The possible + values for this parameter depend on the version of Python. For + Python 2.x, possible values are 0, 1, 2. For Python>=3.0, 3 is a + valid value. For Python >= 3.4, 4 is a valid value. A negative + value for the protocol parameter is equivalent to setting its value + to HIGHEST_PROTOCOL. + + .. [1] https://docs.python.org/3/library/pickle.html + .. versionadded:: 0.21.0 + + Examples + -------- + >>> original_df = pd.DataFrame({"foo": range(5), "bar": range(5, 10)}) + >>> original_df + foo bar + 0 0 5 + 1 1 6 + 2 2 7 + 3 3 8 + 4 4 9 + >>> original_df.to_pickle("./dummy.pkl") + + >>> unpickled_df = pd.read_pickle("./dummy.pkl") + >>> unpickled_df + foo bar + 0 0 5 + 1 1 6 + 2 2 7 + 3 3 8 + 4 4 9 + + See Also + -------- + read_pickle : Load pickled pandas object (or any other pickled object) + from the specified file path. + DataFrame.to_hdf : Write the contained data to an HDF5 file using + HDFStore. + DataFrame.to_sql : Write records stored in a DataFrame to a SQL + database. + DataFrame.to_parquet : Write a DataFrame to the binary parquet format. + """ from pandas.io.pickle import to_pickle return to_pickle(self, path, compression=compression, protocol=protocol) From 7f1d3d4711bd2f8146d03c6e34d82f1e3aef33e5 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Mon, 12 Mar 2018 21:34:57 +0000 Subject: [PATCH 25/30] remove pandas. and add infer description --- pandas/io/pickle.py | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index cad917cdde567..37d970ca6b009 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -19,7 +19,8 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): path : string File path where the pickled object will be stored. compression : {'infer', 'gzip', 'bz2', 'xz', None}, default 'infer' - A string representing the compression to use in the output file. + A string representing the compression to use in the output file. By + default, infers from the specified path. .. versionadded:: 0.20.0 protocol : int @@ -57,14 +58,11 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): See Also -------- - pandas.read_pickle : Load pickled pandas object (or any other pickled - object) from the specified file path. - pandas.DataFrame.to_hdf : Write the contained data to an HDF5 file using - HDFStore. - pandas.DataFrame.to_sql : Write records stored in a DataFrame to a SQL - database. - pandas.DataFrame.to_parquet : Write a DataFrame to the binary parquet - format. + read_pickle : Load pickled pandas object (or any other pickled object) from + the specified file path. + DataFrame.to_hdf : Write the contained data to an HDF5 file using HDFStore. + DataFrame.to_sql : Write records stored in a DataFrame to a SQL database. + DataFrame.to_parquet : Write a DataFrame to the binary parquet format. """ path = _stringify_path(path) inferred_compression = _infer_compression(path, compression) @@ -129,14 +127,13 @@ def read_pickle(path, compression='infer'): See Also -------- - pandas.DataFrame.to_pickle : Pickle (serialize) DataFrame object to input - file path. - pandas.Series.to_pickle : Pickle (serialize) Series object to input - file path. - pandas.read_hdf : read from the store, close it if we opened it. - pandas.read_sql : Read SQL query or database table into a DataFrame. - pandas.read_parquet : Load a parquet object from the file path, returning - a DataFrame. + DataFrame.to_pickle : Pickle (serialize) DataFrame object to input file + path. + Series.to_pickle : Pickle (serialize) Series object to input file path. + read_hdf : read from the store, close it if we opened it. + read_sql : Read SQL query or database table into a DataFrame. + read_parquet : Load a parquet object from the file path, returning a + DataFrame. """ path = _stringify_path(path) inferred_compression = _infer_compression(path, compression) From 3e545f38e32154aadf31488e5b78adab9b24b28f Mon Sep 17 00:00:00 2001 From: minggli Date: Tue, 13 Mar 2018 18:46:50 +0000 Subject: [PATCH 26/30] miscellaneous changes --- pandas/core/generic.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index eab4545e398cf..ee06a638ce894 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1905,11 +1905,11 @@ def to_pickle(self, path, compression='infer', Parameters ---------- - path : string + path : str File path where the pickled object will be stored. compression : {'infer', 'gzip', 'bz2', 'xz', None}, default 'infer' A string representing the compression to use in the output file. By - default, infers from the specified path. + default, infers from the file extension in specified path. .. versionadded:: 0.20.0 protocol : int @@ -1924,6 +1924,15 @@ def to_pickle(self, path, compression='infer', .. [1] https://docs.python.org/3/library/pickle.html .. versionadded:: 0.21.0 + See Also + -------- + read_pickle : Load pickled pandas object (or any object) from file. + DataFrame.to_hdf : Write the contained data to an HDF5 file using + HDFStore. + DataFrame.to_sql : Write records stored in a DataFrame to a SQL + database. + DataFrame.to_parquet : Write a DataFrame to the binary parquet format. + Examples -------- >>> original_df = pd.DataFrame({"foo": range(5), "bar": range(5, 10)}) @@ -1945,15 +1954,8 @@ def to_pickle(self, path, compression='infer', 3 3 8 4 4 9 - See Also - -------- - read_pickle : Load pickled pandas object (or any other pickled object) - from the specified file path. - DataFrame.to_hdf : Write the contained data to an HDF5 file using - HDFStore. - DataFrame.to_sql : Write records stored in a DataFrame to a SQL - database. - DataFrame.to_parquet : Write a DataFrame to the binary parquet format. + >>> import os + >>> os.remove("./dummy.pkl") """ from pandas.io.pickle import to_pickle return to_pickle(self, path, compression=compression, From c1d6f03223d953ed24a95d3490245f2dcfae1e42 Mon Sep 17 00:00:00 2001 From: minggli Date: Tue, 13 Mar 2018 18:47:28 +0000 Subject: [PATCH 27/30] miscellaneous changes --- pandas/io/pickle.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index 37d970ca6b009..acd51585c6805 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -16,11 +16,11 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): ---------- obj : any object Any python object. - path : string + path : str File path where the pickled object will be stored. compression : {'infer', 'gzip', 'bz2', 'xz', None}, default 'infer' A string representing the compression to use in the output file. By - default, infers from the specified path. + default, infers from the file extension in specified path. .. versionadded:: 0.20.0 protocol : int @@ -58,8 +58,7 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): See Also -------- - read_pickle : Load pickled pandas object (or any other pickled object) from - the specified file path. + read_pickle : Load pickled pandas object (or any object) from file. DataFrame.to_hdf : Write the contained data to an HDF5 file using HDFStore. DataFrame.to_sql : Write records stored in a DataFrame to a SQL database. DataFrame.to_parquet : Write a DataFrame to the binary parquet format. @@ -80,8 +79,7 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): def read_pickle(path, compression='infer'): """ - Load pickled pandas object (or any other pickled object) from the specified - file path. + Load pickled pandas object (or any object) from file. .. warning:: @@ -90,7 +88,7 @@ def read_pickle(path, compression='infer'): Parameters ---------- - path : string + path : str File path where the pickled object will be loaded. compression : {'infer', 'gzip', 'bz2', 'xz', 'zip', None}, default 'infer' For on-the-fly decompression of on-disk data. If 'infer', then use @@ -104,6 +102,16 @@ def read_pickle(path, compression='infer'): ------- unpickled : type of object stored in file + See Also + -------- + DataFrame.to_pickle : Pickle (serialize) DataFrame object to input file + path. + Series.to_pickle : Pickle (serialize) Series object to input file path. + read_hdf : read from the store, close it if we opened it. + read_sql : Read SQL query or database table into a DataFrame. + read_parquet : Load a parquet object from the file path, returning a + DataFrame. + Examples -------- >>> original_df = pd.DataFrame({"foo": range(5), "bar": range(5, 10)}) @@ -125,15 +133,8 @@ def read_pickle(path, compression='infer'): 3 3 8 4 4 9 - See Also - -------- - DataFrame.to_pickle : Pickle (serialize) DataFrame object to input file - path. - Series.to_pickle : Pickle (serialize) Series object to input file path. - read_hdf : read from the store, close it if we opened it. - read_sql : Read SQL query or database table into a DataFrame. - read_parquet : Load a parquet object from the file path, returning a - DataFrame. + >>> import os + >>> os.remove("./dummy.pkl") """ path = _stringify_path(path) inferred_compression = _infer_compression(path, compression) From 39969d5f129b6b435d731f83bbeb2ca8b9cb40c9 Mon Sep 17 00:00:00 2001 From: minggli Date: Tue, 13 Mar 2018 21:52:45 +0000 Subject: [PATCH 28/30] move See Also before Example and add os.remove --- pandas/io/pickle.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index acd51585c6805..704969ee82696 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -35,6 +35,13 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): .. [1] https://docs.python.org/3/library/pickle.html .. versionadded:: 0.21.0 + See Also + -------- + read_pickle : Load pickled pandas object (or any object) from file. + DataFrame.to_hdf : Write the contained data to an HDF5 file using HDFStore. + DataFrame.to_sql : Write records stored in a DataFrame to a SQL database. + DataFrame.to_parquet : Write a DataFrame to the binary parquet format. + Examples -------- >>> original_df = pd.DataFrame({"foo": range(5), "bar": range(5, 10)}) @@ -56,12 +63,8 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): 3 3 8 4 4 9 - See Also - -------- - read_pickle : Load pickled pandas object (or any object) from file. - DataFrame.to_hdf : Write the contained data to an HDF5 file using HDFStore. - DataFrame.to_sql : Write records stored in a DataFrame to a SQL database. - DataFrame.to_parquet : Write a DataFrame to the binary parquet format. + >>> import os + >>> os.remove("./dummy.pkl") """ path = _stringify_path(path) inferred_compression = _infer_compression(path, compression) From c1a9d570ae53fb13d32a6768589cad6fdfcfcf02 Mon Sep 17 00:00:00 2001 From: minggli Date: Tue, 13 Mar 2018 22:03:27 +0000 Subject: [PATCH 29/30] simplify See Also and to_pickle summary. --- pandas/core/generic.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index ee06a638ce894..3cd1906b3a557 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1901,7 +1901,7 @@ def to_sql(self, name, con, schema=None, if_exists='fail', index=True, def to_pickle(self, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): """ - Pickle (serialize) object to input file path. + Pickle (serialize) object to file. Parameters ---------- @@ -1927,10 +1927,8 @@ def to_pickle(self, path, compression='infer', See Also -------- read_pickle : Load pickled pandas object (or any object) from file. - DataFrame.to_hdf : Write the contained data to an HDF5 file using - HDFStore. - DataFrame.to_sql : Write records stored in a DataFrame to a SQL - database. + DataFrame.to_hdf : Write DataFrame to an HDF5 file. + DataFrame.to_sql : Write DataFrame to a SQL database. DataFrame.to_parquet : Write a DataFrame to the binary parquet format. Examples From 26b3e2e68b6949f9d619883a97ecf37d41417b38 Mon Sep 17 00:00:00 2001 From: minggli Date: Tue, 13 Mar 2018 22:04:20 +0000 Subject: [PATCH 30/30] simplify See Also and to_pickle summary in pandas.io.pickle --- pandas/io/pickle.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index 704969ee82696..8c72c315c142c 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -10,7 +10,7 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): """ - Pickle (serialize) object to input file path. + Pickle (serialize) object to file. Parameters ---------- @@ -38,8 +38,8 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): See Also -------- read_pickle : Load pickled pandas object (or any object) from file. - DataFrame.to_hdf : Write the contained data to an HDF5 file using HDFStore. - DataFrame.to_sql : Write records stored in a DataFrame to a SQL database. + DataFrame.to_hdf : Write DataFrame to an HDF5 file. + DataFrame.to_sql : Write DataFrame to a SQL database. DataFrame.to_parquet : Write a DataFrame to the binary parquet format. Examples @@ -107,13 +107,11 @@ def read_pickle(path, compression='infer'): See Also -------- - DataFrame.to_pickle : Pickle (serialize) DataFrame object to input file - path. - Series.to_pickle : Pickle (serialize) Series object to input file path. - read_hdf : read from the store, close it if we opened it. + DataFrame.to_pickle : Pickle (serialize) DataFrame object to file. + Series.to_pickle : Pickle (serialize) Series object to file. + read_hdf : Read HDF5 file into a DataFrame. read_sql : Read SQL query or database table into a DataFrame. - read_parquet : Load a parquet object from the file path, returning a - DataFrame. + read_parquet : Load a parquet object, returning a DataFrame. Examples --------