From 977f9d3156da7b285f8881d6c854ddf579920ddd Mon Sep 17 00:00:00 2001 From: sdhjebngc <2224531525@qq.com> Date: Fri, 19 Dec 2025 13:50:01 +0800 Subject: [PATCH 1/3] DOC: Replace @doc decorator with inline docstrings in pandas/io/pickle.py --- pandas/io/pickle.py | 78 ++++++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 22 deletions(-) diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index df1c35e0dabee..e013fd96088d8 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -10,12 +10,7 @@ import warnings from pandas.compat import pickle_compat -from pandas.util._decorators import ( - doc, - set_module, -) - -from pandas.core.shared_docs import _shared_docs +from pandas.util._decorators import set_module from pandas.io.common import get_handle @@ -35,10 +30,6 @@ @set_module("pandas") -@doc( - storage_options=_shared_docs["storage_options"], - compression_options=_shared_docs["compression_options"] % "filepath_or_buffer", -) def to_pickle( obj: Any, filepath_or_buffer: FilePath | WriteBuffer[bytes], @@ -57,8 +48,24 @@ def to_pickle( String, path object (implementing ``os.PathLike[str]``), or file-like object implementing a binary ``write()`` function. Also accepts URL. URL has to be of S3 or GCS. - {compression_options} - + compression : str or dict, default 'infer' + For on-the-fly compression of the output data. If 'infer' and 'filepath_or_buffer' is + path-like, then detect compression from the following extensions: '.gz', + '.bz2', '.zip', '.xz', '.zst', '.tar', '.tar.gz', '.tar.xz' or '.tar.bz2' + (otherwise no compression). + Set to ``None`` for no compression. + Can also be a dict with key ``'method'`` set + to one of {``'zip'``, ``'gzip'``, ``'bz2'``, ``'zstd'``, ``'xz'``, ``'tar'``} and + other key-value pairs are forwarded to + ``zipfile.ZipFile``, ``gzip.GzipFile``, + ``bz2.BZ2File``, ``zstandard.ZstdCompressor``, ``lzma.LZMAFile`` or + ``tarfile.TarFile``, respectively. + As an example, the following could be passed for faster compression and to create + a reproducible gzip archive: + ``compression={'method': 'gzip', 'compresslevel': 1, 'mtime': 1}``. + + .. versionadded:: 1.5.0 + Added support for `.tar` files. protocol : int Int which indicates which protocol should be used by the pickler, default HIGHEST_PROTOCOL (see [1], paragraph 12.1.2). The possible @@ -67,8 +74,15 @@ def to_pickle( 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. - - {storage_options} + storage_options : dict, optional + Extra options that make sense for a particular storage connection, e.g. + host, port, username, password, etc. For HTTP(S) URLs the key-value pairs + are forwarded to ``urllib.request.Request`` as header options. For other + URLs (e.g. starting with "s3://", and "gcs://") the key-value pairs are + forwarded to ``fsspec.open``. Please see ``fsspec`` and ``urllib`` for more + details, and for more examples on storage options refer `here + `_. .. [1] https://docs.python.org/3/library/pickle.html @@ -117,10 +131,6 @@ def to_pickle( @set_module("pandas") -@doc( - storage_options=_shared_docs["storage_options"], - decompression_options=_shared_docs["decompression_options"] % "filepath_or_buffer", -) def read_pickle( filepath_or_buffer: FilePath | ReadPickleBuffer, compression: CompressionOptions = "infer", @@ -140,10 +150,34 @@ def read_pickle( String, path object (implementing ``os.PathLike[str]``), or file-like object implementing a binary ``readlines()`` function. Also accepts URL. URL is not limited to S3 and GCS. - - {decompression_options} - - {storage_options} + compression : str or dict, default 'infer' + For on-the-fly decompression of on-disk data. If 'infer' and 'filepath_or_buffer' is + path-like, then detect compression from the following extensions: '.gz', + '.bz2', '.zip', '.xz', '.zst', '.tar', '.tar.gz', '.tar.xz' or '.tar.bz2' + (otherwise no compression). + If using 'zip' or 'tar', the ZIP file must contain only one data file to be read in. + Set to ``None`` for no decompression. + Can also be a dict with key ``'method'`` set + to one of {``'zip'``, ``'gzip'``, ``'bz2'``, ``'zstd'``, ``'xz'``, ``'tar'``} and + other key-value pairs are forwarded to + ``zipfile.ZipFile``, ``gzip.GzipFile``, + ``bz2.BZ2File``, ``zstandard.ZstdDecompressor``, ``lzma.LZMAFile`` or + ``tarfile.TarFile``, respectively. + As an example, the following could be passed for Zstandard decompression using a + custom compression dictionary: + ``compression={'method': 'zstd', 'dict_data': my_compression_dict}``. + + .. versionadded:: 1.5.0 + Added support for `.tar` files. + storage_options : dict, optional + Extra options that make sense for a particular storage connection, e.g. + host, port, username, password, etc. For HTTP(S) URLs the key-value pairs + are forwarded to ``urllib.request.Request`` as header options. For other + URLs (e.g. starting with "s3://", and "gcs://") the key-value pairs are + forwarded to ``fsspec.open``. Please see ``fsspec`` and ``urllib`` for more + details, and for more examples on storage options refer `here + `_. Returns ------- From 43b2f81bdc086d6f778dfd1b2d32c6b35c8e2f46 Mon Sep 17 00:00:00 2001 From: sdhjebngc <2224531525@qq.com> Date: Fri, 19 Dec 2025 13:55:57 +0800 Subject: [PATCH 2/3] DOC: Fix line length issues in pandas/io/pickle.py --- pandas/io/pickle.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index e013fd96088d8..844987d65f94f 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -49,19 +49,19 @@ def to_pickle( object implementing a binary ``write()`` function. Also accepts URL. URL has to be of S3 or GCS. compression : str or dict, default 'infer' - For on-the-fly compression of the output data. If 'infer' and 'filepath_or_buffer' is - path-like, then detect compression from the following extensions: '.gz', - '.bz2', '.zip', '.xz', '.zst', '.tar', '.tar.gz', '.tar.xz' or '.tar.bz2' - (otherwise no compression). + For on-the-fly compression of the output data. If 'infer' and + 'filepath_or_buffer' is path-like, then detect compression from the + following extensions: '.gz', '.bz2', '.zip', '.xz', '.zst', '.tar', + '.tar.gz', '.tar.xz' or '.tar.bz2' (otherwise no compression). Set to ``None`` for no compression. Can also be a dict with key ``'method'`` set - to one of {``'zip'``, ``'gzip'``, ``'bz2'``, ``'zstd'``, ``'xz'``, ``'tar'``} and - other key-value pairs are forwarded to + to one of {``'zip'``, ``'gzip'``, ``'bz2'``, ``'zstd'``, ``'xz'``, + ``'tar'``} and other key-value pairs are forwarded to ``zipfile.ZipFile``, ``gzip.GzipFile``, ``bz2.BZ2File``, ``zstandard.ZstdCompressor``, ``lzma.LZMAFile`` or ``tarfile.TarFile``, respectively. - As an example, the following could be passed for faster compression and to create - a reproducible gzip archive: + As an example, the following could be passed for faster compression + and to create a reproducible gzip archive: ``compression={'method': 'gzip', 'compresslevel': 1, 'mtime': 1}``. .. versionadded:: 1.5.0 @@ -151,20 +151,21 @@ def read_pickle( object implementing a binary ``readlines()`` function. Also accepts URL. URL is not limited to S3 and GCS. compression : str or dict, default 'infer' - For on-the-fly decompression of on-disk data. If 'infer' and 'filepath_or_buffer' is - path-like, then detect compression from the following extensions: '.gz', - '.bz2', '.zip', '.xz', '.zst', '.tar', '.tar.gz', '.tar.xz' or '.tar.bz2' - (otherwise no compression). - If using 'zip' or 'tar', the ZIP file must contain only one data file to be read in. + For on-the-fly decompression of on-disk data. If 'infer' and + 'filepath_or_buffer' is path-like, then detect compression from the + following extensions: '.gz', '.bz2', '.zip', '.xz', '.zst', '.tar', + '.tar.gz', '.tar.xz' or '.tar.bz2' (otherwise no compression). + If using 'zip' or 'tar', the ZIP file must contain only one data file + to be read in. Set to ``None`` for no decompression. Can also be a dict with key ``'method'`` set - to one of {``'zip'``, ``'gzip'``, ``'bz2'``, ``'zstd'``, ``'xz'``, ``'tar'``} and - other key-value pairs are forwarded to + to one of {``'zip'``, ``'gzip'``, ``'bz2'``, ``'zstd'``, ``'xz'``, + ``'tar'``} and other key-value pairs are forwarded to ``zipfile.ZipFile``, ``gzip.GzipFile``, ``bz2.BZ2File``, ``zstandard.ZstdDecompressor``, ``lzma.LZMAFile`` or ``tarfile.TarFile``, respectively. - As an example, the following could be passed for Zstandard decompression using a - custom compression dictionary: + As an example, the following could be passed for Zstandard decompression + using a custom compression dictionary: ``compression={'method': 'zstd', 'dict_data': my_compression_dict}``. .. versionadded:: 1.5.0 From 67c9fe30c0dafda102f4215be2174ba01cdc862f Mon Sep 17 00:00:00 2001 From: sdhjebngc <2224531525@qq.com> Date: Sat, 20 Dec 2025 11:13:49 +0800 Subject: [PATCH 3/3] DOC: Remove versionadded notes from pickle.py compression parameter --- pandas/io/pickle.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index 844987d65f94f..0f2b380bc70bf 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -63,9 +63,6 @@ def to_pickle( As an example, the following could be passed for faster compression and to create a reproducible gzip archive: ``compression={'method': 'gzip', 'compresslevel': 1, 'mtime': 1}``. - - .. versionadded:: 1.5.0 - Added support for `.tar` files. protocol : int Int which indicates which protocol should be used by the pickler, default HIGHEST_PROTOCOL (see [1], paragraph 12.1.2). The possible @@ -167,9 +164,6 @@ def read_pickle( As an example, the following could be passed for Zstandard decompression using a custom compression dictionary: ``compression={'method': 'zstd', 'dict_data': my_compression_dict}``. - - .. versionadded:: 1.5.0 - Added support for `.tar` files. storage_options : dict, optional Extra options that make sense for a particular storage connection, e.g. host, port, username, password, etc. For HTTP(S) URLs the key-value pairs