Skip to content

Commit 5023f2e

Browse files
authored
Address some upcoming deprecations (#3820)
* 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
1 parent 385e546 commit 5023f2e

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

seaborn/_compat.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,9 @@ def groupby_apply_include_groups(val):
121121
if _version_predates(pd, "2.2.0"):
122122
return {}
123123
return {"include_groups": val}
124+
125+
126+
def get_converter(axis):
127+
if _version_predates(mpl, "3.10.0"):
128+
return axis.converter
129+
return axis.get_converter()

seaborn/categorical.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,8 @@ def get_props(element, artist=mpl.lines.Line2D):
626626
props["whisker"].setdefault("solid_capstyle", "butt")
627627
props["flier"].setdefault("markersize", fliersize)
628628

629+
orientation = {"x": "vertical", "y": "horizontal"}[self.orient]
630+
629631
ax = self.ax
630632

631633
for sub_vars, sub_data in self.iter_data(iter_vars,
@@ -682,14 +684,20 @@ def get_props(element, artist=mpl.lines.Line2D):
682684
# Set width to 0 to avoid going out of domain
683685
widths=data["width"] if linear_orient_scale else 0,
684686
patch_artist=fill,
685-
vert=self.orient == "x",
686687
manage_ticks=False,
687688
boxprops=boxprops,
688689
medianprops=medianprops,
689690
whiskerprops=whiskerprops,
690691
flierprops=flierprops,
691692
capprops=capprops,
692-
# Added in matplotlib 3.6.0; see below
693+
# Added in matplotlib 3.10; see below
694+
# orientation=orientation
695+
**(
696+
{"vert": orientation == "vertical"}
697+
if _version_predates(mpl, "3.10.0")
698+
else {"orientation": orientation}
699+
),
700+
# added in matplotlib 3.6.0; see below
693701
# capwidths=capwidth,
694702
**(
695703
{} if _version_predates(mpl, "3.6.0")

tests/test_base.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pandas.testing import assert_frame_equal
1010

1111
from seaborn.axisgrid import FacetGrid
12-
from seaborn._compat import get_colormap
12+
from seaborn._compat import get_colormap, get_converter
1313
from seaborn._base import (
1414
SemanticMapping,
1515
HueMapping,
@@ -454,7 +454,7 @@ def test_map_size_categorical(self, long_df):
454454
def test_array_palette_deprecation(self, long_df):
455455

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

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

11421142
def test_attach_facets(self, long_df):
11431143

@@ -1340,7 +1340,6 @@ def test_comp_data_category_order(self):
13401340
["numeric", "category", "datetime"],
13411341
)
13421342
)
1343-
@pytest.mark.parametrize("NA,var_type")
13441343
def comp_data_missing_fixture(self, request):
13451344

13461345
# This fixture holds the logic for parameterizing

tests/test_categorical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ def check_boxen(self, patches, data, orient, pos, width=0.8):
12061206

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

0 commit comments

Comments
 (0)