-
-
Notifications
You must be signed in to change notification settings - Fork 150
Simplify and improve Series.sum #1362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -187,6 +189,7 @@ from pandas._typing import ( | |
ValueKeyFunc, | ||
VoidDtypeArg, | ||
WriteBuffer, | ||
_T_co, | ||
np_1darray, | ||
np_ndarray_anyint, | ||
np_ndarray_bool, | ||
|
@@ -203,6 +206,10 @@ from pandas.core.dtypes.dtypes import CategoricalDtype | |
|
||
from pandas.plotting import PlotAccessor | ||
|
||
@type_check_only | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just realized that you added the use of There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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( | ||
|
Uh oh!
There was an error while loading. Please reload this page.