Skip to content
Merged
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
31 changes: 9 additions & 22 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ from typing import (
Generic,
Literal,
NoReturn,
Protocol,
final,
overload,
type_check_only,
)

from _typeshed import SupportsGetItem
from matplotlib.axes import (
Axes as PlotAxes,
SubplotBase,
Expand Down Expand Up @@ -187,6 +189,7 @@ from pandas._typing import (
ValueKeyFunc,
VoidDtypeArg,
WriteBuffer,
_T_co,
np_1darray,
np_ndarray_anyint,
np_ndarray_bool,
Expand All @@ -203,6 +206,10 @@ from pandas.core.dtypes.dtypes import CategoricalDtype

from pandas.plotting import PlotAccessor

@type_check_only
Copy link
Collaborator

Choose a reason for hiding this comment

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

I just realized that you added the use of type_check_only in a previous PR, but now I'm wondering if it makes sense in a stub file, because if you're using a stub file, doesn't that mean that its contents are only for type checking?

Copy link
Contributor Author

@hamdanal hamdanal Sep 9, 2025

Choose a reason for hiding this comment

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

This decorator is meant to be used with functions/classes that exist at type checking time but not at runtime. It is not strictly needed but it tells type checkers to flag any misuse of the decorated object at runtime. It is part of the typing module but it only exists at type checking time. The API documentation is here https://docs.python.org/3/library/typing.html#typing.type_check_only and the user guide is here https://typing.python.org/en/latest/guides/writing_stubs.html#stub-only-objects

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK - thanks for the explanation. We probably should be using that more in the pandas stubs

class _SupportsAdd(Protocol[_T_co]):
def __add__(self, value: Self, /) -> _T_co: ...

class _iLocIndexerSeries(_iLocIndexer, Generic[S1]):
# get item
@overload
Expand Down Expand Up @@ -3751,34 +3758,14 @@ class Series(IndexOpsMixin[S1], NDFrame):
numeric_only: _bool = False,
**kwargs: Any,
) -> float: ...
@overload
def sum(
self: Series[Never],
self: SupportsGetItem[Scalar, _SupportsAdd[_T]],
axis: AxisIndex | None = 0,
skipna: _bool | None = ...,
numeric_only: _bool = ...,
min_count: int = ...,
**kwargs: Any,
) -> Any: ...
# between `Series[bool]` and `Series[int]`.
@overload
def sum(
self: Series[bool],
axis: AxisIndex | None = 0,
skipna: _bool | None = ...,
numeric_only: _bool = ...,
min_count: int = ...,
**kwargs: Any,
) -> int: ...
@overload
def sum(
self: Series[S1],
axis: AxisIndex | None = 0,
skipna: _bool | None = ...,
numeric_only: _bool = ...,
min_count: int = ...,
**kwargs: Any,
) -> S1: ...
) -> _T: ...
def to_list(self) -> list[S1]: ...
def tolist(self) -> list[S1]: ...
def var(
Expand Down
Loading