Skip to content

Commit c10ae89

Browse files
committed
tst/cln: check userwarnings
1 parent 3944a36 commit c10ae89

File tree

3 files changed

+192
-112
lines changed

3 files changed

+192
-112
lines changed

pandas/tests/test_graphics.py

+77-46
Original file line numberDiff line numberDiff line change
@@ -820,10 +820,13 @@ def test_hist_legacy(self):
820820
_check_plot_works(self.ts.hist)
821821
_check_plot_works(self.ts.hist, grid=False)
822822
_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)
823+
# _check_plot_works adds an ax so catch warning. see GH #13188
824+
with tm.assert_produces_warning(UserWarning):
825+
_check_plot_works(self.ts.hist,
826+
by=self.ts.index.month)
827+
with tm.assert_produces_warning(UserWarning):
828+
_check_plot_works(self.ts.hist,
829+
by=self.ts.index.month, bins=5)
827830

828831
fig, ax = self.plt.subplots(1, 1)
829832
_check_plot_works(self.ts.hist, ax=ax)
@@ -857,32 +860,40 @@ def test_hist_layout(self):
857860
def test_hist_layout_with_by(self):
858861
df = self.hist_df
859862

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

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

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

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

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

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

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

888899
axes = df.height.hist(by=df.category, layout=(4, 2), figsize=(12, 7))
@@ -1300,17 +1311,21 @@ def setUp(self):
13001311
@slow
13011312
def test_plot(self):
13021313
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)
1314+
_check_plot_works(df.plot, grid=False)
1315+
# _check_plot_works adds an ax so catch warning. see GH #13188
1316+
with tm.assert_produces_warning(UserWarning):
1317+
axes = _check_plot_works(df.plot,
1318+
subplots=True)
13061319
self._check_axes_shape(axes, axes_num=4, layout=(4, 1))
13071320

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

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

13161331
df = DataFrame({'x': [1, 2], 'y': [3, 4]})
@@ -1326,8 +1341,8 @@ def test_plot(self):
13261341
_check_plot_works(df.plot, xticks=[1, 5, 10])
13271342
_check_plot_works(df.plot, ylim=(-100, 100), xlim=(-100, 100))
13281343

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

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

22182233
_check_plot_works(df.plot.bar)
22192234
_check_plot_works(df.plot.bar, legend=False)
2220-
_check_plot_works(df.plot.bar, filterwarnings='ignore', subplots=True)
2235+
# _check_plot_works adds an ax so catch warning. see GH #13188
2236+
with tm.assert_produces_warning(UserWarning):
2237+
_check_plot_works(df.plot.bar, subplots=True)
22212238
_check_plot_works(df.plot.bar, stacked=True)
22222239

22232240
df = DataFrame(randn(10, 15),
@@ -2433,8 +2450,10 @@ def test_boxplot_vertical(self):
24332450
self._check_text_labels(ax.get_yticklabels(), labels)
24342451
self.assertEqual(len(ax.lines), self.bp_n_objects * len(numeric_cols))
24352452

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

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

25012521
axes = df.plot(kind='kde', logy=True, subplots=True)
@@ -2522,8 +2542,9 @@ def test_hist_df(self):
25222542
expected = [pprint_thing(c) for c in df.columns]
25232543
self._check_legend_labels(ax, labels=expected)
25242544

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

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

29082930
rgba_colors = lmap(cm.jet, np.linspace(0, 1, len(df)))
29092931
for cmap in ['jet', cm.jet]:
@@ -3294,8 +3316,10 @@ def test_pie_df(self):
32943316
ax = _check_plot_works(df.plot.pie, y=2)
32953317
self._check_text_labels(ax.texts, df.index)
32963318

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

33053329
labels = ['A', 'B', 'C', 'D', 'E']
33063330
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)
3331+
with tm.assert_produces_warning(UserWarning):
3332+
axes = _check_plot_works(df.plot.pie,
3333+
subplots=True, labels=labels,
3334+
colors=color_args)
33103335
self.assertEqual(len(axes), len(df.columns))
33113336

33123337
for ax in axes:
@@ -3362,9 +3387,12 @@ def test_errorbar_plot(self):
33623387
self._check_has_errorbars(ax, xerr=2, yerr=2)
33633388
ax = _check_plot_works(df.plot, xerr=0.2, yerr=0.2, kind=kind)
33643389
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)
3390+
# _check_plot_works adds an ax so catch warning. see GH #13188
3391+
with tm.assert_produces_warning(UserWarning):
3392+
axes = _check_plot_works(df.plot,
3393+
yerr=df_err, xerr=df_err,
3394+
subplots=True,
3395+
kind=kind)
33683396
self._check_has_errorbars(axes, xerr=1, yerr=1)
33693397

33703398
ax = _check_plot_works((df + 1).plot, yerr=df_err,
@@ -3455,8 +3483,11 @@ def test_errorbar_timeseries(self):
34553483
self._check_has_errorbars(ax, xerr=0, yerr=1)
34563484
ax = _check_plot_works(tdf.plot, yerr=tdf_err, kind=kind)
34573485
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)
3486+
# _check_plot_works adds an ax so catch warning. see GH #13188
3487+
with tm.assert_produces_warning(UserWarning):
3488+
axes = _check_plot_works(tdf.plot,
3489+
kind=kind, yerr=tdf_err,
3490+
subplots=True)
34603491
self._check_has_errorbars(axes, xerr=0, yerr=1)
34613492

34623493
def test_errorbar_asymmetrical(self):

0 commit comments

Comments
 (0)