@@ -448,7 +448,11 @@ def test_sum(self):
448448 has_numeric_only = True , check_dtype = False ,
449449 check_less_precise = True )
450450
451- def test_stat_operators_attempt_obj_array (self ):
451+ @pytest .mark .parametrize (
452+ "method" , ['sum' , 'mean' , 'prod' , 'var' ,
453+ 'std' , 'skew' , 'min' , 'max' ])
454+ def test_stat_operators_attempt_obj_array (self , method ):
455+ # GH #676
452456 data = {
453457 'a' : [- 0.00049987540199591344 , - 0.0016467257772919831 ,
454458 0.00067695870775883013 ],
@@ -458,20 +462,17 @@ def test_stat_operators_attempt_obj_array(self):
458462 }
459463 df1 = DataFrame (data , index = ['foo' , 'bar' , 'baz' ],
460464 dtype = 'O' )
461- methods = ['sum' , 'mean' , 'prod' , 'var' , 'std' , 'skew' , 'min' , 'max' ]
462465
463- # GH #676
464466 df2 = DataFrame ({0 : [np .nan , 2 ], 1 : [np .nan , 3 ],
465467 2 : [np .nan , 4 ]}, dtype = object )
466468
467469 for df in [df1 , df2 ]:
468- for meth in methods :
469- assert df .values .dtype == np .object_
470- result = getattr (df , meth )(1 )
471- expected = getattr (df .astype ('f8' ), meth )(1 )
470+ assert df .values .dtype == np .object_
471+ result = getattr (df , method )(1 )
472+ expected = getattr (df .astype ('f8' ), method )(1 )
472473
473- if not tm . _incompat_bottleneck_version ( meth ) :
474- tm .assert_series_equal (result , expected )
474+ if method in [ 'sum' , 'prod' ] :
475+ tm .assert_series_equal (result , expected )
475476
476477 def test_mean (self ):
477478 self ._check_stat_op ('mean' , np .mean , check_dates = True )
@@ -563,15 +564,15 @@ def test_var_std(self):
563564 arr = np .repeat (np .random .random ((1 , 1000 )), 1000 , 0 )
564565 result = nanops .nanvar (arr , axis = 0 )
565566 assert not (result < 0 ).any ()
566- if nanops . _USE_BOTTLENECK :
567- nanops . _USE_BOTTLENECK = False
567+
568+ with pd . option_context ( 'use_bottleneck' , False ):
568569 result = nanops .nanvar (arr , axis = 0 )
569570 assert not (result < 0 ).any ()
570- nanops ._USE_BOTTLENECK = True
571571
572- def test_numeric_only_flag (self ):
572+ @pytest .mark .parametrize (
573+ "meth" , ['sem' , 'var' , 'std' ])
574+ def test_numeric_only_flag (self , meth ):
573575 # GH #9201
574- methods = ['sem' , 'var' , 'std' ]
575576 df1 = DataFrame (np .random .randn (5 , 3 ), columns = ['foo' , 'bar' , 'baz' ])
576577 # set one entry to a number in str format
577578 df1 .loc [0 , 'foo' ] = '100'
@@ -580,20 +581,19 @@ def test_numeric_only_flag(self):
580581 # set one entry to a non-number str
581582 df2 .loc [0 , 'foo' ] = 'a'
582583
583- for meth in methods :
584- result = getattr (df1 , meth )(axis = 1 , numeric_only = True )
585- expected = getattr (df1 [['bar' , 'baz' ]], meth )(axis = 1 )
586- tm .assert_series_equal (expected , result )
584+ result = getattr (df1 , meth )(axis = 1 , numeric_only = True )
585+ expected = getattr (df1 [['bar' , 'baz' ]], meth )(axis = 1 )
586+ tm .assert_series_equal (expected , result )
587587
588- result = getattr (df2 , meth )(axis = 1 , numeric_only = True )
589- expected = getattr (df2 [['bar' , 'baz' ]], meth )(axis = 1 )
590- tm .assert_series_equal (expected , result )
588+ result = getattr (df2 , meth )(axis = 1 , numeric_only = True )
589+ expected = getattr (df2 [['bar' , 'baz' ]], meth )(axis = 1 )
590+ tm .assert_series_equal (expected , result )
591591
592- # df1 has all numbers, df2 has a letter inside
593- pytest .raises (TypeError , lambda : getattr (df1 , meth )(
594- axis = 1 , numeric_only = False ))
595- pytest .raises (TypeError , lambda : getattr (df2 , meth )(
596- axis = 1 , numeric_only = False ))
592+ # df1 has all numbers, df2 has a letter inside
593+ pytest .raises (TypeError , lambda : getattr (df1 , meth )(
594+ axis = 1 , numeric_only = False ))
595+ pytest .raises (TypeError , lambda : getattr (df2 , meth )(
596+ axis = 1 , numeric_only = False ))
597597
598598 def test_mixed_ops (self ):
599599 # GH 16116
@@ -606,11 +606,9 @@ def test_mixed_ops(self):
606606 result = getattr (df , op )()
607607 assert len (result ) == 2
608608
609- if nanops ._USE_BOTTLENECK :
610- nanops ._USE_BOTTLENECK = False
609+ with pd .option_context ('use_bottleneck' , False ):
611610 result = getattr (df , op )()
612611 assert len (result ) == 2
613- nanops ._USE_BOTTLENECK = True
614612
615613 def test_cumsum (self ):
616614 self .tsframe .loc [5 :10 , 0 ] = nan
@@ -676,11 +674,10 @@ def test_sem(self):
676674 arr = np .repeat (np .random .random ((1 , 1000 )), 1000 , 0 )
677675 result = nanops .nansem (arr , axis = 0 )
678676 assert not (result < 0 ).any ()
679- if nanops . _USE_BOTTLENECK :
680- nanops . _USE_BOTTLENECK = False
677+
678+ with pd . option_context ( 'use_bottleneck' , False ):
681679 result = nanops .nansem (arr , axis = 0 )
682680 assert not (result < 0 ).any ()
683- nanops ._USE_BOTTLENECK = True
684681
685682 def test_skew (self ):
686683 tm ._skip_if_no_scipy ()
@@ -767,7 +764,7 @@ def wrapper(x):
767764 tm .assert_series_equal (result0 , frame .apply (skipna_wrapper ),
768765 check_dtype = check_dtype ,
769766 check_less_precise = check_less_precise )
770- if not tm . _incompat_bottleneck_version ( name ) :
767+ if name in [ 'sum' , 'prod' ] :
771768 exp = frame .apply (skipna_wrapper , axis = 1 )
772769 tm .assert_series_equal (result1 , exp , check_dtype = False ,
773770 check_less_precise = check_less_precise )
@@ -799,7 +796,7 @@ def wrapper(x):
799796 all_na = self .frame * np .NaN
800797 r0 = getattr (all_na , name )(axis = 0 )
801798 r1 = getattr (all_na , name )(axis = 1 )
802- if not tm . _incompat_bottleneck_version ( name ) :
799+ if name in [ 'sum' , 'prod' ] :
803800 assert np .isnan (r0 ).all ()
804801 assert np .isnan (r1 ).all ()
805802
@@ -1859,14 +1856,14 @@ def test_dataframe_clip(self):
18591856 assert (clipped_df .values [ub_mask ] == ub ).all ()
18601857 assert (clipped_df .values [mask ] == df .values [mask ]).all ()
18611858
1862- @pytest .mark .xfail (reason = ("clip on mixed integer or floats "
1863- "with integer clippers coerces to float" ))
18641859 def test_clip_mixed_numeric (self ):
1865-
1860+ # TODO(jreback)
1861+ # clip on mixed integer or floats
1862+ # with integer clippers coerces to float
18661863 df = DataFrame ({'A' : [1 , 2 , 3 ],
18671864 'B' : [1. , np .nan , 3. ]})
18681865 result = df .clip (1 , 2 )
1869- expected = DataFrame ({'A' : [1 , 2 , 2 ],
1866+ expected = DataFrame ({'A' : [1 , 2 , 2. ],
18701867 'B' : [1. , np .nan , 2. ]})
18711868 tm .assert_frame_equal (result , expected , check_like = True )
18721869
0 commit comments