@@ -366,51 +366,51 @@ def _compare_stacked_y_cood(self, normal_lines, stacked_lines):
366366
367367 @pytest .mark .parametrize ("kind" , ["line" , "area" ])
368368 def test_line_area_stacked (self , kind ):
369- with tm . RNGContext (42 ):
370- df = DataFrame (np . random .rand (6 , 4 ), columns = ["w" , "x" , "y" , "z" ])
371- neg_df = - df
372- # each column has either positive or negative value
373- sep_df = DataFrame (
374- {
375- "w" : np . random .rand (6 ),
376- "x" : np . random .rand (6 ),
377- "y" : - np . random .rand (6 ),
378- "z" : - np . random .rand (6 ),
379- }
380- )
381- # each column has positive-negative mixed value
382- mixed_df = DataFrame (
383- np . random .randn (6 , 4 ),
384- index = list (string .ascii_letters [:6 ]),
385- columns = ["w" , "x" , "y" , "z" ],
386- )
369+ np_random = np . random . RandomState (42 )
370+ df = DataFrame (np_random .rand (6 , 4 ), columns = ["w" , "x" , "y" , "z" ])
371+ neg_df = - df
372+ # each column has either positive or negative value
373+ sep_df = DataFrame (
374+ {
375+ "w" : np_random .rand (6 ),
376+ "x" : np_random .rand (6 ),
377+ "y" : - np_random .rand (6 ),
378+ "z" : - np_random .rand (6 ),
379+ }
380+ )
381+ # each column has positive-negative mixed value
382+ mixed_df = DataFrame (
383+ np_random .randn (6 , 4 ),
384+ index = list (string .ascii_letters [:6 ]),
385+ columns = ["w" , "x" , "y" , "z" ],
386+ )
387387
388- ax1 = _check_plot_works (df .plot , kind = kind , stacked = False )
389- ax2 = _check_plot_works (df .plot , kind = kind , stacked = True )
390- self ._compare_stacked_y_cood (ax1 .lines , ax2 .lines )
388+ ax1 = _check_plot_works (df .plot , kind = kind , stacked = False )
389+ ax2 = _check_plot_works (df .plot , kind = kind , stacked = True )
390+ self ._compare_stacked_y_cood (ax1 .lines , ax2 .lines )
391391
392- ax1 = _check_plot_works (neg_df .plot , kind = kind , stacked = False )
393- ax2 = _check_plot_works (neg_df .plot , kind = kind , stacked = True )
394- self ._compare_stacked_y_cood (ax1 .lines , ax2 .lines )
392+ ax1 = _check_plot_works (neg_df .plot , kind = kind , stacked = False )
393+ ax2 = _check_plot_works (neg_df .plot , kind = kind , stacked = True )
394+ self ._compare_stacked_y_cood (ax1 .lines , ax2 .lines )
395395
396- ax1 = _check_plot_works (sep_df .plot , kind = kind , stacked = False )
397- ax2 = _check_plot_works (sep_df .plot , kind = kind , stacked = True )
398- self ._compare_stacked_y_cood (ax1 .lines [:2 ], ax2 .lines [:2 ])
399- self ._compare_stacked_y_cood (ax1 .lines [2 :], ax2 .lines [2 :])
396+ ax1 = _check_plot_works (sep_df .plot , kind = kind , stacked = False )
397+ ax2 = _check_plot_works (sep_df .plot , kind = kind , stacked = True )
398+ self ._compare_stacked_y_cood (ax1 .lines [:2 ], ax2 .lines [:2 ])
399+ self ._compare_stacked_y_cood (ax1 .lines [2 :], ax2 .lines [2 :])
400400
401- _check_plot_works (mixed_df .plot , stacked = False )
402- msg = (
403- "When stacked is True, each column must be either all positive or "
404- "all negative. Column 'w' contains both positive and negative "
405- "values"
406- )
407- with pytest .raises (ValueError , match = msg ):
408- mixed_df .plot (stacked = True )
401+ _check_plot_works (mixed_df .plot , stacked = False )
402+ msg = (
403+ "When stacked is True, each column must be either all positive or "
404+ "all negative. Column 'w' contains both positive and negative "
405+ "values"
406+ )
407+ with pytest .raises (ValueError , match = msg ):
408+ mixed_df .plot (stacked = True )
409409
410- # Use an index with strictly positive values, preventing
411- # matplotlib from warning about ignoring xlim
412- df2 = df .set_index (df .index + 1 )
413- _check_plot_works (df2 .plot , kind = kind , logx = True , stacked = True )
410+ # Use an index with strictly positive values, preventing
411+ # matplotlib from warning about ignoring xlim
412+ df2 = df .set_index (df .index + 1 )
413+ _check_plot_works (df2 .plot , kind = kind , logx = True , stacked = True )
414414
415415 def test_line_area_nan_df (self ):
416416 values1 = [1 , 2 , np .nan , 3 ]
@@ -1237,20 +1237,18 @@ def test_all_invalid_plot_data(self):
12371237 df .plot (kind = kind )
12381238
12391239 def test_partially_invalid_plot_data (self ):
1240- with tm .RNGContext (42 ):
1241- df = DataFrame (np .random .randn (10 , 2 ), dtype = object )
1242- df [np .random .rand (df .shape [0 ]) > 0.5 ] = "a"
1243- for kind in plotting .PlotAccessor ._common_kinds :
1244- msg = "no numeric data to plot"
1245- with pytest .raises (TypeError , match = msg ):
1246- df .plot (kind = kind )
1247-
1248- with tm .RNGContext (42 ):
1249- # area plot doesn't support positive/negative mixed data
1250- df = DataFrame (np .random .rand (10 , 2 ), dtype = object )
1251- df [np .random .rand (df .shape [0 ]) > 0.5 ] = "a"
1252- with pytest .raises (TypeError , match = "no numeric data to plot" ):
1253- df .plot (kind = "area" )
1240+ df = DataFrame (np .random .RandomState (42 ).randn (10 , 2 ), dtype = object )
1241+ df [np .random .rand (df .shape [0 ]) > 0.5 ] = "a"
1242+ for kind in plotting .PlotAccessor ._common_kinds :
1243+ msg = "no numeric data to plot"
1244+ with pytest .raises (TypeError , match = msg ):
1245+ df .plot (kind = kind )
1246+
1247+ # area plot doesn't support positive/negative mixed data
1248+ df = DataFrame (np .random .RandomState (42 ).rand (10 , 2 ), dtype = object )
1249+ df [np .random .rand (df .shape [0 ]) > 0.5 ] = "a"
1250+ with pytest .raises (TypeError , match = "no numeric data to plot" ):
1251+ df .plot (kind = "area" )
12541252
12551253 def test_invalid_kind (self ):
12561254 df = DataFrame (np .random .randn (10 , 2 ))
0 commit comments