Skip to content

Commit bb6fb4e

Browse files
authored
STYLE: Fix errors in doctests (#51356)
* Ignore F821 in setup.cfg * Fix doctest F721 errors * Fix indentation * Remove F821 line * Restore commented lines * Revert template string changes
1 parent d82f9dd commit bb6fb4e

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

pandas/core/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3329,7 +3329,7 @@ def to_latex(
33293329
>>> print(df.to_latex(index=False,
33303330
... formatters={"name": str.upper},
33313331
... float_format="{:.1f}".format,
3332-
... ) # doctest: +SKIP
3332+
... )) # doctest: +SKIP
33333333
\begin{tabular}{lrr}
33343334
\toprule
33353335
name & age & height \\

pandas/errors/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,11 @@ class CSSWarning(UserWarning):
455455
Examples
456456
--------
457457
>>> df = pd.DataFrame({'A': [1, 1, 1]})
458-
>>> df.style.applymap(lambda x: 'background-color: blueGreenRed;')
459-
... .to_excel('styled.xlsx') # doctest: +SKIP
458+
>>> (df.style.applymap(lambda x: 'background-color: blueGreenRed;')
459+
... .to_excel('styled.xlsx')) # doctest: +SKIP
460460
... # CSSWarning: Unhandled color format: 'blueGreenRed'
461-
>>> df.style.applymap(lambda x: 'border: 1px solid red red;')
462-
... .to_excel('styled.xlsx') # doctest: +SKIP
461+
>>> (df.style.applymap(lambda x: 'border: 1px solid red red;')
462+
... .to_excel('styled.xlsx')) # doctest: +SKIP
463463
... # CSSWarning: Too many tokens provided to "border" (expected 1-3)
464464
"""
465465

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

pandas/io/formats/style.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -961,12 +961,12 @@ def to_latex(
961961
Second we will format the display and, since our table is quite wide, will
962962
hide the repeated level-0 of the index:
963963
964-
>>> styler.format(subset="Equity", precision=2)
964+
>>> (styler.format(subset="Equity", precision=2)
965965
... .format(subset="Stats", precision=1, thousands=",")
966966
... .format(subset="Rating", formatter=str.upper)
967967
... .format_index(escape="latex", axis=1)
968968
... .format_index(escape="latex", axis=0)
969-
... .hide(level=0, axis=0) # doctest: +SKIP
969+
... .hide(level=0, axis=0)) # doctest: +SKIP
970970
971971
Note that one of the string entries of the index and column headers is "H&M".
972972
Without applying the `escape="latex"` option to the `format_index` method the
@@ -982,8 +982,8 @@ def to_latex(
982982
... elif v == "Sell": color = "#ff5933"
983983
... else: color = "#ffdd33"
984984
... return f"color: {color}; font-weight: bold;"
985-
>>> styler.background_gradient(cmap="inferno", subset="Equity", vmin=0, vmax=1)
986-
... .applymap(rating_color, subset="Rating") # doctest: +SKIP
985+
>>> (styler.background_gradient(cmap="inferno", subset="Equity", vmin=0, vmax=1)
986+
... .applymap(rating_color, subset="Rating")) # doctest: +SKIP
987987
988988
All the above styles will work with HTML (see below) and LaTeX upon conversion:
989989
@@ -3503,9 +3503,9 @@ def pipe(self, func: Callable, *args, **kwargs):
35033503
Since the method returns a ``Styler`` object it can be chained with other
35043504
methods as if applying the underlying highlighters directly.
35053505
3506-
>>> df.style.format("{:.1f}")
3506+
>>> (df.style.format("{:.1f}")
35073507
... .pipe(some_highlights, min_color="green")
3508-
... .highlight_between(left=2, right=5) # doctest: +SKIP
3508+
... .highlight_between(left=2, right=5)) # doctest: +SKIP
35093509
35103510
.. figure:: ../../_static/style/df_pipe_hl2.png
35113511

pandas/io/formats/style_render.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,8 +1076,8 @@ def format(
10761076
Multiple ``na_rep`` or ``precision`` specifications under the default
10771077
``formatter``.
10781078
1079-
>>> df.style.format(na_rep='MISS', precision=1, subset=[0])
1080-
... .format(na_rep='PASS', precision=2, subset=[1, 2]) # doctest: +SKIP
1079+
>>> (df.style.format(na_rep='MISS', precision=1, subset=[0])
1080+
... .format(na_rep='PASS', precision=2, subset=[1, 2])) # doctest: +SKIP
10811081
0 1 2
10821082
0 MISS 1.00 A
10831083
1 2.0 PASS 3.00

0 commit comments

Comments
 (0)