Skip to content

Commit

Permalink
BUG: Correctly reinstate Matplotlib converters (#27481)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstansby authored and TomAugspurger committed Aug 20, 2019
1 parent 69c58da commit e55b698
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
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 @@ -111,6 +111,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

0 comments on commit e55b698

Please sign in to comment.