Skip to content

Commit 321df55

Browse files
DOC: fix EX03 errors in docstrings - pandas.io.formats.style.Styler: format_index, relabel_index, hide, set_td_classes (#56881)
1 parent a0634c9 commit 321df55

File tree

3 files changed

+23
-28
lines changed

3 files changed

+23
-28
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
101101
pandas.io.formats.style.Styler.apply_index \
102102
pandas.io.formats.style.Styler.map_index \
103103
pandas.io.formats.style.Styler.format \
104-
pandas.io.formats.style.Styler.format_index \
105-
pandas.io.formats.style.Styler.relabel_index \
106-
pandas.io.formats.style.Styler.hide \
107-
pandas.io.formats.style.Styler.set_td_classes \
108104
pandas.io.formats.style.Styler.set_tooltips \
109105
pandas.io.formats.style.Styler.set_uuid \
110106
pandas.io.formats.style.Styler.pipe \
@@ -114,9 +110,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
114110
pandas.io.formats.style.Styler.text_gradient \
115111
pandas.DataFrame.values \
116112
pandas.DataFrame.groupby \
117-
pandas.DataFrame.idxmax \
118-
pandas.DataFrame.idxmin \
119-
pandas.DataFrame.pivot \
120113
pandas.DataFrame.sort_values \
121114
pandas.DataFrame.plot.hexbin \
122115
pandas.DataFrame.plot.line \

pandas/io/formats/style.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,10 +1496,10 @@ def set_td_classes(self, classes: DataFrame) -> Styler:
14961496
Using `MultiIndex` columns and a `classes` `DataFrame` as a subset of the
14971497
underlying,
14981498
1499-
>>> df = pd.DataFrame([[1,2],[3,4]], index=["a", "b"],
1500-
... columns=[["level0", "level0"], ["level1a", "level1b"]])
1499+
>>> df = pd.DataFrame([[1, 2], [3, 4]], index=["a", "b"],
1500+
... columns=[["level0", "level0"], ["level1a", "level1b"]])
15011501
>>> classes = pd.DataFrame(["min-val"], index=["a"],
1502-
... columns=[["level0"],["level1a"]])
1502+
... columns=[["level0"], ["level1a"]])
15031503
>>> df.style.set_td_classes(classes) # doctest: +SKIP
15041504
15051505
Form of the output with new additional css classes,
@@ -2717,15 +2717,15 @@ def hide(
27172717
--------
27182718
Simple application hiding specific rows:
27192719
2720-
>>> df = pd.DataFrame([[1,2], [3,4], [5,6]], index=["a", "b", "c"])
2720+
>>> df = pd.DataFrame([[1, 2], [3, 4], [5, 6]], index=["a", "b", "c"])
27212721
>>> df.style.hide(["a", "b"]) # doctest: +SKIP
27222722
0 1
27232723
c 5 6
27242724
27252725
Hide the index and retain the data values:
27262726
27272727
>>> midx = pd.MultiIndex.from_product([["x", "y"], ["a", "b", "c"]])
2728-
>>> df = pd.DataFrame(np.random.randn(6,6), index=midx, columns=midx)
2728+
>>> df = pd.DataFrame(np.random.randn(6, 6), index=midx, columns=midx)
27292729
>>> df.style.format("{:.1f}").hide() # doctest: +SKIP
27302730
x y
27312731
a b c a b c
@@ -2739,7 +2739,7 @@ def hide(
27392739
Hide specific rows in a MultiIndex but retain the index:
27402740
27412741
>>> df.style.format("{:.1f}").hide(subset=(slice(None), ["a", "c"]))
2742-
... # doctest: +SKIP
2742+
... # doctest: +SKIP
27432743
x y
27442744
a b c a b c
27452745
x b 0.7 1.0 1.3 1.5 -0.0 -0.2
@@ -2748,7 +2748,7 @@ def hide(
27482748
Hide specific rows and the index through chaining:
27492749
27502750
>>> df.style.format("{:.1f}").hide(subset=(slice(None), ["a", "c"])).hide()
2751-
... # doctest: +SKIP
2751+
... # doctest: +SKIP
27522752
x y
27532753
a b c a b c
27542754
0.7 1.0 1.3 1.5 -0.0 -0.2

pandas/io/formats/style_render.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,9 +1318,10 @@ def format_index(
13181318
Using the default ``formatter`` for unspecified levels
13191319
13201320
>>> df = pd.DataFrame([[1, 2, 3]],
1321-
... columns=pd.MultiIndex.from_arrays([["a", "a", "b"],[2, np.nan, 4]]))
1321+
... columns=pd.MultiIndex.from_arrays(
1322+
... [["a", "a", "b"], [2, np.nan, 4]]))
13221323
>>> df.style.format_index({0: lambda v: v.upper()}, axis=1, precision=1)
1323-
... # doctest: +SKIP
1324+
... # doctest: +SKIP
13241325
A B
13251326
2.0 nan 4.0
13261327
0 1 2 3
@@ -1329,7 +1330,7 @@ def format_index(
13291330
13301331
>>> func = lambda s: 'STRING' if isinstance(s, str) else 'FLOAT'
13311332
>>> df.style.format_index(func, axis=1, na_rep='MISS')
1332-
... # doctest: +SKIP
1333+
... # doctest: +SKIP
13331334
STRING STRING
13341335
FLOAT MISS FLOAT
13351336
0 1 2 3
@@ -1338,7 +1339,7 @@ def format_index(
13381339
13391340
>>> df = pd.DataFrame([[1, 2, 3]], columns=['"A"', 'A&B', None])
13401341
>>> s = df.style.format_index('$ {0}', axis=1, escape="html", na_rep="NA")
1341-
... # doctest: +SKIP
1342+
... # doctest: +SKIP
13421343
<th .. >$ &#34;A&#34;</th>
13431344
<th .. >$ A&amp;B</th>
13441345
<th .. >NA</td>
@@ -1348,7 +1349,7 @@ def format_index(
13481349
13491350
>>> df = pd.DataFrame([[1, 2, 3]], columns=["123", "~", "$%#"])
13501351
>>> df.style.format_index("\\textbf{{{}}}", escape="latex", axis=1).to_latex()
1351-
... # doctest: +SKIP
1352+
... # doctest: +SKIP
13521353
\begin{tabular}{lrrr}
13531354
{} & {\textbf{123}} & {\textbf{\textasciitilde }} & {\textbf{\$\%\#}} \\
13541355
0 & 1 & 2 & 3 \\
@@ -1475,7 +1476,7 @@ def relabel_index(
14751476
14761477
Chaining with pre-hidden elements
14771478
1478-
>>> df.style.hide([0,1]).relabel_index(["C"]) # doctest: +SKIP
1479+
>>> df.style.hide([0, 1]).relabel_index(["C"]) # doctest: +SKIP
14791480
col
14801481
C c
14811482
@@ -1493,19 +1494,20 @@ def relabel_index(
14931494
1 5
14941495
1 0 6
14951496
1 7
1496-
>>> styler.hide((midx.get_level_values(0)==0)|(midx.get_level_values(1)==0))
1497-
... # doctest: +SKIP
1498-
>>> styler.hide(level=[0,1]) # doctest: +SKIP
1497+
>>> styler.hide((midx.get_level_values(0) == 0) |
1498+
... (midx.get_level_values(1) == 0))
1499+
... # doctest: +SKIP
1500+
>>> styler.hide(level=[0, 1]) # doctest: +SKIP
14991501
>>> styler.relabel_index(["binary6", "binary7"]) # doctest: +SKIP
15001502
col
15011503
binary6 6
15021504
binary7 7
15031505
15041506
We can also achieve the above by indexing first and then re-labeling
15051507
1506-
>>> styler = df.loc[[(1,1,0), (1,1,1)]].style
1507-
>>> styler.hide(level=[0,1]).relabel_index(["binary6", "binary7"])
1508-
... # doctest: +SKIP
1508+
>>> styler = df.loc[[(1, 1, 0), (1, 1, 1)]].style
1509+
>>> styler.hide(level=[0, 1]).relabel_index(["binary6", "binary7"])
1510+
... # doctest: +SKIP
15091511
col
15101512
binary6 6
15111513
binary7 7
@@ -1516,9 +1518,9 @@ def relabel_index(
15161518
brackets if the string if pre-formatted),
15171519
15181520
>>> df = pd.DataFrame({"samples": np.random.rand(10)})
1519-
>>> styler = df.loc[np.random.randint(0,10,3)].style
1521+
>>> styler = df.loc[np.random.randint(0, 10, 3)].style
15201522
>>> styler.relabel_index([f"sample{i+1} ({{}})" for i in range(3)])
1521-
... # doctest: +SKIP
1523+
... # doctest: +SKIP
15221524
samples
15231525
sample1 (5) 0.315811
15241526
sample2 (0) 0.495941

0 commit comments

Comments
 (0)