From a79624d1dec794eeb6647e85e2e9ec47d1633e24 Mon Sep 17 00:00:00 2001 From: Jordan Murphy <35613487+jordan-d-murphy@users.noreply.github.com> Date: Sun, 14 Jan 2024 23:50:43 -0700 Subject: [PATCH] DOC: fix EX03 errors in docstrings - pandas.io.formats.style.Styler: format_index, relabel_index, hide, set_td_classes (#56881) --- ci/code_checks.sh | 7 ------- pandas/io/formats/style.py | 14 +++++++------- pandas/io/formats/style_render.py | 30 ++++++++++++++++-------------- 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 50310a3af9661..1eeb39d428ee3 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -101,10 +101,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 \ @@ -114,9 +110,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 \ diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 26349dc129361..0fbfae22f4663 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -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, @@ -2717,7 +2717,7 @@ 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 @@ -2725,7 +2725,7 @@ def hide( 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 @@ -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 @@ -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 diff --git a/pandas/io/formats/style_render.py b/pandas/io/formats/style_render.py index 55541e5262719..622e047b9f99b 100644 --- a/pandas/io/formats/style_render.py +++ b/pandas/io/formats/style_render.py @@ -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 @@ -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 @@ -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