Skip to content

Commit 4f31f3c

Browse files
committed
TST: test MultiIndexPyIntEngine
1 parent 3ad8335 commit 4f31f3c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

pandas/tests/test_multilevel.py

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

1593+
def test_huge_index_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+
idces = np.arange(idx + 1, dtype=int)
1613+
expected = idces
1614+
result = index.get_indexer([keys[i] for i in idces])
1615+
assert tm.assert_numpy_array_equal(result, expected)
1616+
1617+
# With missing key:
1618+
idces = range(len(keys))
1619+
expected = np.array([-1] + list(idces), dtype=int)
1620+
missing = tuple([0, 1] * 5 * N)
1621+
result = index.get_indexer([missing] + [keys[i] for i in idces])
1622+
assert tm.assert_numpy_array_equal(result, expected)
1623+
15931624
def test_getitem_lowerdim_corner(self):
15941625
pytest.raises(KeyError, self.frame.loc.__getitem__,
15951626
(('bar', 'three'), 'B'))

0 commit comments

Comments
 (0)