@@ -444,7 +444,11 @@ def test_sum(self):
444444 has_numeric_only = True , check_dtype = False ,
445445 check_less_precise = True )
446446
447- def test_stat_operators_attempt_obj_array (self ):
447+ @pytest .mark .parametrize (
448+ "method" , ['sum' , 'mean' , 'prod' , 'var' ,
449+ 'std' , 'skew' , 'min' , 'max' ])
450+ def test_stat_operators_attempt_obj_array (self , method ):
451+ # GH #676
448452 data = {
449453 'a' : [- 0.00049987540199591344 , - 0.0016467257772919831 ,
450454 0.00067695870775883013 ],
@@ -454,20 +458,17 @@ def test_stat_operators_attempt_obj_array(self):
454458 }
455459 df1 = DataFrame (data , index = ['foo' , 'bar' , 'baz' ],
456460 dtype = 'O' )
457- methods = ['sum' , 'mean' , 'prod' , 'var' , 'std' , 'skew' , 'min' , 'max' ]
458461
459- # GH #676
460462 df2 = DataFrame ({0 : [np .nan , 2 ], 1 : [np .nan , 3 ],
461463 2 : [np .nan , 4 ]}, dtype = object )
462464
463465 for df in [df1 , df2 ]:
464- for meth in methods :
465- assert df .values .dtype == np .object_
466- result = getattr (df , meth )(1 )
467- expected = getattr (df .astype ('f8' ), meth )(1 )
466+ assert df .values .dtype == np .object_
467+ result = getattr (df , method )(1 )
468+ expected = getattr (df .astype ('f8' ), method )(1 )
468469
469- if not tm . _incompat_bottleneck_version ( meth ) :
470- tm .assert_series_equal (result , expected )
470+ if method in [ 'sum' , 'prod' ] :
471+ tm .assert_series_equal (result , expected )
471472
472473 def test_mean (self ):
473474 self ._check_stat_op ('mean' , np .mean , check_dates = True )
@@ -559,15 +560,15 @@ def test_var_std(self):
559560 arr = np .repeat (np .random .random ((1 , 1000 )), 1000 , 0 )
560561 result = nanops .nanvar (arr , axis = 0 )
561562 assert not (result < 0 ).any ()
562- if nanops . _USE_BOTTLENECK :
563- nanops . _USE_BOTTLENECK = False
563+
564+ with pd . option_context ( 'use_bottleneck' , False ):
564565 result = nanops .nanvar (arr , axis = 0 )
565566 assert not (result < 0 ).any ()
566- nanops ._USE_BOTTLENECK = True
567567
568- def test_numeric_only_flag (self ):
568+ @pytest .mark .parametrize (
569+ "meth" , ['sem' , 'var' , 'std' ])
570+ def test_numeric_only_flag (self , meth ):
569571 # GH #9201
570- methods = ['sem' , 'var' , 'std' ]
571572 df1 = DataFrame (np .random .randn (5 , 3 ), columns = ['foo' , 'bar' , 'baz' ])
572573 # set one entry to a number in str format
573574 df1 .loc [0 , 'foo' ] = '100'
@@ -576,20 +577,19 @@ def test_numeric_only_flag(self):
576577 # set one entry to a non-number str
577578 df2 .loc [0 , 'foo' ] = 'a'
578579
579- for meth in methods :
580- result = getattr (df1 , meth )(axis = 1 , numeric_only = True )
581- expected = getattr (df1 [['bar' , 'baz' ]], meth )(axis = 1 )
582- tm .assert_series_equal (expected , result )
580+ result = getattr (df1 , meth )(axis = 1 , numeric_only = True )
581+ expected = getattr (df1 [['bar' , 'baz' ]], meth )(axis = 1 )
582+ tm .assert_series_equal (expected , result )
583583
584- result = getattr (df2 , meth )(axis = 1 , numeric_only = True )
585- expected = getattr (df2 [['bar' , 'baz' ]], meth )(axis = 1 )
586- tm .assert_series_equal (expected , result )
584+ result = getattr (df2 , meth )(axis = 1 , numeric_only = True )
585+ expected = getattr (df2 [['bar' , 'baz' ]], meth )(axis = 1 )
586+ tm .assert_series_equal (expected , result )
587587
588- # df1 has all numbers, df2 has a letter inside
589- pytest .raises (TypeError , lambda : getattr (df1 , meth )(
590- axis = 1 , numeric_only = False ))
591- pytest .raises (TypeError , lambda : getattr (df2 , meth )(
592- axis = 1 , numeric_only = False ))
588+ # df1 has all numbers, df2 has a letter inside
589+ pytest .raises (TypeError , lambda : getattr (df1 , meth )(
590+ axis = 1 , numeric_only = False ))
591+ pytest .raises (TypeError , lambda : getattr (df2 , meth )(
592+ axis = 1 , numeric_only = False ))
593593
594594 def test_mixed_ops (self ):
595595 # GH 16116
@@ -602,11 +602,9 @@ def test_mixed_ops(self):
602602 result = getattr (df , op )()
603603 assert len (result ) == 2
604604
605- if nanops ._USE_BOTTLENECK :
606- nanops ._USE_BOTTLENECK = False
605+ with pd .option_context ('use_bottleneck' , False ):
607606 result = getattr (df , op )()
608607 assert len (result ) == 2
609- nanops ._USE_BOTTLENECK = True
610608
611609 def test_cumsum (self ):
612610 self .tsframe .loc [5 :10 , 0 ] = nan
@@ -672,11 +670,10 @@ def test_sem(self):
672670 arr = np .repeat (np .random .random ((1 , 1000 )), 1000 , 0 )
673671 result = nanops .nansem (arr , axis = 0 )
674672 assert not (result < 0 ).any ()
675- if nanops . _USE_BOTTLENECK :
676- nanops . _USE_BOTTLENECK = False
673+
674+ with pd . option_context ( 'use_bottleneck' , False ):
677675 result = nanops .nansem (arr , axis = 0 )
678676 assert not (result < 0 ).any ()
679- nanops ._USE_BOTTLENECK = True
680677
681678 def test_skew (self ):
682679 tm ._skip_if_no_scipy ()
@@ -763,7 +760,7 @@ def wrapper(x):
763760 tm .assert_series_equal (result0 , frame .apply (skipna_wrapper ),
764761 check_dtype = check_dtype ,
765762 check_less_precise = check_less_precise )
766- if not tm . _incompat_bottleneck_version ( name ) :
763+ if name in [ 'sum' , 'prod' ] :
767764 exp = frame .apply (skipna_wrapper , axis = 1 )
768765 tm .assert_series_equal (result1 , exp , check_dtype = False ,
769766 check_less_precise = check_less_precise )
@@ -795,7 +792,7 @@ def wrapper(x):
795792 all_na = self .frame * np .NaN
796793 r0 = getattr (all_na , name )(axis = 0 )
797794 r1 = getattr (all_na , name )(axis = 1 )
798- if not tm . _incompat_bottleneck_version ( name ) :
795+ if name in [ 'sum' , 'prod' ] :
799796 assert np .isnan (r0 ).all ()
800797 assert np .isnan (r1 ).all ()
801798
@@ -1855,14 +1852,14 @@ def test_dataframe_clip(self):
18551852 assert (clipped_df .values [ub_mask ] == ub ).all ()
18561853 assert (clipped_df .values [mask ] == df .values [mask ]).all ()
18571854
1858- @pytest .mark .xfail (reason = ("clip on mixed integer or floats "
1859- "with integer clippers coerces to float" ))
18601855 def test_clip_mixed_numeric (self ):
1861-
1856+ # TODO(jreback)
1857+ # clip on mixed integer or floats
1858+ # with integer clippers coerces to float
18621859 df = DataFrame ({'A' : [1 , 2 , 3 ],
18631860 'B' : [1. , np .nan , 3. ]})
18641861 result = df .clip (1 , 2 )
1865- expected = DataFrame ({'A' : [1 , 2 , 2 ],
1862+ expected = DataFrame ({'A' : [1 , 2 , 2. ],
18661863 'B' : [1. , np .nan , 2. ]})
18671864 tm .assert_frame_equal (result , expected , check_like = True )
18681865
0 commit comments