Skip to content

Commit 6415f43

Browse files
committed
TST: test MultiIndexPyIntEngine
1 parent 0073f29 commit 6415f43

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pandas/tests/test_multilevel.py

+30
Original file line numberDiff line numberDiff line change
@@ -1590,6 +1590,36 @@ def test_unstack_group_index_overflow(self):
15901590
result = s.unstack(4)
15911591
assert result.shape == (500, 2)
15921592

1593+
def test_pyint_engine(self):
1594+
# GH 18519
1595+
N = 5
1596+
keys = [tuple(l) for l in [[0] * 10 * N,
1597+
[1] * 10 * N,
1598+
[2] * 10 * N,
1599+
[np.nan] * N + [2] * 9 * N,
1600+
[0] * N + [2] * 9 * N,
1601+
[np.nan] * N + [2] * 8 * N + [0] * N]]
1602+
# Each level contains 4 elements (including NaN), so it is represented
1603+
# in 2 bits, for a total of 2*N*10 = 100 > 64 bits. If we were using a
1604+
# 64 bit engine and truncating the first levels, the fourth and fifth
1605+
# keys would collide; if truncating the last levels, the fifth and
1606+
# sixth; if rotating bits rather than shifting, the third and fifth.
1607+
1608+
for idx in range(len(keys)):
1609+
index = MultiIndex.from_tuples(keys)
1610+
assert index.get_loc(keys[idx]) == idx
1611+
1612+
expected = np.arange(idx + 1, dtype='int64')
1613+
result = index.get_indexer([keys[i] for i in expected])
1614+
tm.assert_numpy_array_equal(result, expected)
1615+
1616+
# With missing key:
1617+
idces = range(len(keys))
1618+
expected = np.array([-1] + list(idces), dtype='int64')
1619+
missing = tuple([0, 1] * 5 * N)
1620+
result = index.get_indexer([missing] + [keys[i] for i in idces])
1621+
tm.assert_numpy_array_equal(result, expected)
1622+
15931623
def test_getitem_lowerdim_corner(self):
15941624
pytest.raises(KeyError, self.frame.loc.__getitem__,
15951625
(('bar', 'three'), 'B'))

0 commit comments

Comments
 (0)