Skip to content

Correctly re-instate Matplotlib converters #27481

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 20, 2019
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
3 changes: 3 additions & 0 deletions doc/source/whatsnew/v0.25.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ Plotting
^^^^^^^^

- Added a pandas_plotting_backends entrypoint group for registering plot backends. See :ref:`extending.plotting-backends` for more (:issue:`26747`).
- Fixed the re-instatement of Matplotlib datetime converters after calling
`pandas.plotting.deregister_matplotlib_converters()` (:issue:`27481`).
-
- Fix compatibility issue with matplotlib when passing a pandas ``Index`` to a plot call (:issue:`27775`).
-

Expand Down
7 changes: 4 additions & 3 deletions pandas/plotting/_matplotlib/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ def register(explicit=True):

pairs = get_pairs()
for type_, cls in pairs:
converter = cls()
if type_ in units.registry:
# Cache previous converter if present
if type_ in units.registry and not isinstance(units.registry[type_], cls):
previous = units.registry[type_]
_mpl_units[type_] = previous
units.registry[type_] = converter
# Replace with pandas converter
units.registry[type_] = cls()


def deregister():
Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/plotting/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ def test_initial_warning():
assert "Using an implicitly" in out


def test_registry_mpl_resets():
# Check that Matplotlib converters are properly reset (see issue #27481)
code = (
"import matplotlib.units as units; "
"import matplotlib.dates as mdates; "
"n_conv = len(units.registry); "
"import pandas as pd; "
"pd.plotting.register_matplotlib_converters(); "
"pd.plotting.deregister_matplotlib_converters(); "
"assert len(units.registry) == n_conv"
)
call = [sys.executable, "-c", code]
subprocess.check_output(call)


def test_timtetonum_accepts_unicode():
assert converter.time2num("00:01") == converter.time2num("00:01")

Expand Down