Skip to content

Commit 697ded8

Browse files
committed
TST: added test for implicit casting in MultiIndex.get_loc()
1 parent 71adac3 commit 697ded8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pandas/tests/indexes/test_multi.py

+12
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,18 @@ def test_get_loc_missing_nan(self):
12511251
pytest.raises(KeyError, idx.get_loc, np.nan)
12521252
pytest.raises(KeyError, idx.get_loc, [np.nan])
12531253

1254+
@pytest.mark.parametrize('level', [0, 1])
1255+
@pytest.mark.parametrize('dtypes', [[int, float], [float, int]])
1256+
def test_get_loc_implicit_cast(self, level, dtypes):
1257+
# GH 18818
1258+
levels = [['a', 'b'], ['c', 'd']]
1259+
key = ['b', 'd']
1260+
lev_dtype, key_dtype = dtypes
1261+
levels[level] = np.array([0, 1], dtype=lev_dtype)
1262+
key[level] = key_dtype(1)
1263+
idx = MultiIndex.from_product(levels)
1264+
assert (idx.get_loc(tuple(key)) == 3)
1265+
12541266
def test_slice_locs(self):
12551267
df = tm.makeTimeDataFrame()
12561268
stacked = df.stack()

0 commit comments

Comments
 (0)