13
13
import pandas .core .nanops as nanops
14
14
import pandas .util .testing as tm
15
15
import pandas .util ._test_decorators as td
16
- from pandas .compat .numpy import _np_version_under1p13
16
+ from pandas .compat .numpy import (_np_version_under1p13 , _np_version_under1p10 ,
17
+ _np_version_under1p12 )
17
18
18
19
use_bn = nanops ._USE_BOTTLENECK
19
20
@@ -995,10 +996,16 @@ def prng(self):
995
996
996
997
997
998
@pytest .fixture (params = [
998
- pd .Series ([1 , 2 , 3 , 4 , 5 , 6 ]),
999
- pd .DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ]])
999
+ pd .Series ([1 , 2 , 3 , 4 ]),
1000
+ pd .DataFrame ([[1 , 2 ], [3 , 4 ]]),
1001
+ pd .Series ([np .nan , 2 , 3 , 4 ]),
1002
+ pd .DataFrame ([[np .nan , 2 ], [3 , 4 ]]),
1003
+ pd .Series (),
1004
+ pd .DataFrame (),
1005
+ pd .Series ([np .nan ]),
1006
+ pd .DataFrame ([[np .nan ]]),
1000
1007
])
1001
- def nan_test_object (request ):
1008
+ def series_or_frame (request ):
1002
1009
return request .param
1003
1010
1004
1011
@@ -1010,30 +1017,27 @@ def nan_test_object(request):
1010
1017
(np .median , np .nanmedian ),
1011
1018
(np .max , np .nanmax ),
1012
1019
(np .min , np .nanmin ),
1013
- ])
1014
- def test_np_nan_functions (standard , nan_method , nan_test_object ):
1015
- tm .assert_almost_equal (nan_test_object .agg (standard ),
1016
- nan_test_object .agg (nan_method ),
1020
+ ], ids = lambda x : x . __name__ )
1021
+ def test_np_nan_functions (standard , nan_method , series_or_frame ):
1022
+ tm .assert_almost_equal (series_or_frame .agg (standard ),
1023
+ series_or_frame .agg (nan_method ),
1017
1024
check_exact = True )
1018
1025
1019
1026
1020
- @td . skip_if_no ( "numpy" , min_version = " 1.10.0 " )
1021
- def test_np_nanprod (nan_test_object ):
1022
- tm .assert_almost_equal (nan_test_object .agg (np .prod ),
1023
- nan_test_object .agg (np .nanprod ),
1027
+ @pytest . mark . skipif ( _np_version_under1p10 , reason = "requires numpy>= 1.10" )
1028
+ def test_np_nanprod (series_or_frame ):
1029
+ tm .assert_almost_equal (series_or_frame .agg (np .prod ),
1030
+ series_or_frame .agg (np .nanprod ),
1024
1031
check_exact = True )
1025
1032
1026
1033
1027
- @td .skip_if_no ("numpy" , min_version = "1.12.0" )
1028
- def test_np_nancumprod (nan_test_object ):
1029
- # Not using pytest params for methods as will fail at build time
1030
- methods = [
1031
- (np .cumprod , np .nancumprod ),
1032
- (np .cumsum , np .nancumsum )
1033
- ]
1034
- for standard , nan_method in methods :
1035
- tm .assert_almost_equal (nan_test_object .agg (standard ),
1036
- nan_test_object .agg (nan_method ),
1034
+ @pytest .mark .skipif (_np_version_under1p12 , reason = "requires numpy>=1.12" )
1035
+ def test_np_nancumprod (series_or_frame ):
1036
+ funcs = [(np .cumprod , np .nancumprod ),
1037
+ (np .cumsum , np .nancumsum )]
1038
+ for standard , nan_method in funcs :
1039
+ tm .assert_almost_equal (series_or_frame .agg (standard ),
1040
+ series_or_frame .agg (nan_method ),
1037
1041
check_exact = True )
1038
1042
1039
1043
0 commit comments