Skip to content

STYLE: Fix errors in doctests #51356

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 11 commits into from
Feb 16, 2023
2 changes: 1 addition & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3329,7 +3329,7 @@ def to_latex(
>>> print(df.to_latex(index=False,
... formatters={"name": str.upper},
... float_format="{:.1f}".format,
... ) # doctest: +SKIP
... )) # doctest: +SKIP
\begin{tabular}{lrr}
\toprule
name & age & height \\
Expand Down
10 changes: 5 additions & 5 deletions pandas/errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,11 @@ class CSSWarning(UserWarning):
Examples
--------
>>> df = pd.DataFrame({'A': [1, 1, 1]})
>>> df.style.applymap(lambda x: 'background-color: blueGreenRed;')
... .to_excel('styled.xlsx') # doctest: +SKIP
>>> (df.style.applymap(lambda x: 'background-color: blueGreenRed;')
... .to_excel('styled.xlsx')) # doctest: +SKIP
... # CSSWarning: Unhandled color format: 'blueGreenRed'
>>> df.style.applymap(lambda x: 'border: 1px solid red red;')
... .to_excel('styled.xlsx') # doctest: +SKIP
>>> (df.style.applymap(lambda x: 'border: 1px solid red red;')
... .to_excel('styled.xlsx')) # doctest: +SKIP
... # CSSWarning: Too many tokens provided to "border" (expected 1-3)
"""

Expand Down Expand Up @@ -569,7 +569,7 @@ class CategoricalConversionWarning(Warning):
>>> from pandas.io.stata import StataReader
>>> with StataReader('dta_file', chunksize=2) as reader: # doctest: +SKIP
... for i, block in enumerate(reader):
... print(i, block))
... print(i, block)
... # CategoricalConversionWarning: One or more series with value labels...
"""

Expand Down
12 changes: 6 additions & 6 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,12 +961,12 @@ def to_latex(
Second we will format the display and, since our table is quite wide, will
hide the repeated level-0 of the index:

>>> styler.format(subset="Equity", precision=2)
>>> (styler.format(subset="Equity", precision=2)
... .format(subset="Stats", precision=1, thousands=",")
... .format(subset="Rating", formatter=str.upper)
... .format_index(escape="latex", axis=1)
... .format_index(escape="latex", axis=0)
... .hide(level=0, axis=0) # doctest: +SKIP
... .hide(level=0, axis=0)) # doctest: +SKIP

Note that one of the string entries of the index and column headers is "H&M".
Without applying the `escape="latex"` option to the `format_index` method the
Expand All @@ -982,8 +982,8 @@ def to_latex(
... elif v == "Sell": color = "#ff5933"
... else: color = "#ffdd33"
... return f"color: {color}; font-weight: bold;"
>>> styler.background_gradient(cmap="inferno", subset="Equity", vmin=0, vmax=1)
... .applymap(rating_color, subset="Rating") # doctest: +SKIP
>>> (styler.background_gradient(cmap="inferno", subset="Equity", vmin=0, vmax=1)
... .applymap(rating_color, subset="Rating")) # doctest: +SKIP

All the above styles will work with HTML (see below) and LaTeX upon conversion:

Expand Down Expand Up @@ -3503,9 +3503,9 @@ def pipe(self, func: Callable, *args, **kwargs):
Since the method returns a ``Styler`` object it can be chained with other
methods as if applying the underlying highlighters directly.

>>> df.style.format("{:.1f}")
>>> (df.style.format("{:.1f}")
... .pipe(some_highlights, min_color="green")
... .highlight_between(left=2, right=5) # doctest: +SKIP
... .highlight_between(left=2, right=5)) # doctest: +SKIP

.. figure:: ../../_static/style/df_pipe_hl2.png

Expand Down
4 changes: 2 additions & 2 deletions pandas/io/formats/style_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,8 +1076,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
Expand Down