@@ -1012,6 +1012,78 @@ def test_join_self(self, index, join_type):
10121012 expected = expected .sort_values ()
10131013 tm .assert_index_equal (result , expected )
10141014
1015+ def test_join_both_unique (self , join_type ):
1016+ idx1 = Index ([1 , 2 , 3 ], name = "index1" )
1017+ idx2 = Index ([4 , 5 , 6 ], name = "index2" )
1018+ result = idx1 .join (idx2 , how = join_type )
1019+
1020+ if join_type == "outer" :
1021+ expected = Index ([1 , 2 , 3 , 4 , 5 , 6 ], name = None )
1022+ elif join_type == "inner" :
1023+ expected = Index ([], name = None )
1024+ elif join_type == "left" :
1025+ expected = Index ([1 , 2 , 3 ], name = None )
1026+ elif join_type == "right" :
1027+ expected = Index ([4 , 5 , 6 ], name = None )
1028+
1029+ tm .assert_index_equal (result , expected )
1030+
1031+ def test_join_one_unique (self , join_type ):
1032+ idx1 = Index ([1 , 2 , 3 ], name = "index1" )
1033+ idx2 = Index ([3 , 3 , 4 ], name = "index2" )
1034+ result = idx1 .join (idx2 , how = join_type )
1035+
1036+ if join_type == "outer" :
1037+ expected = Index ([1 , 2 , 3 , 3 , 4 ], name = None )
1038+ elif join_type == "inner" :
1039+ expected = Index ([3 ], name = None )
1040+ elif join_type == "left" :
1041+ expected = Index ([1 , 2 , 3 ], name = None )
1042+ elif join_type == "right" :
1043+ expected = Index ([3 , 3 , 4 ], name = None )
1044+
1045+ tm .assert_index_equal (result , expected )
1046+
1047+ def test_join_neither_unique (self , join_type ):
1048+ idx1 = Index ([1 , 1 , 2 ], name = "index1" )
1049+ idx2 = Index ([2 , 2 , 3 ], name = "index2" )
1050+ result = idx1 .join (idx2 , how = join_type )
1051+
1052+ if join_type == "outer" :
1053+ expected = Index ([1 , 1 , 2 , 2 , 2 , 3 ], name = None )
1054+ elif join_type == "inner" :
1055+ expected = Index ([2 , 2 ], name = None )
1056+ elif join_type == "left" :
1057+ expected = Index ([1 , 1 , 2 ], name = None )
1058+ elif join_type == "right" :
1059+ expected = Index ([2 , 2 , 3 ], name = None )
1060+
1061+ tm .assert_index_equal (result , expected )
1062+
1063+ def test_join_empty_indexes (self , join_type ):
1064+ idx1 = Index ([], name = "index1" )
1065+ idx2 = Index ([], name = "index2" )
1066+ result = idx1 .join (idx2 , how = join_type )
1067+
1068+ expected = Index ([], name = None )
1069+ tm .assert_index_equal (result , expected )
1070+
1071+ def test_join_mixed_types (self , join_type ):
1072+ idx1 = Index ([1 , "a" , 3 ], name = "index1" )
1073+ idx2 = Index (["b" , 2 , "a" ], name = "index2" )
1074+ result = idx1 .join (idx2 , how = join_type )
1075+
1076+ if join_type == "outer" :
1077+ expected = Index ([1 , 2 , 3 , "a" , "b" ], name = None )
1078+ elif join_type == "inner" :
1079+ expected = Index (["a" ], name = None )
1080+ elif join_type == "left" :
1081+ expected = Index ([1 , "a" , 3 ], name = None )
1082+ elif join_type == "right" :
1083+ expected = Index (["b" , 2 , "a" ], name = None )
1084+
1085+ tm .assert_index_equal (result , expected )
1086+
10151087 @pytest .mark .parametrize ("method" , ["strip" , "rstrip" , "lstrip" ])
10161088 def test_str_attribute (self , method ):
10171089 # GH9068
0 commit comments