Skip to content

DOC: Fixing EX01 - Added examples #54354

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 4 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
MSG='Partially validate docstrings (EX01)' ; echo $MSG
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \
pandas.io.stata.StataWriter.write_file \
pandas.plotting.deregister_matplotlib_converters \
pandas.api.extensions.ExtensionArray \
RET=$(($RET + $?)) ; echo $MSG "DONE"

Expand Down
22 changes: 22 additions & 0 deletions pandas/plotting/_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,28 @@ def deregister() -> None:
--------
register_matplotlib_converters : Register pandas formatters and converters
with matplotlib.

Examples
--------
.. plot::
:context: close-figs

The following line is done automatically by pandas so
the plot can be rendered:

>>> pd.plotting.register_matplotlib_converters()

>>> df = pd.DataFrame({'ts': pd.period_range('2020', periods=2, freq='M'),
... 'y': [1, 2]
... })
>>> plot = df.plot.line(x='ts', y='y')

Using deregister an error will be raised:

>>> pd.plotting.deregister_matplotlib_converters() # doctest: +SKIP
>>> df.plot.line(x='ts', y='y') # doctest: +SKIP
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it does, because df.plot automatically re-enables it

I think we can just use the same example from the other one

Copy link
Member Author

Choose a reason for hiding this comment

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

It did it locally, but I can change it of course.

Copy link
Member

Choose a reason for hiding this comment

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

don't know, it plots fine for me

image

Copy link
Member Author

Choose a reason for hiding this comment

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

I have these lines on another cell and fails very nice :-)

pd.plotting.deregister_matplotlib_converters()
df.plot.line(x='ts', y='y') 

Copy link
Member Author

Choose a reason for hiding this comment

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

.. but don't worry I'll change it.

Copy link
Member

@MarcoGorelli MarcoGorelli Aug 1, 2023

Choose a reason for hiding this comment

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

🤔 don't know then - are they the only two cells in the notebook? does it still fail if you only have those two and restart and run all?

image

Copy link
Member Author

Choose a reason for hiding this comment

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

Soooooorry, there was a pd.set_option("plotting.matplotlib.deregister_converters", True) hidden making the trick.

Traceback (most recent call last):
TypeError: float() argument must be a string or a real number, not 'Period'
"""
plot_backend = _get_plot_backend("matplotlib")
plot_backend.deregister()
Expand Down