@@ -21,20 +21,14 @@ def test_join_non_unique(self):
21
21
tm .assert_numpy_array_equal (ridx , exp_ridx )
22
22
23
23
def test_join_inner (self ):
24
- index = Index (range (0 , 20 , 2 ), dtype = np .int64 )
25
- other = Index ([7 , 12 , 25 , 1 , 2 , 5 ], dtype = np .int64 )
26
- other_mono = Index ([1 , 2 , 5 , 7 , 12 , 25 ], dtype = np .int64 )
24
+ index = Index (range (0 , 20 , 2 ), dtype = np .int64 , name = "lhs" )
25
+ other = Index ([7 , 12 , 25 , 1 , 2 , 5 ], dtype = np .int64 , name = "rhs" )
26
+ other_mono = Index ([1 , 2 , 5 , 7 , 12 , 25 ], dtype = np .int64 , name = "rhs" )
27
27
28
28
# not monotonic
29
29
res , lidx , ridx = index .join (other , how = "inner" , return_indexers = True )
30
30
31
- # no guarantee of sortedness, so sort for comparison purposes
32
- ind = res .argsort ()
33
- res = res .take (ind )
34
- lidx = lidx .take (ind )
35
- ridx = ridx .take (ind )
36
-
37
- eres = Index ([2 , 12 ], dtype = np .int64 )
31
+ eres = Index ([2 , 12 ], dtype = np .int64 , name = "lhs" )
38
32
elidx = np .array ([1 , 6 ], dtype = np .intp )
39
33
eridx = np .array ([4 , 1 ], dtype = np .intp )
40
34
@@ -46,7 +40,7 @@ def test_join_inner(self):
46
40
# monotonic
47
41
res , lidx , ridx = index .join (other_mono , how = "inner" , return_indexers = True )
48
42
49
- res2 = index .intersection (other_mono )
43
+ res2 = index .intersection (other_mono ). set_names ([ "lhs" ])
50
44
tm .assert_index_equal (res , res2 )
51
45
52
46
elidx = np .array ([1 , 6 ], dtype = np .intp )
@@ -57,9 +51,9 @@ def test_join_inner(self):
57
51
tm .assert_numpy_array_equal (ridx , eridx )
58
52
59
53
def test_join_left (self ):
60
- index = Index (range (0 , 20 , 2 ), dtype = np .int64 )
61
- other = Index ([7 , 12 , 25 , 1 , 2 , 5 ], dtype = np .int64 )
62
- other_mono = Index ([1 , 2 , 5 , 7 , 12 , 25 ], dtype = np .int64 )
54
+ index = Index (range (0 , 20 , 2 ), dtype = np .int64 , name = "lhs" )
55
+ other = Index ([7 , 12 , 25 , 1 , 2 , 5 ], dtype = np .int64 , name = "rhs" )
56
+ other_mono = Index ([1 , 2 , 5 , 7 , 12 , 25 ], dtype = np .int64 , name = "rhs" )
63
57
64
58
# not monotonic
65
59
res , lidx , ridx = index .join (other , how = "left" , return_indexers = True )
@@ -80,20 +74,20 @@ def test_join_left(self):
80
74
tm .assert_numpy_array_equal (ridx , eridx )
81
75
82
76
# non-unique
83
- idx = Index ([1 , 1 , 2 , 5 ])
84
- idx2 = Index ([1 , 2 , 5 , 7 , 9 ])
77
+ idx = Index ([1 , 1 , 2 , 5 ], name = "rhs" )
78
+ idx2 = Index ([1 , 2 , 5 , 7 , 9 ], name = "lhs" )
85
79
res , lidx , ridx = idx2 .join (idx , how = "left" , return_indexers = True )
86
- eres = Index ([1 , 1 , 2 , 5 , 7 , 9 ]) # 1 is in idx2, so it should be x2
80
+ eres = Index ([1 , 1 , 2 , 5 , 7 , 9 ], name = "lhs" ) # 1 is in idx2, so it should be x2
87
81
eridx = np .array ([0 , 1 , 2 , 3 , - 1 , - 1 ], dtype = np .intp )
88
82
elidx = np .array ([0 , 0 , 1 , 2 , 3 , 4 ], dtype = np .intp )
89
83
tm .assert_index_equal (res , eres )
90
84
tm .assert_numpy_array_equal (lidx , elidx )
91
85
tm .assert_numpy_array_equal (ridx , eridx )
92
86
93
87
def test_join_right (self ):
94
- index = Index (range (0 , 20 , 2 ), dtype = np .int64 )
95
- other = Index ([7 , 12 , 25 , 1 , 2 , 5 ], dtype = np .int64 )
96
- other_mono = Index ([1 , 2 , 5 , 7 , 12 , 25 ], dtype = np .int64 )
88
+ index = Index (range (0 , 20 , 2 ), dtype = np .int64 , name = "lhs" )
89
+ other = Index ([7 , 12 , 25 , 1 , 2 , 5 ], dtype = np .int64 , name = "rhs" )
90
+ other_mono = Index ([1 , 2 , 5 , 7 , 12 , 25 ], dtype = np .int64 , name = "rhs" )
97
91
98
92
# not monotonic
99
93
res , lidx , ridx = index .join (other , how = "right" , return_indexers = True )
@@ -115,10 +109,10 @@ def test_join_right(self):
115
109
assert ridx is None
116
110
117
111
# non-unique
118
- idx = Index ([1 , 1 , 2 , 5 ])
119
- idx2 = Index ([1 , 2 , 5 , 7 , 9 ])
112
+ idx = Index ([1 , 1 , 2 , 5 ], name = "lhs" )
113
+ idx2 = Index ([1 , 2 , 5 , 7 , 9 ], name = "rhs" )
120
114
res , lidx , ridx = idx .join (idx2 , how = "right" , return_indexers = True )
121
- eres = Index ([1 , 1 , 2 , 5 , 7 , 9 ]) # 1 is in idx2, so it should be x2
115
+ eres = Index ([1 , 1 , 2 , 5 , 7 , 9 ], name = "rhs" ) # 1 is in idx2, so it should be x2
122
116
elidx = np .array ([0 , 1 , 2 , 3 , - 1 , - 1 ], dtype = np .intp )
123
117
eridx = np .array ([0 , 0 , 1 , 2 , 3 , 4 ], dtype = np .intp )
124
118
tm .assert_index_equal (res , eres )
0 commit comments