Skip to content

Commit 3c42dc7

Browse files
Brian TuBrian Tu
Brian Tu
authored and
Brian Tu
committed
Jeff's changes
1 parent 0f14411 commit 3c42dc7

File tree

1 file changed

+27
-33
lines changed

1 file changed

+27
-33
lines changed

pandas/tests/indexes/test_base.py

+27-33
Original file line numberDiff line numberDiff line change
@@ -1092,11 +1092,6 @@ def test_get_indexer_nearest(self):
10921092
tm.assert_numpy_array_equal(actual, np.array([0, 5, 9],
10931093
dtype=np.intp))
10941094

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-
11001095
for method, expected in zip(all_methods, [[0, 1, 8], [1, 2, 9],
11011096
[0, 2, 9]]):
11021097
actual = idx.get_indexer([0.2, 1.8, 8.5], method=method)
@@ -1108,51 +1103,50 @@ def test_get_indexer_nearest(self):
11081103
tm.assert_numpy_array_equal(actual, np.array(expected,
11091104
dtype=np.intp))
11101105

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-
11161106
for method, expected in zip(all_methods, [[0, -1, -1], [-1, 2, -1],
11171107
[0, 2, -1]]):
11181108
actual = idx.get_indexer([0.2, 1.8, 8.5], method=method,
11191109
tolerance=0.2)
11201110
tm.assert_numpy_array_equal(actual, np.array(expected,
11211111
dtype=np.intp))
11221112

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)
11271115

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],
11361124
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])
11401130
tm.assert_numpy_array_equal(actual, np.array(expected,
11411131
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])
11451137
tm.assert_numpy_array_equal(actual, np.array(expected,
11461138
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)):
11481145
actual = idx.get_indexer([0.2, 1.8, 8.5], method='nearest',
1149-
tolerance=np.array(tolerance))
1146+
tolerance=listtype(tolerance))
11501147
tm.assert_numpy_array_equal(actual, np.array(expected,
11511148
dtype=np.intp))
11521149

1153-
with tm.assert_raises_regex(ValueError, 'limit argument'):
1154-
idx.get_indexer([1, 0], method='nearest', limit=1)
1155-
11561150
def test_get_indexer_nearest_decreasing(self):
11571151
idx = Index(np.arange(10))[::-1]
11581152

0 commit comments

Comments
 (0)