Skip to content
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

DOC: Fixing EX01 - Added examples #54351

Merged
merged 3 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -66,7 +66,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.NaT \
pandas.io.stata.StataWriter.write_file \
pandas.plotting.deregister_matplotlib_converters \
pandas.plotting.register_matplotlib_converters \
pandas.api.extensions.ExtensionArray \
RET=$(($RET + $?)) ; echo $MSG "DONE"

Expand Down
23 changes: 23 additions & 0 deletions pandas/plotting/_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,29 @@ def register() -> None:
See Also
--------
deregister_matplotlib_converters : Remove pandas formatters and converters.

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

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

>>> pd.plotting.register_matplotlib_converters()
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.

Can we remove this line? I think pandas should do it automatically

Could we explain that pandas does this automatically?

Copy link
Member

Choose a reason for hiding this comment

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

And then note that if we manually prevent it from happening, then plotting for period fails

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

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 added the first line because of Sphinx local fail.


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

Unsetting the register manually an error will be raised:

>>> pd.set_option("plotting.matplotlib.register_converters",
... False) # doctest: +SKIP
>>> df.plot.line(x='ts', y='y') # doctest: +SKIP
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.register()
Expand Down