Skip to content

DOC: fix EX03 errors in docstrings - pandas.io.formats.style.Styler: format_index, relabel_index, hide, set_td_classes #56881

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 1 commit into from
Jan 15, 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
7 changes: 0 additions & 7 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.io.formats.style.Styler.apply_index \
pandas.io.formats.style.Styler.map_index \
pandas.io.formats.style.Styler.format \
pandas.io.formats.style.Styler.format_index \
pandas.io.formats.style.Styler.relabel_index \
pandas.io.formats.style.Styler.hide \
pandas.io.formats.style.Styler.set_td_classes \
pandas.io.formats.style.Styler.set_tooltips \
pandas.io.formats.style.Styler.set_uuid \
pandas.io.formats.style.Styler.pipe \
Expand All @@ -122,9 +118,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.io.formats.style.Styler.text_gradient \
pandas.DataFrame.values \
pandas.DataFrame.groupby \
pandas.DataFrame.idxmax \
pandas.DataFrame.idxmin \
pandas.DataFrame.pivot \
pandas.DataFrame.sort_values \
pandas.DataFrame.plot.hexbin \
pandas.DataFrame.plot.line \
Expand Down
14 changes: 7 additions & 7 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -1496,10 +1496,10 @@ def set_td_classes(self, classes: DataFrame) -> Styler:
Using `MultiIndex` columns and a `classes` `DataFrame` as a subset of the
underlying,

>>> df = pd.DataFrame([[1,2],[3,4]], index=["a", "b"],
... columns=[["level0", "level0"], ["level1a", "level1b"]])
>>> df = pd.DataFrame([[1, 2], [3, 4]], index=["a", "b"],
... columns=[["level0", "level0"], ["level1a", "level1b"]])
>>> classes = pd.DataFrame(["min-val"], index=["a"],
... columns=[["level0"],["level1a"]])
... columns=[["level0"], ["level1a"]])
>>> df.style.set_td_classes(classes) # doctest: +SKIP

Form of the output with new additional css classes,
Expand Down Expand Up @@ -2717,15 +2717,15 @@ def hide(
--------
Simple application hiding specific rows:

>>> df = pd.DataFrame([[1,2], [3,4], [5,6]], index=["a", "b", "c"])
>>> df = pd.DataFrame([[1, 2], [3, 4], [5, 6]], index=["a", "b", "c"])
>>> df.style.hide(["a", "b"]) # doctest: +SKIP
0 1
c 5 6

Hide the index and retain the data values:

>>> midx = pd.MultiIndex.from_product([["x", "y"], ["a", "b", "c"]])
>>> df = pd.DataFrame(np.random.randn(6,6), index=midx, columns=midx)
>>> df = pd.DataFrame(np.random.randn(6, 6), index=midx, columns=midx)
>>> df.style.format("{:.1f}").hide() # doctest: +SKIP
x y
a b c a b c
Expand All @@ -2739,7 +2739,7 @@ def hide(
Hide specific rows in a MultiIndex but retain the index:

>>> df.style.format("{:.1f}").hide(subset=(slice(None), ["a", "c"]))
... # doctest: +SKIP
... # doctest: +SKIP
x y
a b c a b c
x b 0.7 1.0 1.3 1.5 -0.0 -0.2
Expand All @@ -2748,7 +2748,7 @@ def hide(
Hide specific rows and the index through chaining:

>>> df.style.format("{:.1f}").hide(subset=(slice(None), ["a", "c"])).hide()
... # doctest: +SKIP
... # doctest: +SKIP
x y
a b c a b c
0.7 1.0 1.3 1.5 -0.0 -0.2
Expand Down
30 changes: 16 additions & 14 deletions pandas/io/formats/style_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -1318,9 +1318,10 @@ def format_index(
Using the default ``formatter`` for unspecified levels

>>> df = pd.DataFrame([[1, 2, 3]],
... columns=pd.MultiIndex.from_arrays([["a", "a", "b"],[2, np.nan, 4]]))
... columns=pd.MultiIndex.from_arrays(
... [["a", "a", "b"], [2, np.nan, 4]]))
>>> df.style.format_index({0: lambda v: v.upper()}, axis=1, precision=1)
... # doctest: +SKIP
... # doctest: +SKIP
A B
2.0 nan 4.0
0 1 2 3
Expand All @@ -1329,7 +1330,7 @@ def format_index(

>>> func = lambda s: 'STRING' if isinstance(s, str) else 'FLOAT'
>>> df.style.format_index(func, axis=1, na_rep='MISS')
... # doctest: +SKIP
... # doctest: +SKIP
STRING STRING
FLOAT MISS FLOAT
0 1 2 3
Expand All @@ -1338,7 +1339,7 @@ def format_index(

>>> df = pd.DataFrame([[1, 2, 3]], columns=['"A"', 'A&B', None])
>>> s = df.style.format_index('$ {0}', axis=1, escape="html", na_rep="NA")
... # doctest: +SKIP
... # doctest: +SKIP
<th .. >$ &#34;A&#34;</th>
<th .. >$ A&amp;B</th>
<th .. >NA</td>
Expand All @@ -1348,7 +1349,7 @@ def format_index(

>>> df = pd.DataFrame([[1, 2, 3]], columns=["123", "~", "$%#"])
>>> df.style.format_index("\\textbf{{{}}}", escape="latex", axis=1).to_latex()
... # doctest: +SKIP
... # doctest: +SKIP
\begin{tabular}{lrrr}
{} & {\textbf{123}} & {\textbf{\textasciitilde }} & {\textbf{\$\%\#}} \\
0 & 1 & 2 & 3 \\
Expand Down Expand Up @@ -1475,7 +1476,7 @@ def relabel_index(

Chaining with pre-hidden elements

>>> df.style.hide([0,1]).relabel_index(["C"]) # doctest: +SKIP
>>> df.style.hide([0, 1]).relabel_index(["C"]) # doctest: +SKIP
col
C c

Expand All @@ -1493,19 +1494,20 @@ def relabel_index(
1 5
1 0 6
1 7
>>> styler.hide((midx.get_level_values(0)==0)|(midx.get_level_values(1)==0))
... # doctest: +SKIP
>>> styler.hide(level=[0,1]) # doctest: +SKIP
>>> styler.hide((midx.get_level_values(0) == 0) |
... (midx.get_level_values(1) == 0))
... # doctest: +SKIP
>>> styler.hide(level=[0, 1]) # doctest: +SKIP
>>> styler.relabel_index(["binary6", "binary7"]) # doctest: +SKIP
col
binary6 6
binary7 7

We can also achieve the above by indexing first and then re-labeling

>>> styler = df.loc[[(1,1,0), (1,1,1)]].style
>>> styler.hide(level=[0,1]).relabel_index(["binary6", "binary7"])
... # doctest: +SKIP
>>> styler = df.loc[[(1, 1, 0), (1, 1, 1)]].style
>>> styler.hide(level=[0, 1]).relabel_index(["binary6", "binary7"])
... # doctest: +SKIP
col
binary6 6
binary7 7
Expand All @@ -1516,9 +1518,9 @@ def relabel_index(
brackets if the string if pre-formatted),

>>> df = pd.DataFrame({"samples": np.random.rand(10)})
>>> styler = df.loc[np.random.randint(0,10,3)].style
>>> styler = df.loc[np.random.randint(0, 10, 3)].style
>>> styler.relabel_index([f"sample{i+1} ({{}})" for i in range(3)])
... # doctest: +SKIP
... # doctest: +SKIP
samples
sample1 (5) 0.315811
sample2 (0) 0.495941
Expand Down