Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
  • Loading branch information
cmp0xff committed Jul 18, 2025
commit 45e0ad30fd18379d6b97f74d8e2a68ca37c3fa3a
5 changes: 4 additions & 1 deletion pandas-stubs/core/indexes/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ from typing_extensions import (
from pandas._libs.interval import _OrderableT
from pandas._typing import (
S1,
S2,
AnyAll,
AxesData,
DropKeep,
Expand Down Expand Up @@ -402,7 +403,9 @@ class Index(IndexOpsMixin[S1]):
@overload
def __getitem__(self, idx: int | tuple[np_ndarray_anyint, ...]) -> S1: ...
@overload
def append(self, other: Index[S1] | Sequence[Index[S1]]) -> Index[S1]: ...
def append(self, other: Index[S1] | Sequence[Index[S1]]) -> Self: ...
@overload
def append(self, other: Index[S2] | Sequence[Index[S2]]) -> Index[S1 | S2]: ...
@overload
def append(self, other: Index | Sequence) -> Index: ...
def putmask(self, mask, value): ...
Expand Down
35 changes: 27 additions & 8 deletions tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import datetime as dt
from typing import (
TYPE_CHECKING,
Any,
Union,
cast,
)

import numpy as np
Expand Down Expand Up @@ -1028,20 +1030,37 @@ def test_getitem() -> None:
check(assert_type(i0[[0, 2]], "pd.Index[str]"), pd.Index, str)


def test_append_any() -> None:
def test_append_mix() -> None:
"""Test pd.Index.append that gives pd.Index[Any]"""
first = pd.Index([1])
second = pd.Index(["a"])
third = pd.Index([1, "a"])
check(assert_type(first.append(second), pd.Index), pd.Index)
check(assert_type(first.append([second]), pd.Index), pd.Index)
check(assert_type(first.append(second), "pd.Index[int | str]"), pd.Index)
check(assert_type(first.append([second]), "pd.Index[int | str]"), pd.Index)

check(assert_type(first.append(third), pd.Index), pd.Index)
check(assert_type(first.append([third]), pd.Index), pd.Index)
check(assert_type(first.append([second, third]), pd.Index), pd.Index)
check(assert_type(first.append(third), "pd.Index[int | str]"), pd.Index) # type: ignore[assert-type]
check(assert_type(first.append([third]), "pd.Index[int | str]"), pd.Index) # type: ignore[assert-type]
check(
assert_type( # type: ignore[assert-type]
first.append([second, third]), # pyright: ignore[reportAssertTypeFailure]
"pd.Index[int | str]",
),
pd.Index,
)

check(assert_type(third.append([]), "pd.Index[str | int]"), pd.Index) # type: ignore[assert-type]
check(assert_type(third.append([first]), pd.Index), pd.Index)
check(assert_type(third.append([]), "pd.Index[int | str]"), pd.Index) # type: ignore[assert-type]
check(
assert_type(third.append(cast("list[Index[Any]]", [])), "pd.Index[int | str]"), # type: ignore[assert-type]
pd.Index,
)
check(assert_type(third.append([first]), "pd.Index[int | str]"), pd.Index) # type: ignore[assert-type]
check(
assert_type( # type: ignore[assert-type]
third.append([first, second]), # pyright: ignore[reportAssertTypeFailure]
"pd.Index[int | str]",
),
pd.Index,
)


def test_append_int() -> None:
Expand Down
Loading