Skip to content

Commit

Permalink
Address some upcoming deprecations (#3820)
Browse files Browse the repository at this point in the history
* Address matplotlib bxp vert= deprecation

* Address np.in1d deprecation

* Address converter attribute deprecation

* Address parameterized fixture deprecation

* Address false-positive internal deprecation warning

* Fix boxplot backcompat
  • Loading branch information
mwaskom authored Jan 26, 2025
1 parent 385e546 commit 5023f2e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
6 changes: 6 additions & 0 deletions seaborn/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,9 @@ def groupby_apply_include_groups(val):
if _version_predates(pd, "2.2.0"):
return {}
return {"include_groups": val}


def get_converter(axis):
if _version_predates(mpl, "3.10.0"):
return axis.converter
return axis.get_converter()
12 changes: 10 additions & 2 deletions seaborn/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,8 @@ def get_props(element, artist=mpl.lines.Line2D):
props["whisker"].setdefault("solid_capstyle", "butt")
props["flier"].setdefault("markersize", fliersize)

orientation = {"x": "vertical", "y": "horizontal"}[self.orient]

ax = self.ax

for sub_vars, sub_data in self.iter_data(iter_vars,
Expand Down Expand Up @@ -682,14 +684,20 @@ def get_props(element, artist=mpl.lines.Line2D):
# Set width to 0 to avoid going out of domain
widths=data["width"] if linear_orient_scale else 0,
patch_artist=fill,
vert=self.orient == "x",
manage_ticks=False,
boxprops=boxprops,
medianprops=medianprops,
whiskerprops=whiskerprops,
flierprops=flierprops,
capprops=capprops,
# Added in matplotlib 3.6.0; see below
# Added in matplotlib 3.10; see below
# orientation=orientation
**(
{"vert": orientation == "vertical"}
if _version_predates(mpl, "3.10.0")
else {"orientation": orientation}
),
# added in matplotlib 3.6.0; see below
# capwidths=capwidth,
**(
{} if _version_predates(mpl, "3.6.0")
Expand Down
13 changes: 6 additions & 7 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pandas.testing import assert_frame_equal

from seaborn.axisgrid import FacetGrid
from seaborn._compat import get_colormap
from seaborn._compat import get_colormap, get_converter
from seaborn._base import (
SemanticMapping,
HueMapping,
Expand Down Expand Up @@ -454,7 +454,7 @@ def test_map_size_categorical(self, long_df):
def test_array_palette_deprecation(self, long_df):

p = VectorPlotter(long_df, {"y": "y", "hue": "s"})
pal = mpl.cm.Blues([.3, .8])[:, :3]
pal = mpl.cm.Blues([.3, .5, .8])[:, :3]
with pytest.warns(UserWarning, match="Numpy array is not a supported type"):
m = HueMapping(p, pal)
assert m.palette == pal.tolist()
Expand Down Expand Up @@ -1130,14 +1130,14 @@ def test_attach_converters(self, long_df):
_, ax = plt.subplots()
p = VectorPlotter(data=long_df, variables={"x": "x", "y": "t"})
p._attach(ax)
assert ax.xaxis.converter is None
assert "Date" in ax.yaxis.converter.__class__.__name__
assert get_converter(ax.xaxis) is None
assert "Date" in get_converter(ax.yaxis).__class__.__name__

_, ax = plt.subplots()
p = VectorPlotter(data=long_df, variables={"x": "a", "y": "y"})
p._attach(ax)
assert "CategoryConverter" in ax.xaxis.converter.__class__.__name__
assert ax.yaxis.converter is None
assert "CategoryConverter" in get_converter(ax.xaxis).__class__.__name__
assert get_converter(ax.yaxis) is None

def test_attach_facets(self, long_df):

Expand Down Expand Up @@ -1340,7 +1340,6 @@ def test_comp_data_category_order(self):
["numeric", "category", "datetime"],
)
)
@pytest.mark.parametrize("NA,var_type")
def comp_data_missing_fixture(self, request):

# This fixture holds the logic for parameterizing
Expand Down
2 changes: 1 addition & 1 deletion tests/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ def check_boxen(self, patches, data, orient, pos, width=0.8):

assert verts[pos_idx].min().round(4) >= np.round(pos - width / 2, 4)
assert verts[pos_idx].max().round(4) <= np.round(pos + width / 2, 4)
assert np.in1d(
assert np.isin(
np.percentile(data, [25, 75]).round(4), verts[val_idx].round(4).flat
).all()
assert_array_equal(verts[val_idx, 1:, 0], verts[val_idx, :-1, 2])
Expand Down

0 comments on commit 5023f2e

Please sign in to comment.