MCPcopy
hub / github.com/pandas-dev/pandas / test_join_multi

Function test_join_multi

pandas/tests/indexes/multi/test_join.py:63–94  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

61
62
63def test_join_multi():
64 # GH 10665
65 midx = MultiIndex.from_product([np.arange(4), np.arange(4)], names=["a", "b"])
66 idx = Index([1, 2, 5], name="b")
67
68 # inner
69 jidx, lidx, ridx = midx.join(idx, how="inner", return_indexers=True)
70 exp_idx = MultiIndex.from_product([np.arange(4), [1, 2]], names=["a", "b"])
71 exp_lidx = np.array([1, 2, 5, 6, 9, 10, 13, 14], dtype=np.intp)
72 exp_ridx = np.array([0, 1, 0, 1, 0, 1, 0, 1], dtype=np.intp)
73 tm.assert_index_equal(jidx, exp_idx)
74 tm.assert_numpy_array_equal(lidx, exp_lidx)
75 tm.assert_numpy_array_equal(ridx, exp_ridx)
76 # flip
77 jidx, ridx, lidx = idx.join(midx, how="inner", return_indexers=True)
78 tm.assert_index_equal(jidx, exp_idx)
79 tm.assert_numpy_array_equal(lidx, exp_lidx)
80 tm.assert_numpy_array_equal(ridx, exp_ridx)
81
82 # keep MultiIndex
83 jidx, lidx, ridx = midx.join(idx, how="left", return_indexers=True)
84 exp_ridx = np.array(
85 [-1, 0, 1, -1, -1, 0, 1, -1, -1, 0, 1, -1, -1, 0, 1, -1], dtype=np.intp
86 )
87 tm.assert_index_equal(jidx, midx)
88 assert lidx is None
89 tm.assert_numpy_array_equal(ridx, exp_ridx)
90 # flip
91 jidx, ridx, lidx = idx.join(midx, how="right", return_indexers=True)
92 tm.assert_index_equal(jidx, midx)
93 assert lidx is None
94 tm.assert_numpy_array_equal(ridx, exp_ridx)
95
96
97def test_join_multi_wrong_order():

Callers

nothing calls this directly

Calls 5

joinMethod · 0.95
IndexClass · 0.90
from_productMethod · 0.80
joinMethod · 0.45
arrayMethod · 0.45

Tested by

no test coverage detected