Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions pandas-stubs/core/indexes/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
def __lt__(self, other: Self | S1) -> np_1darray_bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
def __gt__(self, other: Self | S1) -> np_1darray_bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
@overload
def __add__(self: Index[Never], other: _str) -> Never: ...
def __add__(self: Index[Never], other: _str) -> Index[_str]: ...
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add tests in tests/indexes/arithmetic/test_add.py

@overload
def __add__(
self: Index[Never], other: complex | ArrayLike | SequenceNotStr[S1] | Index
Expand Down Expand Up @@ -680,7 +680,7 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
self: Index[_str], other: np_ndarray_str | Index[_str]
) -> Index[_str]: ...
@overload
def __radd__(self: Index[Never], other: _str) -> Never: ...
def __radd__(self: Index[Never], other: _str) -> Index[_str]: ...
@overload
def __radd__(
self: Index[Never], other: complex | ArrayLike | SequenceNotStr[S1] | Index
Expand Down
20 changes: 13 additions & 7 deletions pandas-stubs/core/reshape/pivot.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ _Values: TypeAlias = SequenceNotStr[Any] | _ExtendedAnyArrayLike
@overload
def pivot_table(
data: DataFrame,
values: _PivotTableValuesTypes[
values: _PivotTableValuesTypes[ # ty: ignore[non-subscriptable]
Hashable # ty: ignore[invalid-type-arguments]
] = None,
index: _PivotTableIndexTypes[Hashable] = None, # ty: ignore[invalid-type-arguments]
columns: _PivotTableColumnsTypes[
index: _PivotTableIndexTypes[ # ty: ignore[non-subscriptable]
Hashable # ty: ignore[invalid-type-arguments]
] = None,
columns: _PivotTableColumnsTypes[ # ty: ignore[non-subscriptable]
Comment on lines +70 to +76
Copy link
Contributor

Choose a reason for hiding this comment

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

Proposing an alternative fix in #1547. This is related to astral-sh/ty#1846.

Hashable # ty: ignore[invalid-type-arguments]
] = None,
aggfunc: (
Expand All @@ -91,13 +93,15 @@ def pivot_table(
@overload
def pivot_table(
data: DataFrame,
values: _PivotTableValuesTypes[
values: _PivotTableValuesTypes[ # ty: ignore[non-subscriptable]
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a bit surprising that we now need to ty: ignore's here. Would be great if you could report it to ty.

Copy link
Contributor

@cmp0xff cmp0xff Dec 14, 2025

Choose a reason for hiding this comment

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

Proposing an alternative fix in #1547. This is related to astral-sh/ty#1846.

Hashable # ty: ignore[invalid-type-arguments]
] = None,
*,
index: Grouper,
columns: (
_PivotTableColumnsTypes[Hashable] # ty: ignore[invalid-type-arguments]
_PivotTableColumnsTypes[ # ty: ignore[non-subscriptable]
Hashable # ty: ignore[invalid-type-arguments]
]
Comment on lines +102 to +104
Copy link
Contributor

Choose a reason for hiding this comment

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

Proposing an alternative fix in #1547. This is related to astral-sh/ty#1846.

| np_ndarray
| Index[Any]
) = None,
Expand All @@ -116,11 +120,13 @@ def pivot_table(
@overload
def pivot_table(
data: DataFrame,
values: _PivotTableValuesTypes[
values: _PivotTableValuesTypes[ # ty: ignore[non-subscriptable]
Hashable # ty: ignore[invalid-type-arguments]
] = None,
index: (
_PivotTableIndexTypes[Hashable] # ty: ignore[invalid-type-arguments]
_PivotTableIndexTypes[ # ty: ignore[non-subscriptable]
Hashable # ty: ignore[invalid-type-arguments]
]
Comment on lines +123 to +129
Copy link
Contributor

Choose a reason for hiding this comment

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

Proposing an alternative fix in #1547. This is related to astral-sh/ty#1846.

| np_ndarray
| Index[Any]
) = None,
Expand Down
4 changes: 4 additions & 0 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,8 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
# just failed to generate these so I couldn't match
# them up.
@overload
def __add__(self: Series[Never], other: _str) -> Series[_str]: ...
@overload
def __add__(self: Series[Never], other: complex | ListLike) -> Series: ...
@overload
def __add__(self, other: Index[Never] | Series[Never]) -> Series: ...
Expand Down Expand Up @@ -2008,6 +2010,8 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
axis: int = 0,
) -> Series[_str]: ...
@overload
def __radd__(self: Series[Never], other: _str) -> Series[_str]: ...
@overload
def __radd__(self: Series[Never], other: complex | ListLike) -> Series: ...
@overload
def __radd__(self, other: Index[Never] | Series[Never]) -> Series: ...
Expand Down
6 changes: 3 additions & 3 deletions tests/indexes/arithmetic/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import numpy as np
import pandas as pd
from typing_extensions import (
Never,
assert_type,
)
Comment on lines 5 to 7
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
from typing_extensions import (
Never,
assert_type,
)
from typing_extensions import assert_type


Expand Down Expand Up @@ -107,5 +106,6 @@ def test_add_i_py_str() -> None:
s = "abc"

if TYPE_CHECKING_INVALID_USAGE:
assert_type(left_i + s, Never)
assert_type(s + left_i, Never)
# relaxing typing, won't work at runtime though
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# relaxing typing, won't work at runtime though
# GH1541 relaxing typing, won't work at runtime though

assert_type(left_i + s, "pd.Index[str]")
assert_type(s + left_i, "pd.Index[str]")
9 changes: 9 additions & 0 deletions tests/series/arithmetic/str/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,12 @@ def test_add_pd_series() -> None:
if TYPE_CHECKING_INVALID_USAGE:
left.radd(i) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue]
check(assert_type(left.radd(r0), "pd.Series[str]"), pd.Series, str)


def test_series_add_str() -> None:
"""Test Series.__add__ with Series[Any]."""
df = pd.DataFrame({0: ["a", "b"]})
sr = df[0]

check(assert_type(sr + "c1", "pd.Series[str]"), pd.Series, str)
check(assert_type("c1" + sr, "pd.Series[str]"), pd.Series, str)
Copy link
Contributor

Choose a reason for hiding this comment

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

  • series/arithmetic/str/test_add.py is meant to test for known Series[str]. For Series[Any] at type checking, the plan is to use series/arithmetic/test_add.py. Please move this part there.
    • We also have a left_str = pd.DataFrame({"a": ["1", "2", "3_"]})["a"] defined in that file.
  • Please also make the undunder methods add and radd work

4 changes: 3 additions & 1 deletion tests/test_timefuncs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import annotations

import datetime as dt
from typing import TypeAlias
from typing import (
TypeAlias,
)
Comment on lines +4 to +6
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
from typing import (
TypeAlias,
)
from typing import TypeAlias


from dateutil.relativedelta import (
FR,
Expand Down