Skip to content

Commit e892a63

Browse files
author
wdyy20041223
committed
DOC: Inline docstrings in pandas\core\generic.py file for methods: droplevel, to_excel, to_json
1 parent ea75dd7 commit e892a63

File tree

1 file changed

+46
-31
lines changed

1 file changed

+46
-31
lines changed

pandas/core/generic.py

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -775,10 +775,9 @@ def _set_axis(self, axis: AxisInt, labels: AnyArrayLike | list) -> None:
775775
self._mgr.set_axis(axis, labels)
776776

777777
@final
778-
@doc(klass=_shared_doc_kwargs["klass"])
779778
def droplevel(self, level: IndexLabel, axis: Axis = 0) -> Self:
780779
"""
781-
Return {klass} with requested index / column level(s) removed.
780+
Return Series or DataFrame with requested index / column level(s) removed.
782781
783782
Parameters
784783
----------
@@ -787,7 +786,7 @@ def droplevel(self, level: IndexLabel, axis: Axis = 0) -> Self:
787786
If list-like, elements must be names or positional indexes
788787
of levels.
789788
790-
axis : {{0 or 'index', 1 or 'columns'}}, default 0
789+
axis : {0 or 'index', 1 or 'columns'}, default 0
791790
Axis along which the level(s) is removed:
792791
793792
* 0 or 'index': remove level(s) in column.
@@ -797,8 +796,8 @@ def droplevel(self, level: IndexLabel, axis: Axis = 0) -> Self:
797796
798797
Returns
799798
-------
800-
{klass}
801-
{klass} with requested index / column level(s) removed.
799+
Series or DataFrame
800+
Series or DataFrame with requested index / column level(s) removed.
802801
803802
See Also
804803
--------
@@ -2144,19 +2143,6 @@ def _repr_data_resource_(self):
21442143
# I/O Methods
21452144

21462145
@final
2147-
@doc(
2148-
klass="object",
2149-
storage_options=_shared_docs["storage_options"],
2150-
storage_options_versionadded="1.2.0",
2151-
encoding_parameter="",
2152-
verbose_parameter="",
2153-
extra_parameters=textwrap.dedent(
2154-
"""\
2155-
engine_kwargs : dict, optional
2156-
Arbitrary keyword arguments passed to excel engine.
2157-
"""
2158-
),
2159-
)
21602146
def to_excel(
21612147
self,
21622148
excel_writer: FilePath | WriteExcelBuffer | ExcelWriter,
@@ -2178,9 +2164,9 @@ def to_excel(
21782164
engine_kwargs: dict[str, Any] | None = None,
21792165
) -> None:
21802166
"""
2181-
Write {klass} to an Excel sheet.
2167+
Write object to an Excel sheet.
21822168
2183-
To write a single {klass} to an Excel .xlsx file it is only necessary to
2169+
To write a single object to an Excel .xlsx file it is only necessary to
21842170
specify a target file name. To write to multiple sheets it is necessary to
21852171
create an `ExcelWriter` object with a target file name, and specify a sheet
21862172
in the file to write to.
@@ -2224,18 +2210,26 @@ def to_excel(
22242210
merge_cells : bool or 'columns', default False
22252211
If True, write MultiIndex index and columns as merged cells.
22262212
If 'columns', merge MultiIndex column cells only.
2227-
{encoding_parameter}
22282213
inf_rep : str, default 'inf'
22292214
Representation for infinity (there is no native representation for
22302215
infinity in Excel).
2231-
{verbose_parameter}
22322216
freeze_panes : tuple of int (length 2), optional
22332217
Specifies the one-based bottommost row and rightmost column that
22342218
is to be frozen.
2235-
{storage_options}
2219+
storage_options : dict, optional
2220+
Extra options that make sense for a particular storage connection, e.g.
2221+
host, port, username, password, etc. For HTTP(S) URLs the key-value pairs
2222+
are forwarded to ``urllib.request.Request`` as header options. For other
2223+
URLs (e.g. starting with "s3://", and "gcs://") the key-value pairs are
2224+
forwarded to ``fsspec.open``. Please see ``fsspec`` and ``urllib`` for more
2225+
details, and for more examples on storage options refer `here
2226+
<https://pandas.pydata.org/docs/user_guide/io.html?
2227+
highlight=storage_options#reading-writing-remote-files>`_.
2228+
2229+
.. versionadded:: 1.2.0
2230+
engine_kwargs : dict, optional
2231+
Arbitrary keyword arguments passed to excel engine.
22362232
2237-
.. versionadded:: {storage_options_versionadded}
2238-
{extra_parameters}
22392233
See Also
22402234
--------
22412235
to_csv : Write DataFrame to a comma-separated values (csv) file.
@@ -2321,10 +2315,6 @@ def to_excel(
23212315
)
23222316

23232317
@final
2324-
@doc(
2325-
storage_options=_shared_docs["storage_options"],
2326-
compression_options=_shared_docs["compression_options"] % "path_or_buf",
2327-
)
23282318
def to_json(
23292319
self,
23302320
path_or_buf: FilePath | WriteBuffer[bytes] | WriteBuffer[str] | None = None,
@@ -2409,7 +2399,24 @@ def to_json(
24092399
If 'orient' is 'records' write out line-delimited json format. Will
24102400
throw ValueError if incorrect 'orient' since others are not
24112401
list-like.
2412-
{compression_options}
2402+
compression : str or dict, default 'infer'
2403+
For on-the-fly compression of the output data. If 'infer' and 'path_or_buf' is
2404+
path-like, then detect compression from the following extensions: '.gz',
2405+
'.bz2', '.zip', '.xz', '.zst', '.tar', '.tar.gz', '.tar.xz' or '.tar.bz2'
2406+
(otherwise no compression).
2407+
Set to ``None`` for no compression.
2408+
Can also be a dict with key ``'method'`` set
2409+
to one of {``'zip'``, ``'gzip'``, ``'bz2'``, ``'zstd'``, ``'xz'``, ``'tar'``} and
2410+
other key-value pairs are forwarded to
2411+
``zipfile.ZipFile``, ``gzip.GzipFile``,
2412+
``bz2.BZ2File``, ``zstandard.ZstdCompressor``, ``lzma.LZMAFile`` or
2413+
``tarfile.TarFile``, respectively.
2414+
As an example, the following could be passed for faster compression and to create
2415+
a reproducible gzip archive:
2416+
``compression={'method': 'gzip', 'compresslevel': 1, 'mtime': 1}``.
2417+
2418+
.. versionadded:: 1.5.0
2419+
Added support for `.tar` files.
24132420
24142421
.. versionchanged:: 1.4.0 Zstandard support.
24152422
@@ -2422,7 +2429,15 @@ def to_json(
24222429
indent : int, optional
24232430
Length of whitespace used to indent each record.
24242431
2425-
{storage_options}
2432+
storage_options : dict, optional
2433+
Extra options that make sense for a particular storage connection, e.g.
2434+
host, port, username, password, etc. For HTTP(S) URLs the key-value pairs
2435+
are forwarded to ``urllib.request.Request`` as header options. For other
2436+
URLs (e.g. starting with "s3://", and "gcs://") the key-value pairs are
2437+
forwarded to ``fsspec.open``. Please see ``fsspec`` and ``urllib`` for more
2438+
details, and for more examples on storage options refer `here
2439+
<https://pandas.pydata.org/docs/user_guide/io.html?
2440+
highlight=storage_options#reading-writing-remote-files>`_.
24262441
24272442
mode : str, default 'w' (writing)
24282443
Specify the IO mode for output when supplying a path_or_buf.

0 commit comments

Comments
 (0)