Skip to content

Commit d38ee27

Browse files
Tom Augspurgerjorisvandenbossche
Tom Augspurger
authored andcommitted
CLN: Check Warnings in test_graphics_others (#13188)
closes #13185 Also a MatplotlibDeprecationWarning for use of .get_axes() vs. .axes in some tests.
1 parent 2134b63 commit d38ee27

File tree

3 files changed

+200
-117
lines changed

3 files changed

+200
-117
lines changed

pandas/tests/test_graphics.py

+80-48
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,9 @@ def _check_box_return_type(self, returned, return_type, expected_keys=None,
450450
self.assertIsInstance(value.lines, dict)
451451
elif return_type == 'dict':
452452
line = value['medians'][0]
453+
axes = line.axes if self.mpl_ge_1_5_0 else line.get_axes()
453454
if check_ax_title:
454-
self.assertEqual(line.get_axes().get_title(), key)
455+
self.assertEqual(axes.get_title(), key)
455456
else:
456457
raise AssertionError
457458

@@ -820,10 +821,13 @@ def test_hist_legacy(self):
820821
_check_plot_works(self.ts.hist)
821822
_check_plot_works(self.ts.hist, grid=False)
822823
_check_plot_works(self.ts.hist, figsize=(8, 10))
823-
_check_plot_works(self.ts.hist, filterwarnings='ignore',
824-
by=self.ts.index.month)
825-
_check_plot_works(self.ts.hist, filterwarnings='ignore',
826-
by=self.ts.index.month, bins=5)
824+
# _check_plot_works adds an ax so catch warning. see GH #13188
825+
with tm.assert_produces_warning(UserWarning):
826+
_check_plot_works(self.ts.hist,
827+
by=self.ts.index.month)
828+
with tm.assert_produces_warning(UserWarning):
829+
_check_plot_works(self.ts.hist,
830+
by=self.ts.index.month, bins=5)
827831

828832
fig, ax = self.plt.subplots(1, 1)
829833
_check_plot_works(self.ts.hist, ax=ax)
@@ -857,32 +861,40 @@ def test_hist_layout(self):
857861
def test_hist_layout_with_by(self):
858862
df = self.hist_df
859863

860-
axes = _check_plot_works(df.height.hist, filterwarnings='ignore',
861-
by=df.gender, layout=(2, 1))
864+
# _check_plot_works adds an ax so catch warning. see GH #13188
865+
with tm.assert_produces_warning(UserWarning):
866+
axes = _check_plot_works(df.height.hist,
867+
by=df.gender, layout=(2, 1))
862868
self._check_axes_shape(axes, axes_num=2, layout=(2, 1))
863869

864-
axes = _check_plot_works(df.height.hist, filterwarnings='ignore',
865-
by=df.gender, layout=(3, -1))
870+
with tm.assert_produces_warning(UserWarning):
871+
axes = _check_plot_works(df.height.hist,
872+
by=df.gender, layout=(3, -1))
866873
self._check_axes_shape(axes, axes_num=2, layout=(3, 1))
867874

868-
axes = _check_plot_works(df.height.hist, filterwarnings='ignore',
869-
by=df.category, layout=(4, 1))
875+
with tm.assert_produces_warning(UserWarning):
876+
axes = _check_plot_works(df.height.hist,
877+
by=df.category, layout=(4, 1))
870878
self._check_axes_shape(axes, axes_num=4, layout=(4, 1))
871879

872-
axes = _check_plot_works(df.height.hist, filterwarnings='ignore',
873-
by=df.category, layout=(2, -1))
880+
with tm.assert_produces_warning(UserWarning):
881+
axes = _check_plot_works(df.height.hist,
882+
by=df.category, layout=(2, -1))
874883
self._check_axes_shape(axes, axes_num=4, layout=(2, 2))
875884

876-
axes = _check_plot_works(df.height.hist, filterwarnings='ignore',
877-
by=df.category, layout=(3, -1))
885+
with tm.assert_produces_warning(UserWarning):
886+
axes = _check_plot_works(df.height.hist,
887+
by=df.category, layout=(3, -1))
878888
self._check_axes_shape(axes, axes_num=4, layout=(3, 2))
879889

880-
axes = _check_plot_works(df.height.hist, filterwarnings='ignore',
881-
by=df.category, layout=(-1, 4))
890+
with tm.assert_produces_warning(UserWarning):
891+
axes = _check_plot_works(df.height.hist,
892+
by=df.category, layout=(-1, 4))
882893
self._check_axes_shape(axes, axes_num=4, layout=(1, 4))
883894

884-
axes = _check_plot_works(df.height.hist, filterwarnings='ignore',
885-
by=df.classroom, layout=(2, 2))
895+
with tm.assert_produces_warning(UserWarning):
896+
axes = _check_plot_works(df.height.hist,
897+
by=df.classroom, layout=(2, 2))
886898
self._check_axes_shape(axes, axes_num=3, layout=(2, 2))
887899

888900
axes = df.height.hist(by=df.category, layout=(4, 2), figsize=(12, 7))
@@ -899,7 +911,7 @@ def test_hist_no_overlap(self):
899911
subplot(122)
900912
y.hist()
901913
fig = gcf()
902-
axes = fig.get_axes()
914+
axes = fig.axes if self.mpl_ge_1_5_0 else fig.get_axes()
903915
self.assertEqual(len(axes), 2)
904916

905917
@slow
@@ -1300,17 +1312,21 @@ def setUp(self):
13001312
@slow
13011313
def test_plot(self):
13021314
df = self.tdf
1303-
_check_plot_works(df.plot, filterwarnings='ignore', grid=False)
1304-
axes = _check_plot_works(df.plot, filterwarnings='ignore',
1305-
subplots=True)
1315+
_check_plot_works(df.plot, grid=False)
1316+
# _check_plot_works adds an ax so catch warning. see GH #13188
1317+
with tm.assert_produces_warning(UserWarning):
1318+
axes = _check_plot_works(df.plot,
1319+
subplots=True)
13061320
self._check_axes_shape(axes, axes_num=4, layout=(4, 1))
13071321

1308-
axes = _check_plot_works(df.plot, filterwarnings='ignore',
1309-
subplots=True, layout=(-1, 2))
1322+
with tm.assert_produces_warning(UserWarning):
1323+
axes = _check_plot_works(df.plot,
1324+
subplots=True, layout=(-1, 2))
13101325
self._check_axes_shape(axes, axes_num=4, layout=(2, 2))
13111326

1312-
axes = _check_plot_works(df.plot, filterwarnings='ignore',
1313-
subplots=True, use_index=False)
1327+
with tm.assert_produces_warning(UserWarning):
1328+
axes = _check_plot_works(df.plot,
1329+
subplots=True, use_index=False)
13141330
self._check_axes_shape(axes, axes_num=4, layout=(4, 1))
13151331

13161332
df = DataFrame({'x': [1, 2], 'y': [3, 4]})
@@ -1326,8 +1342,8 @@ def test_plot(self):
13261342
_check_plot_works(df.plot, xticks=[1, 5, 10])
13271343
_check_plot_works(df.plot, ylim=(-100, 100), xlim=(-100, 100))
13281344

1329-
_check_plot_works(df.plot, filterwarnings='ignore',
1330-
subplots=True, title='blah')
1345+
with tm.assert_produces_warning(UserWarning):
1346+
_check_plot_works(df.plot, subplots=True, title='blah')
13311347

13321348
# We have to redo it here because _check_plot_works does two plots,
13331349
# once without an ax kwarg and once with an ax kwarg and the new sharex
@@ -2217,7 +2233,9 @@ def test_plot_bar(self):
22172233

22182234
_check_plot_works(df.plot.bar)
22192235
_check_plot_works(df.plot.bar, legend=False)
2220-
_check_plot_works(df.plot.bar, filterwarnings='ignore', subplots=True)
2236+
# _check_plot_works adds an ax so catch warning. see GH #13188
2237+
with tm.assert_produces_warning(UserWarning):
2238+
_check_plot_works(df.plot.bar, subplots=True)
22212239
_check_plot_works(df.plot.bar, stacked=True)
22222240

22232241
df = DataFrame(randn(10, 15),
@@ -2433,8 +2451,10 @@ def test_boxplot_vertical(self):
24332451
self._check_text_labels(ax.get_yticklabels(), labels)
24342452
self.assertEqual(len(ax.lines), self.bp_n_objects * len(numeric_cols))
24352453

2436-
axes = _check_plot_works(df.plot.box, filterwarnings='ignore',
2437-
subplots=True, vert=False, logx=True)
2454+
# _check_plot_works adds an ax so catch warning. see GH #13188
2455+
with tm.assert_produces_warning(UserWarning):
2456+
axes = _check_plot_works(df.plot.box,
2457+
subplots=True, vert=False, logx=True)
24382458
self._check_axes_shape(axes, axes_num=3, layout=(1, 3))
24392459
self._check_ax_scales(axes, xaxis='log')
24402460
for ax, label in zip(axes, labels):
@@ -2494,8 +2514,9 @@ def test_kde_df(self):
24942514
ax = df.plot(kind='kde', rot=20, fontsize=5)
24952515
self._check_ticks_props(ax, xrot=20, xlabelsize=5, ylabelsize=5)
24962516

2497-
axes = _check_plot_works(df.plot, filterwarnings='ignore', kind='kde',
2498-
subplots=True)
2517+
with tm.assert_produces_warning(UserWarning):
2518+
axes = _check_plot_works(df.plot, kind='kde',
2519+
subplots=True)
24992520
self._check_axes_shape(axes, axes_num=4, layout=(4, 1))
25002521

25012522
axes = df.plot(kind='kde', logy=True, subplots=True)
@@ -2522,8 +2543,9 @@ def test_hist_df(self):
25222543
expected = [pprint_thing(c) for c in df.columns]
25232544
self._check_legend_labels(ax, labels=expected)
25242545

2525-
axes = _check_plot_works(df.plot.hist, filterwarnings='ignore',
2526-
subplots=True, logy=True)
2546+
with tm.assert_produces_warning(UserWarning):
2547+
axes = _check_plot_works(df.plot.hist,
2548+
subplots=True, logy=True)
25272549
self._check_axes_shape(axes, axes_num=4, layout=(4, 1))
25282550
self._check_ax_scales(axes, yaxis='log')
25292551

@@ -2902,8 +2924,9 @@ def test_line_colors_and_styles_subplots(self):
29022924
# Color contains shorthand hex value results in ValueError
29032925
custom_colors = ['#F00', '#00F', '#FF0', '#000', '#FFF']
29042926
# Forced show plot
2905-
_check_plot_works(df.plot, color=custom_colors, subplots=True,
2906-
filterwarnings='ignore')
2927+
# _check_plot_works adds an ax so catch warning. see GH #13188
2928+
with tm.assert_produces_warning(UserWarning):
2929+
_check_plot_works(df.plot, color=custom_colors, subplots=True)
29072930

29082931
rgba_colors = lmap(cm.jet, np.linspace(0, 1, len(df)))
29092932
for cmap in ['jet', cm.jet]:
@@ -3294,8 +3317,10 @@ def test_pie_df(self):
32943317
ax = _check_plot_works(df.plot.pie, y=2)
32953318
self._check_text_labels(ax.texts, df.index)
32963319

3297-
axes = _check_plot_works(df.plot.pie, filterwarnings='ignore',
3298-
subplots=True)
3320+
# _check_plot_works adds an ax so catch warning. see GH #13188
3321+
with tm.assert_produces_warning(UserWarning):
3322+
axes = _check_plot_works(df.plot.pie,
3323+
subplots=True)
32993324
self.assertEqual(len(axes), len(df.columns))
33003325
for ax in axes:
33013326
self._check_text_labels(ax.texts, df.index)
@@ -3304,9 +3329,10 @@ def test_pie_df(self):
33043329

33053330
labels = ['A', 'B', 'C', 'D', 'E']
33063331
color_args = ['r', 'g', 'b', 'c', 'm']
3307-
axes = _check_plot_works(df.plot.pie, filterwarnings='ignore',
3308-
subplots=True, labels=labels,
3309-
colors=color_args)
3332+
with tm.assert_produces_warning(UserWarning):
3333+
axes = _check_plot_works(df.plot.pie,
3334+
subplots=True, labels=labels,
3335+
colors=color_args)
33103336
self.assertEqual(len(axes), len(df.columns))
33113337

33123338
for ax in axes:
@@ -3362,9 +3388,12 @@ def test_errorbar_plot(self):
33623388
self._check_has_errorbars(ax, xerr=2, yerr=2)
33633389
ax = _check_plot_works(df.plot, xerr=0.2, yerr=0.2, kind=kind)
33643390
self._check_has_errorbars(ax, xerr=2, yerr=2)
3365-
axes = _check_plot_works(df.plot, filterwarnings='ignore',
3366-
yerr=df_err, xerr=df_err, subplots=True,
3367-
kind=kind)
3391+
# _check_plot_works adds an ax so catch warning. see GH #13188
3392+
with tm.assert_produces_warning(UserWarning):
3393+
axes = _check_plot_works(df.plot,
3394+
yerr=df_err, xerr=df_err,
3395+
subplots=True,
3396+
kind=kind)
33683397
self._check_has_errorbars(axes, xerr=1, yerr=1)
33693398

33703399
ax = _check_plot_works((df + 1).plot, yerr=df_err,
@@ -3455,8 +3484,11 @@ def test_errorbar_timeseries(self):
34553484
self._check_has_errorbars(ax, xerr=0, yerr=1)
34563485
ax = _check_plot_works(tdf.plot, yerr=tdf_err, kind=kind)
34573486
self._check_has_errorbars(ax, xerr=0, yerr=2)
3458-
axes = _check_plot_works(tdf.plot, filterwarnings='ignore',
3459-
kind=kind, yerr=tdf_err, subplots=True)
3487+
# _check_plot_works adds an ax so catch warning. see GH #13188
3488+
with tm.assert_produces_warning(UserWarning):
3489+
axes = _check_plot_works(tdf.plot,
3490+
kind=kind, yerr=tdf_err,
3491+
subplots=True)
34603492
self._check_has_errorbars(axes, xerr=0, yerr=1)
34613493

34623494
def test_errorbar_asymmetrical(self):

0 commit comments

Comments
 (0)