@@ -800,8 +800,8 @@ def test_hist_legacy(self):
800
800
_check_plot_works (self .ts .hist )
801
801
_check_plot_works (self .ts .hist , grid = False )
802
802
_check_plot_works (self .ts .hist , figsize = (8 , 10 ))
803
- _check_plot_works (self .ts .hist , by = self .ts .index .month )
804
- _check_plot_works (self .ts .hist , by = self .ts .index .month , bins = 5 )
803
+ _check_plot_works (self .ts .hist , filterwarnings = 'ignore' , by = self .ts .index .month )
804
+ _check_plot_works (self .ts .hist , filterwarnings = 'ignore' , by = self .ts .index .month , bins = 5 )
805
805
806
806
fig , ax = self .plt .subplots (1 , 1 )
807
807
_check_plot_works (self .ts .hist , ax = ax )
@@ -835,25 +835,32 @@ def test_hist_layout(self):
835
835
def test_hist_layout_with_by (self ):
836
836
df = self .hist_df
837
837
838
- axes = _check_plot_works (df .height .hist , by = df .gender , layout = (2 , 1 ))
838
+ axes = _check_plot_works (df .height .hist , filterwarnings = 'ignore' ,
839
+ by = df .gender , layout = (2 , 1 ))
839
840
self ._check_axes_shape (axes , axes_num = 2 , layout = (2 , 1 ))
840
841
841
- axes = _check_plot_works (df .height .hist , by = df .gender , layout = (3 , - 1 ))
842
+ axes = _check_plot_works (df .height .hist , filterwarnings = 'ignore' ,
843
+ by = df .gender , layout = (3 , - 1 ))
842
844
self ._check_axes_shape (axes , axes_num = 2 , layout = (3 , 1 ))
843
845
844
- axes = _check_plot_works (df .height .hist , by = df .category , layout = (4 , 1 ))
846
+ axes = _check_plot_works (df .height .hist , filterwarnings = 'ignore' ,
847
+ by = df .category , layout = (4 , 1 ))
845
848
self ._check_axes_shape (axes , axes_num = 4 , layout = (4 , 1 ))
846
849
847
- axes = _check_plot_works (df .height .hist , by = df .category , layout = (2 , - 1 ))
850
+ axes = _check_plot_works (df .height .hist , filterwarnings = 'ignore' ,
851
+ by = df .category , layout = (2 , - 1 ))
848
852
self ._check_axes_shape (axes , axes_num = 4 , layout = (2 , 2 ))
849
853
850
- axes = _check_plot_works (df .height .hist , by = df .category , layout = (3 , - 1 ))
854
+ axes = _check_plot_works (df .height .hist , filterwarnings = 'ignore' ,
855
+ by = df .category , layout = (3 , - 1 ))
851
856
self ._check_axes_shape (axes , axes_num = 4 , layout = (3 , 2 ))
852
857
853
- axes = _check_plot_works (df .height .hist , by = df .category , layout = (- 1 , 4 ))
858
+ axes = _check_plot_works (df .height .hist , filterwarnings = 'ignore' ,
859
+ by = df .category , layout = (- 1 , 4 ))
854
860
self ._check_axes_shape (axes , axes_num = 4 , layout = (1 , 4 ))
855
861
856
- axes = _check_plot_works (df .height .hist , by = df .classroom , layout = (2 , 2 ))
862
+ axes = _check_plot_works (df .height .hist , filterwarnings = 'ignore' ,
863
+ by = df .classroom , layout = (2 , 2 ))
857
864
self ._check_axes_shape (axes , axes_num = 3 , layout = (2 , 2 ))
858
865
859
866
axes = df .height .hist (by = df .category , layout = (4 , 2 ), figsize = (12 , 7 ))
@@ -1247,14 +1254,16 @@ def setUp(self):
1247
1254
@slow
1248
1255
def test_plot (self ):
1249
1256
df = self .tdf
1250
- _check_plot_works (df .plot , grid = False )
1251
- axes = _check_plot_works (df .plot , subplots = True )
1257
+ _check_plot_works (df .plot , filterwarnings = 'ignore' , grid = False )
1258
+ axes = _check_plot_works (df .plot , filterwarnings = 'ignore' , subplots = True )
1252
1259
self ._check_axes_shape (axes , axes_num = 4 , layout = (4 , 1 ))
1253
1260
1254
- axes = _check_plot_works (df .plot , subplots = True , layout = (- 1 , 2 ))
1261
+ axes = _check_plot_works (df .plot , filterwarnings = 'ignore' ,
1262
+ subplots = True , layout = (- 1 , 2 ))
1255
1263
self ._check_axes_shape (axes , axes_num = 4 , layout = (2 , 2 ))
1256
1264
1257
- axes = _check_plot_works (df .plot , subplots = True , use_index = False )
1265
+ axes = _check_plot_works (df .plot , filterwarnings = 'ignore' ,
1266
+ subplots = True , use_index = False )
1258
1267
self ._check_axes_shape (axes , axes_num = 4 , layout = (4 , 1 ))
1259
1268
1260
1269
df = DataFrame ({'x' : [1 , 2 ], 'y' : [3 , 4 ]})
@@ -1263,13 +1272,14 @@ def test_plot(self):
1263
1272
1264
1273
df = DataFrame (np .random .rand (10 , 3 ),
1265
1274
index = list (string .ascii_letters [:10 ]))
1275
+
1266
1276
_check_plot_works (df .plot , use_index = True )
1267
1277
_check_plot_works (df .plot , sort_columns = False )
1268
1278
_check_plot_works (df .plot , yticks = [1 , 5 , 10 ])
1269
1279
_check_plot_works (df .plot , xticks = [1 , 5 , 10 ])
1270
1280
_check_plot_works (df .plot , ylim = (- 100 , 100 ), xlim = (- 100 , 100 ))
1271
1281
1272
- _check_plot_works (df .plot , subplots = True , title = 'blah' )
1282
+ _check_plot_works (df .plot , filterwarnings = 'ignore' , subplots = True , title = 'blah' )
1273
1283
# We have to redo it here because _check_plot_works does two plots, once without an ax
1274
1284
# kwarg and once with an ax kwarg and the new sharex behaviour does not remove the
1275
1285
# visibility of the latter axis (as ax is present).
@@ -2083,7 +2093,7 @@ def test_plot_bar(self):
2083
2093
2084
2094
_check_plot_works (df .plot .bar )
2085
2095
_check_plot_works (df .plot .bar , legend = False )
2086
- _check_plot_works (df .plot .bar , subplots = True )
2096
+ _check_plot_works (df .plot .bar , filterwarnings = 'ignore' , subplots = True )
2087
2097
_check_plot_works (df .plot .bar , stacked = True )
2088
2098
2089
2099
df = DataFrame (randn (10 , 15 ),
@@ -2300,7 +2310,7 @@ def test_boxplot_vertical(self):
2300
2310
self ._check_text_labels (ax .get_yticklabels (), labels )
2301
2311
self .assertEqual (len (ax .lines ), self .bp_n_objects * len (numeric_cols ))
2302
2312
2303
- axes = _check_plot_works (df .plot .box , subplots = True ,
2313
+ axes = _check_plot_works (df .plot .box , filterwarnings = 'ignore' , subplots = True ,
2304
2314
vert = False , logx = True )
2305
2315
self ._check_axes_shape (axes , axes_num = 3 , layout = (1 , 3 ))
2306
2316
self ._check_ax_scales (axes , xaxis = 'log' )
@@ -2360,7 +2370,7 @@ def test_kde_df(self):
2360
2370
ax = df .plot (kind = 'kde' , rot = 20 , fontsize = 5 )
2361
2371
self ._check_ticks_props (ax , xrot = 20 , xlabelsize = 5 , ylabelsize = 5 )
2362
2372
2363
- axes = _check_plot_works (df .plot , kind = 'kde' , subplots = True )
2373
+ axes = _check_plot_works (df .plot , filterwarnings = 'ignore' , kind = 'kde' , subplots = True )
2364
2374
self ._check_axes_shape (axes , axes_num = 4 , layout = (4 , 1 ))
2365
2375
2366
2376
axes = df .plot (kind = 'kde' , logy = True , subplots = True )
@@ -2387,7 +2397,7 @@ def test_hist_df(self):
2387
2397
expected = [com .pprint_thing (c ) for c in df .columns ]
2388
2398
self ._check_legend_labels (ax , labels = expected )
2389
2399
2390
- axes = _check_plot_works (df .plot .hist , subplots = True , logy = True )
2400
+ axes = _check_plot_works (df .plot .hist , filterwarnings = 'ignore' , subplots = True , logy = True )
2391
2401
self ._check_axes_shape (axes , axes_num = 4 , layout = (4 , 1 ))
2392
2402
self ._check_ax_scales (axes , yaxis = 'log' )
2393
2403
@@ -3093,7 +3103,7 @@ def test_pie_df(self):
3093
3103
ax = _check_plot_works (df .plot .pie , y = 2 )
3094
3104
self ._check_text_labels (ax .texts , df .index )
3095
3105
3096
- axes = _check_plot_works (df .plot .pie , subplots = True )
3106
+ axes = _check_plot_works (df .plot .pie , filterwarnings = 'ignore' , subplots = True )
3097
3107
self .assertEqual (len (axes ), len (df .columns ))
3098
3108
for ax in axes :
3099
3109
self ._check_text_labels (ax .texts , df .index )
@@ -3102,7 +3112,7 @@ def test_pie_df(self):
3102
3112
3103
3113
labels = ['A' , 'B' , 'C' , 'D' , 'E' ]
3104
3114
color_args = ['r' , 'g' , 'b' , 'c' , 'm' ]
3105
- axes = _check_plot_works (df .plot .pie , subplots = True ,
3115
+ axes = _check_plot_works (df .plot .pie , filterwarnings = 'ignore' , subplots = True ,
3106
3116
labels = labels , colors = color_args )
3107
3117
self .assertEqual (len (axes ), len (df .columns ))
3108
3118
@@ -3156,7 +3166,8 @@ def test_errorbar_plot(self):
3156
3166
self ._check_has_errorbars (ax , xerr = 2 , yerr = 2 )
3157
3167
ax = _check_plot_works (df .plot , xerr = 0.2 , yerr = 0.2 , kind = kind )
3158
3168
self ._check_has_errorbars (ax , xerr = 2 , yerr = 2 )
3159
- axes = _check_plot_works (df .plot , yerr = df_err , xerr = df_err , subplots = True , kind = kind )
3169
+ axes = _check_plot_works (df .plot , filterwarnings = 'ignore' , yerr = df_err ,
3170
+ xerr = df_err , subplots = True , kind = kind )
3160
3171
self ._check_has_errorbars (axes , xerr = 1 , yerr = 1 )
3161
3172
3162
3173
ax = _check_plot_works ((df + 1 ).plot , yerr = df_err , xerr = df_err , kind = 'bar' , log = True )
@@ -3245,7 +3256,8 @@ def test_errorbar_timeseries(self):
3245
3256
self ._check_has_errorbars (ax , xerr = 0 , yerr = 1 )
3246
3257
ax = _check_plot_works (tdf .plot , yerr = tdf_err , kind = kind )
3247
3258
self ._check_has_errorbars (ax , xerr = 0 , yerr = 2 )
3248
- axes = _check_plot_works (tdf .plot , kind = kind , yerr = tdf_err , subplots = True )
3259
+ axes = _check_plot_works (tdf .plot , filterwarnings = 'ignore' , kind = kind ,
3260
+ yerr = tdf_err , subplots = True )
3249
3261
self ._check_has_errorbars (axes , xerr = 0 , yerr = 1 )
3250
3262
3251
3263
def test_errorbar_asymmetrical (self ):
@@ -3690,37 +3702,38 @@ def assert_is_valid_plot_return_object(objs):
3690
3702
'' .format (objs .__class__ .__name__ ))
3691
3703
3692
3704
3693
- def _check_plot_works (f , * args , ** kwargs ):
3705
+ def _check_plot_works (f , filterwarnings = 'always' , ** kwargs ):
3694
3706
import matplotlib .pyplot as plt
3695
3707
ret = None
3696
-
3697
- try :
3708
+ with warnings . catch_warnings ():
3709
+ warnings . simplefilter ( filterwarnings )
3698
3710
try :
3699
- fig = kwargs ['figure' ]
3700
- except KeyError :
3701
- fig = plt .gcf ()
3711
+ try :
3712
+ fig = kwargs ['figure' ]
3713
+ except KeyError :
3714
+ fig = plt .gcf ()
3702
3715
3703
- plt .clf ()
3716
+ plt .clf ()
3704
3717
3705
- ax = kwargs .get ('ax' , fig .add_subplot (211 ))
3706
- ret = f (* args , ** kwargs )
3718
+ ax = kwargs .get ('ax' , fig .add_subplot (211 ))
3719
+ ret = f (** kwargs )
3707
3720
3708
- assert_is_valid_plot_return_object (ret )
3709
-
3710
- try :
3711
- kwargs ['ax' ] = fig .add_subplot (212 )
3712
- ret = f (* args , ** kwargs )
3713
- except Exception :
3714
- pass
3715
- else :
3716
3721
assert_is_valid_plot_return_object (ret )
3717
3722
3718
- with ensure_clean (return_filelike = True ) as path :
3719
- plt .savefig (path )
3720
- finally :
3721
- tm .close (fig )
3723
+ try :
3724
+ kwargs ['ax' ] = fig .add_subplot (212 )
3725
+ ret = f (** kwargs )
3726
+ except Exception :
3727
+ pass
3728
+ else :
3729
+ assert_is_valid_plot_return_object (ret )
3730
+
3731
+ with ensure_clean (return_filelike = True ) as path :
3732
+ plt .savefig (path )
3733
+ finally :
3734
+ tm .close (fig )
3722
3735
3723
- return ret
3736
+ return ret
3724
3737
3725
3738
def _generate_4_axes_via_gridspec ():
3726
3739
import matplotlib .pyplot as plt
0 commit comments