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
fix(comment): #1282 (comment)
  • Loading branch information
cmp0xff committed Jul 29, 2025
commit 67e6bde96ea6894aa32b827610347f76c2728989
9 changes: 2 additions & 7 deletions pandas-stubs/core/indexes/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ from typing import (
ClassVar,
Literal,
TypeAlias,
TypeVar,
final,
overload,
)
Expand Down Expand Up @@ -66,8 +65,6 @@ from pandas._typing import (
type_t,
)

_T_INDEX = TypeVar("_T_INDEX", bound=Index) # ty: ignore[unresolved-reference]

class InvalidIndexError(Exception): ...

class Index(IndexOpsMixin[S1]):
Expand Down Expand Up @@ -408,11 +405,9 @@ class Index(IndexOpsMixin[S1]):
@overload
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: Sequence[_T_INDEX]) -> Self | _T_INDEX: ...
def append(self, other: Index[S2]) -> Index[S1 | S2]: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def append(self, other: Index[S2]) -> Index[S1 | S2]: ...
def append(self, other: Index[S2]) -> Index: ...

I really want to avoid having the union types here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@overload
def append(self, other: Index | Sequence) -> Index: ...
def append(self, other: Sequence) -> Index: ...
def putmask(self, mask, value): ...
def equals(self, other) -> bool: ...
@final
Expand Down
20 changes: 10 additions & 10 deletions tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,31 +1036,31 @@ def test_append_mix() -> None:
second = pd.Index(["a"])
third = pd.Index([1, "a"])
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([second]), 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]",
first.append(third), "pd.Index[int | str]"
),
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(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]
assert_type( # type: ignore[assert-type]
third.append([]), "pd.Index[int | str]"
),
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]",
third.append(cast("list[Index[Any]]", [])), "pd.Index[int | str]"
),
pd.Index,
)
check(assert_type(third.append([first]), pd.Index), pd.Index)
check(assert_type(third.append([first, second]), pd.Index), pd.Index)


def test_append_int() -> None:
Expand Down
Loading