@@ -1092,11 +1092,6 @@ def test_get_indexer_nearest(self):
1092
1092
tm .assert_numpy_array_equal (actual , np .array ([0 , 5 , 9 ],
1093
1093
dtype = np .intp ))
1094
1094
1095
- actual = idx .get_indexer ([0 , 5 , 9 ], method = method ,
1096
- tolerance = [0 , 0 , 0 ])
1097
- tm .assert_numpy_array_equal (actual , np .array ([0 , 5 , 9 ],
1098
- dtype = np .intp ))
1099
-
1100
1095
for method , expected in zip (all_methods , [[0 , 1 , 8 ], [1 , 2 , 9 ],
1101
1096
[0 , 2 , 9 ]]):
1102
1097
actual = idx .get_indexer ([0.2 , 1.8 , 8.5 ], method = method )
@@ -1108,51 +1103,50 @@ def test_get_indexer_nearest(self):
1108
1103
tm .assert_numpy_array_equal (actual , np .array (expected ,
1109
1104
dtype = np .intp ))
1110
1105
1111
- actual = idx .get_indexer ([0.2 , 1.8 , 8.5 ], method = method ,
1112
- tolerance = [1.5 , 1 , 1 ])
1113
- tm .assert_numpy_array_equal (actual , np .array (expected ,
1114
- dtype = np .intp ))
1115
-
1116
1106
for method , expected in zip (all_methods , [[0 , - 1 , - 1 ], [- 1 , 2 , - 1 ],
1117
1107
[0 , 2 , - 1 ]]):
1118
1108
actual = idx .get_indexer ([0.2 , 1.8 , 8.5 ], method = method ,
1119
1109
tolerance = 0.2 )
1120
1110
tm .assert_numpy_array_equal (actual , np .array (expected ,
1121
1111
dtype = np .intp ))
1122
1112
1123
- actual = idx .get_indexer ([0.2 , 1.8 , 8.5 ], method = method ,
1124
- tolerance = [0.5 , 0.2 , 0.2 ])
1125
- tm .assert_numpy_array_equal (actual , np .array (expected ,
1126
- dtype = np .intp ))
1113
+ with tm .assert_raises_regex (ValueError , 'limit argument' ):
1114
+ idx .get_indexer ([1 , 0 ], method = 'nearest' , limit = 1 )
1127
1115
1128
- for tolerance , expected in zip ([[ 0.3 , 0.3 , 0.1 ], [ 0.2 , 0.1 , 0.1 ],
1129
- [ 0.1 , 0.5 , 0.5 ]],
1130
- [[ 0 , 2 , - 1 ], [ 0 , - 1 , - 1 ],
1131
- [ - 1 , 2 , 9 ]]):
1132
- # list
1133
- actual = idx .get_indexer ([0.2 , 1.8 , 8.5 ], method = 'nearest' ,
1134
- tolerance = tolerance )
1135
- tm .assert_numpy_array_equal (actual , np .array (expected ,
1116
+ def test_get_indexer_nearest_listtolerance ( self ):
1117
+ idx = Index ( np . arange ( 10 ))
1118
+
1119
+ all_methods = [ 'pad' , 'backfill' , 'nearest' ]
1120
+ for method in all_methods :
1121
+ actual = idx .get_indexer ([0 , 5 , 9 ], method = method ,
1122
+ tolerance = [ 0 , 0 , 0 ] )
1123
+ tm .assert_numpy_array_equal (actual , np .array ([ 0 , 5 , 9 ] ,
1136
1124
dtype = np .intp ))
1137
- # tuple
1138
- actual = idx .get_indexer ([0.2 , 1.8 , 8.5 ], method = 'nearest' ,
1139
- tolerance = tuple (tolerance ))
1125
+
1126
+ for method , expected in zip (all_methods , [[0 , 1 , 8 ], [1 , 2 , 9 ],
1127
+ [0 , 2 , 9 ]]):
1128
+ actual = idx .get_indexer ([0.2 , 1.8 , 8.5 ], method = method ,
1129
+ tolerance = [1.5 , 1 , 1 ])
1140
1130
tm .assert_numpy_array_equal (actual , np .array (expected ,
1141
1131
dtype = np .intp ))
1142
- # Series
1143
- actual = idx .get_indexer ([0.2 , 1.8 , 8.5 ], method = 'nearest' ,
1144
- tolerance = Series (tolerance ))
1132
+
1133
+ for method , expected in zip (all_methods , [[0 , - 1 , - 1 ], [- 1 , 2 , - 1 ],
1134
+ [0 , 2 , - 1 ]]):
1135
+ actual = idx .get_indexer ([0.2 , 1.8 , 8.5 ], method = method ,
1136
+ tolerance = [0.5 , 0.2 , 0.2 ])
1145
1137
tm .assert_numpy_array_equal (actual , np .array (expected ,
1146
1138
dtype = np .intp ))
1147
- # ndarray
1139
+ for tolerance , expected , listtype in \
1140
+ zip ([[0.3 , 0.3 , 0.1 ], [0.2 , 0.1 , 0.1 ],
1141
+ [0.1 , 0.5 , 0.5 ]],
1142
+ [[0 , 2 , - 1 ], [0 , - 1 , - 1 ],
1143
+ [- 1 , 2 , 9 ]],
1144
+ (list , tuple , Series , np .array )):
1148
1145
actual = idx .get_indexer ([0.2 , 1.8 , 8.5 ], method = 'nearest' ,
1149
- tolerance = np . array (tolerance ))
1146
+ tolerance = listtype (tolerance ))
1150
1147
tm .assert_numpy_array_equal (actual , np .array (expected ,
1151
1148
dtype = np .intp ))
1152
1149
1153
- with tm .assert_raises_regex (ValueError , 'limit argument' ):
1154
- idx .get_indexer ([1 , 0 ], method = 'nearest' , limit = 1 )
1155
-
1156
1150
def test_get_indexer_nearest_decreasing (self ):
1157
1151
idx = Index (np .arange (10 ))[::- 1 ]
1158
1152
0 commit comments