Skip to content

DOC: Enforce Numpy Docstring Validation for pandas.DataFrame.to_markdown #58567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.DataFrame.std PR01,RT03,SA01" \
-i "pandas.DataFrame.sum RT03" \
-i "pandas.DataFrame.swaplevel SA01" \
-i "pandas.DataFrame.to_markdown SA01" \
-i "pandas.Grouper PR02" \
-i "pandas.Index PR07" \
-i "pandas.Index.join PR07,RT03,SA01" \
Expand Down
67 changes: 51 additions & 16 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2749,11 +2749,55 @@ def to_markdown(
**kwargs,
) -> str | None: ...

@doc(
Series.to_markdown,
klass=_shared_doc_kwargs["klass"],
storage_options=_shared_docs["storage_options"],
examples="""Examples
def to_markdown(
self,
buf: FilePath | WriteBuffer[str] | None = None,
*,
mode: str = "wt",
index: bool = True,
storage_options: StorageOptions | None = None,
**kwargs,
) -> str | None:
"""
Print DataFrame in Markdown-friendly format.

Parameters
----------
buf : str, Path or StringIO-like, optional, default None
Buffer to write to. If None, the output is returned as a string.
mode : str, optional
Mode in which file is opened, "wt" by default.
index : bool, optional, default True
Add index (row) labels.

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
<https://pandas.pydata.org/docs/user_guide/io.html?
highlight=storage_options#reading-writing-remote-files>`_.

**kwargs
These parameters will be passed to `tabulate <https://pypi.org/project/tabulate>`_.

Returns
-------
str
DataFrame in Markdown-friendly format.

See Also
--------
DataFrame.to_html : Render DataFrame to HTML-formatted table.
DataFrame.to_latex : Render DataFrame to LaTeX-formatted table.

Notes
-----
Requires the `tabulate <https://pypi.org/project/tabulate>`_ package.

Examples
--------
>>> df = pd.DataFrame(
... data={"animal_1": ["elk", "pig"], "animal_2": ["dog", "quetzal"]}
Expand All @@ -2773,17 +2817,8 @@ def to_markdown(
| 0 | elk | dog |
+----+------------+------------+
| 1 | pig | quetzal |
+----+------------+------------+""",
)
def to_markdown(
self,
buf: FilePath | WriteBuffer[str] | None = None,
*,
mode: str = "wt",
index: bool = True,
storage_options: StorageOptions | None = None,
**kwargs,
) -> str | None:
+----+------------+------------+
"""
if "showindex" in kwargs:
raise ValueError("Pass 'index' instead of 'showindex")

Expand Down