@@ -800,8 +800,8 @@ def test_hist_legacy(self):
800800 _check_plot_works (self .ts .hist )
801801 _check_plot_works (self .ts .hist , grid = False )
802802 _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 )
805805
806806 fig , ax = self .plt .subplots (1 , 1 )
807807 _check_plot_works (self .ts .hist , ax = ax )
@@ -835,25 +835,32 @@ def test_hist_layout(self):
835835 def test_hist_layout_with_by (self ):
836836 df = self .hist_df
837837
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 ))
839840 self ._check_axes_shape (axes , axes_num = 2 , layout = (2 , 1 ))
840841
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 ))
842844 self ._check_axes_shape (axes , axes_num = 2 , layout = (3 , 1 ))
843845
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 ))
845848 self ._check_axes_shape (axes , axes_num = 4 , layout = (4 , 1 ))
846849
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 ))
848852 self ._check_axes_shape (axes , axes_num = 4 , layout = (2 , 2 ))
849853
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 ))
851856 self ._check_axes_shape (axes , axes_num = 4 , layout = (3 , 2 ))
852857
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 ))
854860 self ._check_axes_shape (axes , axes_num = 4 , layout = (1 , 4 ))
855861
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 ))
857864 self ._check_axes_shape (axes , axes_num = 3 , layout = (2 , 2 ))
858865
859866 axes = df .height .hist (by = df .category , layout = (4 , 2 ), figsize = (12 , 7 ))
@@ -1247,14 +1254,16 @@ def setUp(self):
12471254 @slow
12481255 def test_plot (self ):
12491256 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 )
12521259 self ._check_axes_shape (axes , axes_num = 4 , layout = (4 , 1 ))
12531260
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 ))
12551263 self ._check_axes_shape (axes , axes_num = 4 , layout = (2 , 2 ))
12561264
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 )
12581267 self ._check_axes_shape (axes , axes_num = 4 , layout = (4 , 1 ))
12591268
12601269 df = DataFrame ({'x' : [1 , 2 ], 'y' : [3 , 4 ]})
@@ -1263,13 +1272,14 @@ def test_plot(self):
12631272
12641273 df = DataFrame (np .random .rand (10 , 3 ),
12651274 index = list (string .ascii_letters [:10 ]))
1275+
12661276 _check_plot_works (df .plot , use_index = True )
12671277 _check_plot_works (df .plot , sort_columns = False )
12681278 _check_plot_works (df .plot , yticks = [1 , 5 , 10 ])
12691279 _check_plot_works (df .plot , xticks = [1 , 5 , 10 ])
12701280 _check_plot_works (df .plot , ylim = (- 100 , 100 ), xlim = (- 100 , 100 ))
12711281
1272- _check_plot_works (df .plot , subplots = True , title = 'blah' )
1282+ _check_plot_works (df .plot , filterwarnings = 'ignore' , subplots = True , title = 'blah' )
12731283 # We have to redo it here because _check_plot_works does two plots, once without an ax
12741284 # kwarg and once with an ax kwarg and the new sharex behaviour does not remove the
12751285 # visibility of the latter axis (as ax is present).
@@ -2083,7 +2093,7 @@ def test_plot_bar(self):
20832093
20842094 _check_plot_works (df .plot .bar )
20852095 _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 )
20872097 _check_plot_works (df .plot .bar , stacked = True )
20882098
20892099 df = DataFrame (randn (10 , 15 ),
@@ -2300,7 +2310,7 @@ def test_boxplot_vertical(self):
23002310 self ._check_text_labels (ax .get_yticklabels (), labels )
23012311 self .assertEqual (len (ax .lines ), self .bp_n_objects * len (numeric_cols ))
23022312
2303- axes = _check_plot_works (df .plot .box , subplots = True ,
2313+ axes = _check_plot_works (df .plot .box , filterwarnings = 'ignore' , subplots = True ,
23042314 vert = False , logx = True )
23052315 self ._check_axes_shape (axes , axes_num = 3 , layout = (1 , 3 ))
23062316 self ._check_ax_scales (axes , xaxis = 'log' )
@@ -2360,7 +2370,7 @@ def test_kde_df(self):
23602370 ax = df .plot (kind = 'kde' , rot = 20 , fontsize = 5 )
23612371 self ._check_ticks_props (ax , xrot = 20 , xlabelsize = 5 , ylabelsize = 5 )
23622372
2363- axes = _check_plot_works (df .plot , kind = 'kde' , subplots = True )
2373+ axes = _check_plot_works (df .plot , filterwarnings = 'ignore' , kind = 'kde' , subplots = True )
23642374 self ._check_axes_shape (axes , axes_num = 4 , layout = (4 , 1 ))
23652375
23662376 axes = df .plot (kind = 'kde' , logy = True , subplots = True )
@@ -2387,7 +2397,7 @@ def test_hist_df(self):
23872397 expected = [com .pprint_thing (c ) for c in df .columns ]
23882398 self ._check_legend_labels (ax , labels = expected )
23892399
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 )
23912401 self ._check_axes_shape (axes , axes_num = 4 , layout = (4 , 1 ))
23922402 self ._check_ax_scales (axes , yaxis = 'log' )
23932403
@@ -3093,7 +3103,7 @@ def test_pie_df(self):
30933103 ax = _check_plot_works (df .plot .pie , y = 2 )
30943104 self ._check_text_labels (ax .texts , df .index )
30953105
3096- axes = _check_plot_works (df .plot .pie , subplots = True )
3106+ axes = _check_plot_works (df .plot .pie , filterwarnings = 'ignore' , subplots = True )
30973107 self .assertEqual (len (axes ), len (df .columns ))
30983108 for ax in axes :
30993109 self ._check_text_labels (ax .texts , df .index )
@@ -3102,7 +3112,7 @@ def test_pie_df(self):
31023112
31033113 labels = ['A' , 'B' , 'C' , 'D' , 'E' ]
31043114 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 ,
31063116 labels = labels , colors = color_args )
31073117 self .assertEqual (len (axes ), len (df .columns ))
31083118
@@ -3156,7 +3166,8 @@ def test_errorbar_plot(self):
31563166 self ._check_has_errorbars (ax , xerr = 2 , yerr = 2 )
31573167 ax = _check_plot_works (df .plot , xerr = 0.2 , yerr = 0.2 , kind = kind )
31583168 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 )
31603171 self ._check_has_errorbars (axes , xerr = 1 , yerr = 1 )
31613172
31623173 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):
32453256 self ._check_has_errorbars (ax , xerr = 0 , yerr = 1 )
32463257 ax = _check_plot_works (tdf .plot , yerr = tdf_err , kind = kind )
32473258 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 )
32493261 self ._check_has_errorbars (axes , xerr = 0 , yerr = 1 )
32503262
32513263 def test_errorbar_asymmetrical (self ):
@@ -3690,37 +3702,38 @@ def assert_is_valid_plot_return_object(objs):
36903702 '' .format (objs .__class__ .__name__ ))
36913703
36923704
3693- def _check_plot_works (f , * args , ** kwargs ):
3705+ def _check_plot_works (f , filterwarnings = 'always' , ** kwargs ):
36943706 import matplotlib .pyplot as plt
36953707 ret = None
3696-
3697- try :
3708+ with warnings . catch_warnings ():
3709+ warnings . simplefilter ( filterwarnings )
36983710 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 ()
37023715
3703- plt .clf ()
3716+ plt .clf ()
37043717
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 )
37073720
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 :
37163721 assert_is_valid_plot_return_object (ret )
37173722
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 )
37223735
3723- return ret
3736+ return ret
37243737
37253738def _generate_4_axes_via_gridspec ():
37263739 import matplotlib .pyplot as plt
0 commit comments