Skip to content

Commit fe65ed7

Browse files
committed
TST: added test for implicit casting in MultiIndex.get_loc()
1 parent 5e44452 commit fe65ed7

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
@@ -1266,6 +1266,18 @@ def test_get_loc_missing_nan(self):
12661266
pytest.raises(KeyError, idx.get_loc, np.nan)
12671267
pytest.raises(KeyError, idx.get_loc, [np.nan])
12681268

1269+
@pytest.mark.parametrize('level', [0, 1])
1270+
@pytest.mark.parametrize('dtypes', [[int, float], [float, int]])
1271+
def test_get_loc_implicit_cast(self, level, dtypes):
1272+
# GH 18818, GH 15994 : as flat index, cast int to float and vice-versa
1273+
levels = [['a', 'b'], ['c', 'd']]
1274+
key = ['b', 'd']
1275+
lev_dtype, key_dtype = dtypes
1276+
levels[level] = np.array([0, 1], dtype=lev_dtype)
1277+
key[level] = key_dtype(1)
1278+
idx = MultiIndex.from_product(levels)
1279+
assert idx.get_loc(tuple(key)) == 3
1280+
12691281
def test_slice_locs(self):
12701282
df = tm.makeTimeDataFrame()
12711283
stacked = df.stack()

0 commit comments

Comments
 (0)