From bce90d523b8107a9d11125181cb19852bc9df520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Fri, 7 Jul 2023 18:07:35 +0200 Subject: [PATCH 1/5] Examples Styler, from_custom_template, DataFrame.columns --- ci/code_checks.sh | 4 ---- pandas/core/frame.py | 19 ++++++++++++++++++- pandas/io/formats/style.py | 23 +++++++++++++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index bf0711dcc0581..528e333d5200f 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -118,8 +118,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.core.window.ewm.ExponentialMovingWindow.cov \ pandas.api.indexers.BaseIndexer \ pandas.api.indexers.VariableOffsetWindowIndexer \ - pandas.io.formats.style.Styler \ - pandas.io.formats.style.Styler.from_custom_template \ pandas.io.formats.style.Styler.set_caption \ pandas.io.formats.style.Styler.set_sticky \ pandas.io.formats.style.Styler.set_uuid \ @@ -163,9 +161,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.api.extensions.ExtensionArray.ndim \ pandas.api.extensions.ExtensionArray.shape \ pandas.api.extensions.ExtensionArray.tolist \ - pandas.DataFrame.columns \ pandas.DataFrame.backfill \ - pandas.DataFrame.ffill \ pandas.DataFrame.pad \ pandas.DataFrame.swapaxes \ pandas.DataFrame.attrs \ diff --git a/pandas/core/frame.py b/pandas/core/frame.py index ae43a44d68f1c..52ecb39b850e7 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -11846,7 +11846,24 @@ def isin_(x): updated with the new labels, and the output shows the modified DataFrame. """, ) - columns = properties.AxisProperty(axis=0, doc="The column labels of the DataFrame.") + columns = properties.AxisProperty( + axis=0, + doc=dedent( + """ + The column labels of the DataFrame. + + Examples + -------- + >>> df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]}) + >>> df + A B + 0 1 3 + 1 2 4 + >>> df.columns + Index(['A', 'B'], dtype='object') + """ + ), + ) # ---------------------------------------------------------------------- # Add plotting methods to DataFrame diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index c599bcbfd4170..06b522d413722 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -238,6 +238,16 @@ class Styler(StylerRenderer): Any, or all, or these classes can be renamed by using the ``css_class_names`` argument in ``Styler.set_table_classes``, giving a value such as *{"row": "MY_ROW_CLASS", "col_trim": "", "row_trim": ""}*. + + Examples + -------- + >>> df = pd.DataFrame([[1.0, 2.0, 3.0], [4, 5, 6]], index=['a', 'b'], + ... columns=['A', 'B', 'C']) + >>> pd.io.formats.style.Styler(df, precision=2, + ... caption="My table") # doctest: +SKIP + + Please see: + :ref:`Table Visualization for more examples `. """ def __init__( @@ -3489,6 +3499,19 @@ def from_custom_template( MyStyler : subclass of Styler Has the correct ``env``,``template_html``, ``template_html_table`` and ``template_html_style`` class attributes set. + + Examples + -------- + >>> from pandas.io.formats.style import Styler # doctest: +SKIP + >>> from IPython.display import HTML # doctest: +SKIP + >>> df = pd.DataFrame({"A": [1, 2]}) # doctest: +SKIP + >>> path = "path/to/template" # doctest: +SKIP + >>> file = "template.tpl" # doctest: +SKIP + >>> EasyStyler = Styler.from_custom_template(path, file) # doctest: +SKIP + >>> HTML(EasyStyler(df).to_html(table_title="Another Title")) # doctest: +SKIP + + Please see: + :ref:`Table Visualization for more examples Date: Sat, 8 Jul 2023 08:03:31 +0200 Subject: [PATCH 2/5] Edit link --- pandas/io/formats/style.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 06b522d413722..f8cd7eaa00619 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -246,8 +246,7 @@ class Styler(StylerRenderer): >>> pd.io.formats.style.Styler(df, precision=2, ... caption="My table") # doctest: +SKIP - Please see: - :ref:`Table Visualization for more examples `. + Please see :ref:`Table Visualization ` for more examples. """ def __init__( @@ -3510,8 +3509,7 @@ def from_custom_template( >>> EasyStyler = Styler.from_custom_template(path, file) # doctest: +SKIP >>> HTML(EasyStyler(df).to_html(table_title="Another Title")) # doctest: +SKIP - Please see: - :ref:`Table Visualization for more examples ` for more examples. """ loader = jinja2.ChoiceLoader([jinja2.FileSystemLoader(searchpath), cls.loader]) From cac2c5fb606d31820e25e1d0134df6a10e93d4ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Tue, 11 Jul 2023 11:57:35 +0200 Subject: [PATCH 3/5] Fixing links --- pandas/io/formats/style.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index f8cd7eaa00619..30e55947d6873 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -246,7 +246,8 @@ class Styler(StylerRenderer): >>> pd.io.formats.style.Styler(df, precision=2, ... caption="My table") # doctest: +SKIP - Please see :ref:`Table Visualization ` for more examples. + Please see: + :ref:Table Visualization <../../user_guide/style.ipynb>`_ for more examples. """ def __init__( @@ -3509,7 +3510,8 @@ def from_custom_template( >>> EasyStyler = Styler.from_custom_template(path, file) # doctest: +SKIP >>> HTML(EasyStyler(df).to_html(table_title="Another Title")) # doctest: +SKIP - Please see :ref:`Table Visualization ` for more examples. + Please see: + :ref:Table Visualization <../../user_guide/style.ipynb>`_ for more examples. """ loader = jinja2.ChoiceLoader([jinja2.FileSystemLoader(searchpath), cls.loader]) From 31cb410c7de06461d042152b2aa11ede1c76638d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Tue, 11 Jul 2023 16:00:41 +0200 Subject: [PATCH 4/5] Link again --- pandas/io/formats/style.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 7d60007d637b4..153dde666928f 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -250,7 +250,7 @@ class Styler(StylerRenderer): ... caption="My table") # doctest: +SKIP Please see: - :ref:Table Visualization <../../user_guide/style.ipynb>`_ for more examples. + :ref:`Table Visualization <../../user_guide/style.ipynb>`_ for more examples. """ def __init__( @@ -3514,7 +3514,7 @@ def from_custom_template( >>> HTML(EasyStyler(df).to_html(table_title="Another Title")) # doctest: +SKIP Please see: - :ref:Table Visualization <../../user_guide/style.ipynb>`_ for more examples. + :ref:`Table Visualization <../../user_guide/style.ipynb>`_ for more examples. """ loader = jinja2.ChoiceLoader([jinja2.FileSystemLoader(searchpath), cls.loader]) From ab8d8539bdde9fdb160fe1544a0d5ef802a0980b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Tue, 11 Jul 2023 19:13:13 +0200 Subject: [PATCH 5/5] Trying that link again --- pandas/io/formats/style.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 153dde666928f..278527fa8fc85 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -250,7 +250,7 @@ class Styler(StylerRenderer): ... caption="My table") # doctest: +SKIP Please see: - :ref:`Table Visualization <../../user_guide/style.ipynb>`_ for more examples. + `Table Visualization <../../user_guide/style.ipynb>`_ for more examples. """ def __init__( @@ -3514,7 +3514,7 @@ def from_custom_template( >>> HTML(EasyStyler(df).to_html(table_title="Another Title")) # doctest: +SKIP Please see: - :ref:`Table Visualization <../../user_guide/style.ipynb>`_ for more examples. + `Table Visualization <../../user_guide/style.ipynb>`_ for more examples. """ loader = jinja2.ChoiceLoader([jinja2.FileSystemLoader(searchpath), cls.loader])