Skip to content

Commit cda0f6b

Browse files
authored
TST: Address MPL 3.6 deprecation warnings (#48695)
* TST: Address MPL 3.6 deprecation warnings * Address min build * missing ()
1 parent 36a67f6 commit cda0f6b

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

pandas/io/formats/style.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -3934,7 +3934,15 @@ def _background_gradient(
39343934
rng = smax - smin
39353935
# extend lower / upper bounds, compresses color range
39363936
norm = mpl.colors.Normalize(smin - (rng * low), smax + (rng * high))
3937-
rgbas = plt.cm.get_cmap(cmap)(norm(gmap))
3937+
from pandas.plotting._matplotlib.compat import mpl_ge_3_6_0
3938+
3939+
if mpl_ge_3_6_0():
3940+
if cmap is None:
3941+
rgbas = mpl.colormaps[mpl.rcParams["image.cmap"]](norm(gmap))
3942+
else:
3943+
rgbas = mpl.colormaps[cmap](norm(gmap))
3944+
else:
3945+
rgbas = plt.cm.get_cmap(cmap)(norm(gmap))
39383946

39393947
def relative_luminance(rgba) -> float:
39403948
"""
@@ -4213,8 +4221,10 @@ def css_calc(x, left: float, right: float, align: str, color: str | list | tuple
42134221
if cmap is not None:
42144222
# use the matplotlib colormap input
42154223
with _mpl(Styler.bar) as (plt, mpl):
4224+
from pandas.plotting._matplotlib.compat import mpl_ge_3_6_0
4225+
42164226
cmap = (
4217-
mpl.cm.get_cmap(cmap)
4227+
(mpl.colormaps[cmap] if mpl_ge_3_6_0() else mpl.cm.get_cmap(cmap))
42184228
if isinstance(cmap, str)
42194229
else cmap # assumed to be a Colormap instance as documented
42204230
)

pandas/tests/io/formats/style/test_matplotlib.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import matplotlib as mpl
1414

1515
from pandas.io.formats.style import Styler
16+
from pandas.plotting._matplotlib.compat import mpl_ge_3_6_0
1617

1718

1819
@pytest.fixture
@@ -260,7 +261,10 @@ def test_background_gradient_gmap_wrong_series(styler_blank):
260261
styler_blank.background_gradient(gmap=gmap, axis=None)._compute()
261262

262263

263-
@pytest.mark.parametrize("cmap", ["PuBu", mpl.cm.get_cmap("PuBu")])
264+
@pytest.mark.parametrize(
265+
"cmap",
266+
["PuBu", mpl.colormaps["PuBu"] if mpl_ge_3_6_0() else mpl.cm.get_cmap("PuBu")],
267+
)
264268
def test_bar_colormap(cmap):
265269
data = DataFrame([[1, 2], [3, 4]])
266270
ctx = data.style.bar(cmap=cmap, axis=None)._compute().ctx

pandas/tests/plotting/common.py

+4
Original file line numberDiff line numberDiff line change
@@ -479,25 +479,29 @@ def is_grid_on():
479479
mpl.rc("axes", grid=False)
480480
obj.plot(kind=kind, **kws)
481481
assert not is_grid_on()
482+
self.plt.clf()
482483

483484
self.plt.subplot(1, 4 * len(kinds), spndx)
484485
spndx += 1
485486
mpl.rc("axes", grid=True)
486487
obj.plot(kind=kind, grid=False, **kws)
487488
assert not is_grid_on()
489+
self.plt.clf()
488490

489491
if kind not in ["pie", "hexbin", "scatter"]:
490492
self.plt.subplot(1, 4 * len(kinds), spndx)
491493
spndx += 1
492494
mpl.rc("axes", grid=True)
493495
obj.plot(kind=kind, **kws)
494496
assert is_grid_on()
497+
self.plt.clf()
495498

496499
self.plt.subplot(1, 4 * len(kinds), spndx)
497500
spndx += 1
498501
mpl.rc("axes", grid=False)
499502
obj.plot(kind=kind, grid=True, **kws)
500503
assert is_grid_on()
504+
self.plt.clf()
501505

502506
def _unpack_cycler(self, rcParams, field="color"):
503507
"""

0 commit comments

Comments
 (0)