diff --git a/ci/code_checks.sh b/ci/code_checks.sh index da4d95f9ae083..5e6c02eab574d 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -80,10 +80,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.io.formats.style.Styler.to_latex \ pandas.read_parquet \ pandas.DataFrame.to_sql \ - pandas.io.formats.style.Styler.map \ - pandas.io.formats.style.Styler.apply_index \ - pandas.io.formats.style.Styler.map_index \ - pandas.io.formats.style.Styler.format \ RET=$(($RET + $?)) ; echo $MSG "DONE" fi diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 6f255fdfc82db..7bbdfdfc6a2fe 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -1880,9 +1880,9 @@ def _apply_index( func="take a Series and return a string array of the same length", input_note="the index as a Series, if an Index, or a level of a MultiIndex", output_note="an identically sized array of CSS styles as strings", - var="s", - ret='np.where(s == "B", "background-color: yellow;", "")', - ret2='["background-color: yellow;" if "x" in v else "" for v in s]', + var="label", + ret='np.where(label == "B", "background-color: yellow;", "")', + ret2='["background-color: yellow;" if "x" in v else "" for v in label]', ) def apply_index( self, @@ -1932,8 +1932,8 @@ def apply_index( -------- Basic usage to conditionally highlight values in the index. - >>> df = pd.DataFrame([[1,2], [3,4]], index=["A", "B"]) - >>> def color_b(s): + >>> df = pd.DataFrame([[1, 2], [3, 4]], index=["A", "B"]) + >>> def color_b({var}): ... return {ret} >>> df.style.{this}_index(color_b) # doctest: +SKIP @@ -1945,8 +1945,8 @@ def apply_index( >>> df = pd.DataFrame([np.arange(8)], columns=midx) >>> def highlight_x({var}): ... return {ret2} - >>> df.style.{this}_index(highlight_x, axis="columns", level=[0, 2]) - ... # doctest: +SKIP + >>> df.style.{this}_index( + ... highlight_x, axis="columns", level=[0, 2]) # doctest: +SKIP .. figure:: ../../_static/style/appmaphead2.png """ @@ -1968,9 +1968,9 @@ def apply_index( func="take a scalar and return a string", input_note="an index value, if an Index, or a level value of a MultiIndex", output_note="CSS styles as a string", - var="v", - ret='"background-color: yellow;" if v == "B" else None', - ret2='"background-color: yellow;" if "x" in v else None', + var="label", + ret='"background-color: yellow;" if label == "B" else None', + ret2='"background-color: yellow;" if "x" in label else None', ) def map_index( self, @@ -2073,17 +2073,16 @@ def map(self, func: Callable, subset: Subset | None = None, **kwargs) -> Styler: Using ``subset`` to restrict application to a single column or multiple columns - >>> df.style.map(color_negative, color='red', subset="A") - ... # doctest: +SKIP - >>> df.style.map(color_negative, color='red', subset=["A", "B"]) - ... # doctest: +SKIP + >>> df.style.map(color_negative, color='red', subset="A") # doctest: +SKIP + >>> df.style.map(color_negative, + ... color='red', subset=["A", "B"]) # doctest: +SKIP Using a 2d input to ``subset`` to select rows in addition to columns >>> df.style.map(color_negative, color='red', - ... subset=([0,1,2], slice(None))) # doctest: +SKIP - >>> df.style.map(color_negative, color='red', subset=(slice(0,5,2), "A")) - ... # doctest: +SKIP + ... subset=([0, 1, 2], slice(None))) # doctest: +SKIP + >>> df.style.map(color_negative, + ... color='red', subset=(slice(0, 5, 2), "A")) # doctest: +SKIP See `Table Visualization <../../user_guide/style.ipynb>`_ user guide for more details. diff --git a/pandas/io/formats/style_render.py b/pandas/io/formats/style_render.py index 622e047b9f99b..38afde1eb762b 100644 --- a/pandas/io/formats/style_render.py +++ b/pandas/io/formats/style_render.py @@ -1063,15 +1063,15 @@ def format( Using a ``formatter`` specification on consistent column dtypes - >>> df.style.format('{:.2f}', na_rep='MISS', subset=[0,1]) # doctest: +SKIP + >>> df.style.format('{:.2f}', na_rep='MISS', subset=[0, 1]) # doctest: +SKIP 0 1 2 0 MISS 1.00 A 1 2.00 MISS 3.000000 Using the default ``formatter`` for unspecified columns - >>> df.style.format({0: '{:.2f}', 1: '£ {:.1f}'}, na_rep='MISS', precision=1) - ... # doctest: +SKIP + >>> df.style.format({0: '{:.2f}', 1: '£ {:.1f}'}, + ... na_rep='MISS', precision=1) # doctest: +SKIP 0 1 2 0 MISS £ 1.0 A 1 2.00 MISS 3.0 @@ -1079,8 +1079,8 @@ def format( Multiple ``na_rep`` or ``precision`` specifications under the default ``formatter``. - >>> (df.style.format(na_rep='MISS', precision=1, subset=[0]) - ... .format(na_rep='PASS', precision=2, subset=[1, 2])) # doctest: +SKIP + >>> (df.style.format(na_rep='MISS', precision=1, subset=[0]).format( + ... na_rep='PASS', precision=2, subset=[1, 2])) # doctest: +SKIP 0 1 2 0 MISS 1.00 A 1 2.0 PASS 3.00 @@ -1088,8 +1088,8 @@ def format( Using a callable ``formatter`` function. >>> func = lambda s: 'STRING' if isinstance(s, str) else 'FLOAT' - >>> df.style.format({0: '{:.1f}', 2: func}, precision=4, na_rep='MISS') - ... # doctest: +SKIP + >>> df.style.format({0: '{:.1f}', 2: func}, + ... precision=4, na_rep='MISS') # doctest: +SKIP 0 1 2 0 MISS 1.0000 STRING 1 2.0 MISS FLOAT @@ -1098,8 +1098,7 @@ def format( >>> df = pd.DataFrame([['
', '"A&B"', None]]) >>> s = df.style.format( - ... '{0}', escape="html", na_rep="NA" - ... ) + ... '{0}', escape="html", na_rep="NA") >>> s.to_html() # doctest: +SKIP ...