@@ -1028,6 +1028,49 @@ def test_getitem() -> None:
10281028 check (assert_type (i0 [[0 , 2 ]], "pd.Index[str]" ), pd .Index , str )
10291029
10301030
1031+ def test_append_any () -> None :
1032+ """Test pd.Index.append that gives pd.Index[Any]"""
1033+ first = pd .Index ([1 ])
1034+ second = pd .Index (["a" ])
1035+ third = pd .Index ([1 , "a" ])
1036+ check (assert_type (first .append (second ), pd .Index ), pd .Index )
1037+ check (assert_type (first .append ([second ]), pd .Index ), pd .Index )
1038+
1039+ check (assert_type (first .append (third ), pd .Index ), pd .Index )
1040+ check (assert_type (first .append ([third ]), pd .Index ), pd .Index )
1041+ check (assert_type (first .append ([second , third ]), pd .Index ), pd .Index )
1042+
1043+ check (assert_type (third .append ([]), "pd.Index[str | int]" ), pd .Index ) # type: ignore[assert-type]
1044+ check (assert_type (third .append ([first ]), pd .Index ), pd .Index )
1045+
1046+
1047+ def test_append_int () -> None :
1048+ """Test pd.Index[int].append"""
1049+ first = pd .Index ([1 ])
1050+ second = pd .Index ([2 ])
1051+ check (assert_type (first .append ([]), "pd.Index[int]" ), pd .Index , np .int64 )
1052+ check (assert_type (first .append (second ), "pd.Index[int]" ), pd .Index , np .int64 )
1053+ check (assert_type (first .append ([second ]), "pd.Index[int]" ), pd .Index , np .int64 )
1054+
1055+
1056+ def test_append_str () -> None :
1057+ """Test pd.Index[str].append"""
1058+ first = pd .Index (["str" ])
1059+ second = pd .Index (["rts" ])
1060+ check (assert_type (first .append ([]), "pd.Index[str]" ), pd .Index , str )
1061+ check (assert_type (first .append (second ), "pd.Index[str]" ), pd .Index , str )
1062+ check (assert_type (first .append ([second ]), "pd.Index[str]" ), pd .Index , str )
1063+
1064+
1065+ def test_append_list_str () -> None :
1066+ """Test pd.Index[list[str]].append"""
1067+ first = pd .Index ([["str" , "rts" ]])
1068+ second = pd .Index ([["srt" , "trs" ]])
1069+ check (assert_type (first .append ([]), "pd.Index[list[str]]" ), pd .Index , list )
1070+ check (assert_type (first .append (second ), "pd.Index[list[str]]" ), pd .Index , list )
1071+ check (assert_type (first .append ([second ]), "pd.Index[list[str]]" ), pd .Index , list )
1072+
1073+
10311074def test_range_index_range () -> None :
10321075 """Test that pd.RangeIndex can be initialized from range."""
10331076 iri = pd .RangeIndex (range (5 ))
0 commit comments