@@ -993,9 +993,9 @@ def test_2D_array_dim1(self):
993
993
994
994
class TestScoreatpercentile (TestCase ):
995
995
def setUp (self ):
996
- self .a1 = [3 ,4 , 5 , 10 ,- 3 ,- 5 ,6 ]
997
- self .a2 = [3 ,- 6 ,- 2 ,8 , 7 , 4 , 2 , 1 ]
998
- self .a3 = [3. ,4 , 5 , 10 ,- 3 ,- 5 ,- 6 ,7.0 ]
996
+ self .a1 = [3 , 4 , 5 , 10 , - 3 , - 5 , 6 ]
997
+ self .a2 = [3 , - 6 , - 2 , 8 , 7 , 4 , 2 , 1 ]
998
+ self .a3 = [3. , 4 , 5 , 10 , - 3 , - 5 , - 6 , 7.0 ]
999
999
1000
1000
def test_basic (self ):
1001
1001
x = arange (8 ) * 0.5
@@ -1009,33 +1009,29 @@ def test_2D(self):
1009
1009
[4 , 4 , 3 ],
1010
1010
[1 , 1 , 1 ],
1011
1011
[1 , 1 , 1 ]])
1012
- assert_array_equal (stats .scoreatpercentile (x , 50 ), [1 ,1 , 1 ])
1012
+ assert_array_equal (stats .scoreatpercentile (x , 50 ), [1 , 1 , 1 ])
1013
1013
1014
1014
def test_fraction (self ):
1015
1015
scoreatperc = stats .scoreatpercentile
1016
1016
1017
1017
# Test defaults
1018
1018
assert_equal (scoreatperc (range (10 ), 50 ), 4.5 )
1019
- assert_equal (scoreatperc (range (10 ), 50 , (2 ,7 )), 4.5 )
1019
+ assert_equal (scoreatperc (range (10 ), 50 , (2 , 7 )), 4.5 )
1020
1020
assert_equal (scoreatperc (range (100 ), 50 , limit = (1 , 8 )), 4.5 )
1021
- assert_equal (scoreatperc (np .array ([1 , 10 , 100 ]), 50 , (10 ,100 )), 55 )
1022
- assert_equal (scoreatperc (np .array ([1 , 10 , 100 ]), 50 , (1 ,10 )), 5.5 )
1021
+ assert_equal (scoreatperc (np .array ([1 , 10 , 100 ]), 50 , (10 , 100 )), 55 )
1022
+ assert_equal (scoreatperc (np .array ([1 , 10 , 100 ]), 50 , (1 , 10 )), 5.5 )
1023
1023
1024
1024
# explicitly specify interpolation_method 'fraction' (the default)
1025
- assert_equal (scoreatperc (range (10 ), 50 , interpolation_method = 'fraction' ),
1026
- 4.5 )
1025
+ assert_equal (scoreatperc (range (10 ), 50 ,
1026
+ interpolation_method = 'fraction' ), 4.5 )
1027
1027
assert_equal (scoreatperc (range (10 ), 50 , limit = (2 , 7 ),
1028
- interpolation_method = 'fraction' ),
1029
- 4.5 )
1028
+ interpolation_method = 'fraction' ), 4.5 )
1030
1029
assert_equal (scoreatperc (range (100 ), 50 , limit = (1 , 8 ),
1031
- interpolation_method = 'fraction' ),
1032
- 4.5 )
1033
- assert_equal (scoreatperc (np .array ([1 , 10 ,100 ]), 50 , (10 , 100 ),
1034
- interpolation_method = 'fraction' ),
1035
- 55 )
1036
- assert_equal (scoreatperc (np .array ([1 , 10 ,100 ]), 50 , (1 ,10 ),
1037
- interpolation_method = 'fraction' ),
1038
- 5.5 )
1030
+ interpolation_method = 'fraction' ), 4.5 )
1031
+ assert_equal (scoreatperc (np .array ([1 , 10 , 100 ]), 50 , (10 , 100 ),
1032
+ interpolation_method = 'fraction' ), 55 )
1033
+ assert_equal (scoreatperc (np .array ([1 , 10 , 100 ]), 50 , (1 , 10 ),
1034
+ interpolation_method = 'fraction' ), 5.5 )
1039
1035
1040
1036
def test_lower_higher (self ):
1041
1037
scoreatperc = stats .scoreatpercentile
@@ -1045,23 +1041,45 @@ def test_lower_higher(self):
1045
1041
interpolation_method = 'lower' ), 4 )
1046
1042
assert_equal (scoreatperc (range (10 ), 50 ,
1047
1043
interpolation_method = 'higher' ), 5 )
1048
- assert_equal (scoreatperc (range (10 ), 50 , (2 ,7 ),
1044
+ assert_equal (scoreatperc (range (10 ), 50 , (2 , 7 ),
1049
1045
interpolation_method = 'lower' ), 4 )
1050
- assert_equal (scoreatperc (range (10 ), 50 , limit = (2 ,7 ),
1046
+ assert_equal (scoreatperc (range (10 ), 50 , limit = (2 , 7 ),
1051
1047
interpolation_method = 'higher' ), 5 )
1052
- assert_equal (scoreatperc (range (100 ), 50 , (1 ,8 ),
1048
+ assert_equal (scoreatperc (range (100 ), 50 , (1 , 8 ),
1053
1049
interpolation_method = 'lower' ), 4 )
1054
- assert_equal (scoreatperc (range (100 ), 50 , (1 ,8 ),
1050
+ assert_equal (scoreatperc (range (100 ), 50 , (1 , 8 ),
1055
1051
interpolation_method = 'higher' ), 5 )
1056
- assert_equal (scoreatperc (np .array ([1 , 10 , 100 ]), 50 , (10 ,100 ),
1052
+ assert_equal (scoreatperc (np .array ([1 , 10 , 100 ]), 50 , (10 , 100 ),
1057
1053
interpolation_method = 'lower' ), 10 )
1058
- assert_equal (scoreatperc (np .array ([1 , 10 , 100 ]), 50 , limit = (10 , 100 ),
1054
+ assert_equal (scoreatperc (np .array ([1 , 10 , 100 ]), 50 , limit = (10 , 100 ),
1059
1055
interpolation_method = 'higher' ), 100 )
1060
- assert_equal (scoreatperc (np .array ([1 , 10 , 100 ]), 50 , (1 ,10 ),
1056
+ assert_equal (scoreatperc (np .array ([1 , 10 , 100 ]), 50 , (1 , 10 ),
1061
1057
interpolation_method = 'lower' ), 1 )
1062
- assert_equal (scoreatperc (np .array ([1 , 10 , 100 ]), 50 , limit = (1 ,10 ),
1058
+ assert_equal (scoreatperc (np .array ([1 , 10 , 100 ]), 50 , limit = (1 , 10 ),
1063
1059
interpolation_method = 'higher' ), 10 )
1064
1060
1061
+ def test_sequence (self ):
1062
+ x = arange (8 ) * 0.5
1063
+ assert_equal (stats .scoreatpercentile (x , [0 , 100 , 50 ]), [0 , 3.5 , 1.75 ])
1064
+
1065
+ def test_axis (self ):
1066
+ scoreatperc = stats .scoreatpercentile
1067
+ x = arange (12 ).reshape (3 , 4 )
1068
+
1069
+ assert_equal (scoreatperc (x , (25 , 50 , 100 )), [2.75 , 5.5 , 11.0 ])
1070
+
1071
+ r0 = [[2 , 3 , 4 , 5 ], [4 , 5 , 6 , 7 ], [8 , 9 , 10 , 11 ]]
1072
+ assert_equal (scoreatperc (x , (25 , 50 , 100 ), axis = 0 ), r0 )
1073
+
1074
+ r1 = [[0.75 , 4.75 , 8.75 ], [1.5 , 5.5 , 9.5 ], [3 , 7 , 11 ]]
1075
+ assert_equal (scoreatperc (x , (25 , 50 , 100 ), axis = 1 ), r1 )
1076
+
1077
+ def test_exception (self ):
1078
+ assert_raises (ValueError , stats .scoreatpercentile , [1 , 2 ], 56 ,
1079
+ interpolation_method = 'foobar' )
1080
+ assert_raises (ValueError , stats .scoreatpercentile , [1 ], 101 )
1081
+ assert_raises (ValueError , stats .scoreatpercentile , [1 ], - 1 )
1082
+
1065
1083
1066
1084
class TestCMedian (TestCase ):
1067
1085
def test_basic (self ):
0 commit comments