File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -112,6 +112,9 @@ Plotting
112112^^^^^^^^
113113
114114- Added a pandas_plotting_backends entrypoint group for registering plot backends. See :ref: `extending.plotting-backends ` for more (:issue: `26747 `).
115+ - Fixed the re-instatement of Matplotlib datetime converters after calling
116+ `pandas.plotting.deregister_matplotlib_converters() ` (:issue: `27481 `).
117+ -
115118- Fix compatibility issue with matplotlib when passing a pandas ``Index `` to a plot call (:issue: `27775 `).
116119-
117120
Original file line number Diff line number Diff line change @@ -64,11 +64,12 @@ def register(explicit=True):
6464
6565 pairs = get_pairs ()
6666 for type_ , cls in pairs :
67- converter = cls ()
68- if type_ in units .registry :
67+ # Cache previous converter if present
68+ if type_ in units .registry and not isinstance ( units . registry [ type_ ], cls ) :
6969 previous = units .registry [type_ ]
7070 _mpl_units [type_ ] = previous
71- units .registry [type_ ] = converter
71+ # Replace with pandas converter
72+ units .registry [type_ ] = cls ()
7273
7374
7475def deregister ():
Original file line number Diff line number Diff line change @@ -40,6 +40,21 @@ def test_initial_warning():
4040 assert "Using an implicitly" in out
4141
4242
43+ def test_registry_mpl_resets ():
44+ # Check that Matplotlib converters are properly reset (see issue #27481)
45+ code = (
46+ "import matplotlib.units as units; "
47+ "import matplotlib.dates as mdates; "
48+ "n_conv = len(units.registry); "
49+ "import pandas as pd; "
50+ "pd.plotting.register_matplotlib_converters(); "
51+ "pd.plotting.deregister_matplotlib_converters(); "
52+ "assert len(units.registry) == n_conv"
53+ )
54+ call = [sys .executable , "-c" , code ]
55+ subprocess .check_output (call )
56+
57+
4358def test_timtetonum_accepts_unicode ():
4459 assert converter .time2num ("00:01" ) == converter .time2num ("00:01" )
4560
You can’t perform that action at this time.
0 commit comments