|
3 | 3 | import datetime as dt
|
4 | 4 | from typing import (
|
5 | 5 | TYPE_CHECKING,
|
| 6 | + Any, |
6 | 7 | Union,
|
| 8 | + cast, |
7 | 9 | )
|
8 | 10 |
|
9 | 11 | import numpy as np
|
@@ -1028,20 +1030,37 @@ def test_getitem() -> None:
|
1028 | 1030 | check(assert_type(i0[[0, 2]], "pd.Index[str]"), pd.Index, str)
|
1029 | 1031 |
|
1030 | 1032 |
|
1031 |
| -def test_append_any() -> None: |
| 1033 | +def test_append_mix() -> None: |
1032 | 1034 | """Test pd.Index.append that gives pd.Index[Any]"""
|
1033 | 1035 | first = pd.Index([1])
|
1034 | 1036 | second = pd.Index(["a"])
|
1035 | 1037 | 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 | + check(assert_type(first.append(second), "pd.Index[int | str]"), pd.Index) |
| 1039 | + check(assert_type(first.append([second]), "pd.Index[int | str]"), pd.Index) |
1038 | 1040 |
|
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) |
| 1041 | + check(assert_type(first.append(third), "pd.Index[int | str]"), pd.Index) # type: ignore[assert-type] |
| 1042 | + check(assert_type(first.append([third]), "pd.Index[int | str]"), pd.Index) # type: ignore[assert-type] |
| 1043 | + check( |
| 1044 | + assert_type( # type: ignore[assert-type] |
| 1045 | + first.append([second, third]), # pyright: ignore[reportAssertTypeFailure] |
| 1046 | + "pd.Index[int | str]", |
| 1047 | + ), |
| 1048 | + pd.Index, |
| 1049 | + ) |
1042 | 1050 |
|
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) |
| 1051 | + check(assert_type(third.append([]), "pd.Index[int | str]"), pd.Index) # type: ignore[assert-type] |
| 1052 | + check( |
| 1053 | + assert_type(third.append(cast("list[Index[Any]]", [])), "pd.Index[int | str]"), # type: ignore[assert-type] |
| 1054 | + pd.Index, |
| 1055 | + ) |
| 1056 | + check(assert_type(third.append([first]), "pd.Index[int | str]"), pd.Index) # type: ignore[assert-type] |
| 1057 | + check( |
| 1058 | + assert_type( # type: ignore[assert-type] |
| 1059 | + third.append([first, second]), # pyright: ignore[reportAssertTypeFailure] |
| 1060 | + "pd.Index[int | str]", |
| 1061 | + ), |
| 1062 | + pd.Index, |
| 1063 | + ) |
1045 | 1064 |
|
1046 | 1065 |
|
1047 | 1066 | def test_append_int() -> None:
|
|
0 commit comments