Skip to content

DOC: Fixing EX01 - Added examples #54039

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
Jul 13, 2023
4 changes: 0 additions & 4 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.DatetimeIndex.snap \
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 \
Expand Down Expand Up @@ -157,8 +155,6 @@ 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.ffill \
pandas.DataFrame.pad \
pandas.DataFrame.swapaxes \
pandas.DataFrame.plot \
Expand Down
19 changes: 18 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -11849,7 +11849,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')
Comment on lines +11865 to +11866
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't believe there wasn't an example for this 😄

"""
),
)

# ----------------------------------------------------------------------
# Add plotting methods to DataFrame
Expand Down
23 changes: 23 additions & 0 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,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:
`Table Visualization <../../user_guide/style.ipynb>`_ for more examples.
"""

def __init__(
Expand Down Expand Up @@ -3492,6 +3502,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a bit slow here but I would have commented that the IPython import and the HTML(..) command are unnecessary. Printing HTML and display in a Jupyter notebook would have worked regardless. These additions just obfuscate the example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @attack68

cool, can we address this as part of a follow-up @DeaMariaLeon please?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might be minimalist if the path and file are moved into the arguments without being pre-defined.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure @MarcoGorelli
Thanks for the review @attack68

Copy link
Member Author

@DeaMariaLeon DeaMariaLeon Jul 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HTML and importing IPython are also in the User Guide.

Edit: I hope my link works! and marking @MarcoGorelli in case he didn't see this last comment. It's just FYI - not a complain.

Copy link
Contributor

@attack68 attack68 Jul 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HTML and importing IPython are also in the [User Guide]

They are but are not necessary here, since these documentation examples do not render HTML.

How a user chooses to render the generated HTML produced via Object.to_html, e.g. in a browser file, in Jupyter Notebook, in an Email or a Javascript component, is not within scope for this documentation example.

The User Guide is different. It is written in Jupyter Notebook, so the inclusions of iPython HTML is included to ensure that the correct HTML is rendered within the notebook correctly, and the only reason it is needed is because a keyword argument is passed to the to_html.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok that's clear. What is not clear to me is how useful my Styler examples are when there are not images at all.


Please see:
`Table Visualization <../../user_guide/style.ipynb>`_ for more examples.
"""
loader = jinja2.ChoiceLoader([jinja2.FileSystemLoader(searchpath), cls.loader])

Expand Down