From f62b1c28be001a404813b4e284f64e53c4a42d2b Mon Sep 17 00:00:00 2001 From: aneesh kulkarni Date: Wed, 28 Jul 2021 23:36:42 +0530 Subject: [PATCH 1/3] TST: Fix for doctest in style_render.py -> pandas.io.formats.style_render.StylerRenderer.format --- pandas/io/formats/style_render.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pandas/io/formats/style_render.py b/pandas/io/formats/style_render.py index f1c5f3ac3a2bd..b7eefd4b767ea 100644 --- a/pandas/io/formats/style_render.py +++ b/pandas/io/formats/style_render.py @@ -646,21 +646,21 @@ def format( Using ``na_rep`` and ``precision`` with the default ``formatter`` >>> df = pd.DataFrame([[np.nan, 1.0, 'A'], [2.0, np.nan, 3.0]]) - >>> df.style.format(na_rep='MISS', precision=3) + >>> df.style.format(na_rep='MISS', precision=3) # doctest: +SKIP 0 1 2 0 MISS 1.000 A 1 2.000 MISS 3.000 Using a ``formatter`` specification on consistent column dtypes - >>> df.style.format('{:.2f}', na_rep='MISS', subset=[0,1]) + >>> 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) + >>> 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 @@ -668,8 +668,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]) + >>> 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 @@ -677,7 +677,7 @@ 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') + >>> 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 @@ -687,8 +687,8 @@ def format( >>> df = pd.DataFrame([['
', '"A&B"', None]]) >>> s = df.style.format( ... '{0}', escape="html", na_rep="NA" - ... ) - >>> s.render() + ... ) + >>> s.render() # doctest: +SKIP ... <div></div> "A&B" @@ -698,7 +698,7 @@ def format( Using a ``formatter`` with LaTeX ``escape``. >>> df = pd.DataFrame([["123"], ["~ ^"], ["$%#"]]) - >>> s = df.style.format("\\textbf{{{}}}", escape="latex").to_latex() + >>> s = df.style.format("\\textbf{{{}}}", escape="latex").to_latex() # doctest: +SKIP \begin{tabular}{ll} {} & {0} \\ 0 & \textbf{123} \\ From 6cc25f52cd651d510756415290b125f805107cb3 Mon Sep 17 00:00:00 2001 From: aneesh kulkarni Date: Wed, 28 Jul 2021 23:52:09 +0530 Subject: [PATCH 2/3] Fixed PEP8 Issues --- pandas/io/formats/style_render.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pandas/io/formats/style_render.py b/pandas/io/formats/style_render.py index b7eefd4b767ea..e306dab078ac4 100644 --- a/pandas/io/formats/style_render.py +++ b/pandas/io/formats/style_render.py @@ -660,7 +660,8 @@ def format( 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 @@ -668,7 +669,7 @@ def format( Multiple ``na_rep`` or ``precision`` specifications under the default ``formatter``. - >>> df.style.format(na_rep='MISS', precision=1, subset=[0]) + >>> 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 @@ -677,7 +678,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 @@ -687,7 +689,7 @@ def format( >>> df = pd.DataFrame([['
', '"A&B"', None]]) >>> s = df.style.format( ... '{0}', escape="html", na_rep="NA" - ... ) + ... ) >>> s.render() # doctest: +SKIP ... <div></div> From 000bfc22ed4ba875d7342a8a11728fa8527432bb Mon Sep 17 00:00:00 2001 From: aneesh kulkarni Date: Thu, 29 Jul 2021 23:36:33 +0530 Subject: [PATCH 3/3] Fixed Whitespace & Longline PEP8 issues --- pandas/io/formats/style_render.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pandas/io/formats/style_render.py b/pandas/io/formats/style_render.py index e306dab078ac4..b64e8bbcc9a7d 100644 --- a/pandas/io/formats/style_render.py +++ b/pandas/io/formats/style_render.py @@ -646,22 +646,22 @@ def format( Using ``na_rep`` and ``precision`` with the default ``formatter`` >>> df = pd.DataFrame([[np.nan, 1.0, 'A'], [2.0, np.nan, 3.0]]) - >>> df.style.format(na_rep='MISS', precision=3) # doctest: +SKIP + >>> df.style.format(na_rep='MISS', precision=3) # doctest: +SKIP 0 1 2 0 MISS 1.000 A 1 2.000 MISS 3.000 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 @@ -670,7 +670,7 @@ def format( ``formatter``. >>> df.style.format(na_rep='MISS', precision=1, subset=[0]) - ... .format(na_rep='PASS', precision=2, subset=[1, 2]) # doctest: +SKIP + ... .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 @@ -678,8 +678,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 @@ -690,7 +690,7 @@ def format( >>> s = df.style.format( ... '{0}', escape="html", na_rep="NA" ... ) - >>> s.render() # doctest: +SKIP + >>> s.render() # doctest: +SKIP ... <div></div> "A&B" @@ -700,7 +700,8 @@ def format( Using a ``formatter`` with LaTeX ``escape``. >>> df = pd.DataFrame([["123"], ["~ ^"], ["$%#"]]) - >>> s = df.style.format("\\textbf{{{}}}", escape="latex").to_latex() # doctest: +SKIP + >>> df.style.format("\\textbf{{{}}}", escape="latex").to_latex() + ... # doctest: +SKIP \begin{tabular}{ll} {} & {0} \\ 0 & \textbf{123} \\