Skip to content
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

GH1089 Migrate frame/series tests to new framework #1093

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
102 changes: 101 additions & 1 deletion pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def dot(self, other: Series[S1]) -> Scalar: ...
@overload
def dot(self, other: DataFrame) -> Series[S1]: ...
def dot(self, other: DataFrame) -> Series: ...
@overload
def dot(
self, other: ArrayLike | dict[_str, np.ndarray] | Sequence[S1] | Index[S1]
Expand Down Expand Up @@ -1609,6 +1609,11 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def __add__(self, other: S1 | Self) -> Self: ...
@overload
def __add__(
self,
other: complex,
) -> Series[complex]: ...
@overload
def __add__(
self,
other: num | _str | timedelta | Timedelta | _ListLike | Series | np.timedelta64,
Expand All @@ -1623,6 +1628,11 @@ class Series(IndexOpsMixin[S1], NDFrame):
self, other: int | np_ndarray_anyint | Series[int]
) -> Series[int]: ...
# def __array__(self, dtype: Optional[_bool] = ...) -> _np_ndarray
@overload
def __div__(self: Series[int], other: Series[int]) -> Series[float]: ...
@overload
def __div__(self: Series[int], other: int) -> Series[float]: ...
Dr-Irv marked this conversation as resolved.
Show resolved Hide resolved
@overload
def __div__(self, other: num | _ListLike | Series[S1]) -> Series[S1]: ...
Dr-Irv marked this conversation as resolved.
Show resolved Hide resolved
def __eq__(self, other: object) -> Series[_bool]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
def __floordiv__(self, other: num | _ListLike | Series[S1]) -> Series[int]: ...
Expand All @@ -1643,6 +1653,14 @@ class Series(IndexOpsMixin[S1], NDFrame):
self, other: timedelta | Timedelta | TimedeltaSeries | np.timedelta64
) -> TimedeltaSeries: ...
Dr-Irv marked this conversation as resolved.
Show resolved Hide resolved
@overload
def __mul__(self: Series[int], other: int) -> Series[int]: ...
@overload
def __mul__(self: Series[int], other: Series[int]) -> Series[int]: ...
Dr-Irv marked this conversation as resolved.
Show resolved Hide resolved
@overload
def __mul__(self: Series[int], other: Series[float]) -> Series[float]: ...
@overload
def __mul__(self: Series[Any], other: Series[Any]) -> Series: ...
@overload
def __mul__(self, other: num | _ListLike | Series) -> Series: ...
def __mod__(self, other: num | _ListLike | Series[S1]) -> Series[S1]: ...
def __ne__(self, other: object) -> Series[_bool]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
Expand All @@ -1669,6 +1687,11 @@ class Series(IndexOpsMixin[S1], NDFrame):
def __rand__( # pyright: ignore[reportIncompatibleMethodOverride]
self, other: int | np_ndarray_anyint | Series[int]
) -> Series[int]: ...
@overload
def __rdiv__(self: Series[int], other: int) -> Series[float]: ...
@overload
def __rdiv__(self: Series[int], other: Series[int]) -> Series[float]: ...
@overload
def __rdiv__(self, other: num | _ListLike | Series[S1]) -> Series[S1]: ...
def __rdivmod__(self, other: num | _ListLike | Series[S1]) -> Series[S1]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
def __rfloordiv__(self, other: num | _ListLike | Series[S1]) -> Series[S1]: ...
Expand Down Expand Up @@ -1716,6 +1739,16 @@ class Series(IndexOpsMixin[S1], NDFrame):
self, other: Timestamp | datetime | TimestampSeries
) -> TimedeltaSeries: ...
Dr-Irv marked this conversation as resolved.
Show resolved Hide resolved
@overload
def __sub__(
self: Series[int],
other: int,
Dr-Irv marked this conversation as resolved.
Show resolved Hide resolved
) -> Series[int]: ...
@overload
def __sub__(
self,
other: complex,
) -> Series[complex]: ...
@overload
def __sub__(self, other: num | _ListLike | Series) -> Series: ...
def __truediv__(self, other: num | _ListLike | Series[S1] | Path) -> Series: ...
# ignore needed for mypy as we want different results based on the arguments
Expand All @@ -1742,6 +1775,23 @@ class Series(IndexOpsMixin[S1], NDFrame):
@property
def loc(self) -> _LocIndexerSeries[S1]: ...
# Methods
@overload
def add(
self: Series[int],
other: int,
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series[int]: ...
@overload
def add(
self,
other: complex,
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series[complex]: ...
@overload
def add(
self,
other: Series[S1] | Scalar,
Expand Down Expand Up @@ -1904,6 +1954,22 @@ class Series(IndexOpsMixin[S1], NDFrame):
axis: AxisIndex | None = ...,
) -> Series[S1]: ...
@overload
def mul(
self: Series[int],
other: Series[int],
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex | None = ...,
) -> Series[int]: ...
@overload
def mul(
self: Series[int],
other: Series[float],
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex | None = ...,
) -> Series[float]: ...
@overload
def mul(
self,
other: timedelta | Timedelta | TimedeltaSeries | np.timedelta64,
Expand Down Expand Up @@ -1934,6 +2000,15 @@ class Series(IndexOpsMixin[S1], NDFrame):
axis: AxisIndex = ...,
) -> Series[_bool]: ...
def nunique(self, dropna: _bool = ...) -> int: ...
@overload
def pow(
self: Series[int],
other: float,
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex | None = ...,
) -> Series[float]: ...
@overload
def pow(
self,
other: num | _ListLike | Series[S1],
Expand Down Expand Up @@ -2076,6 +2151,31 @@ class Series(IndexOpsMixin[S1], NDFrame):
numeric_only: _bool = ...,
**kwargs,
) -> float: ...
@overload
def sub(
self: Series[int],
other: int,
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex | None = ...,
) -> Series[int]: ...
@overload
def sub(
self: Series[int],
other: float,
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex | None = ...,
) -> Series[int]: ...
Dr-Irv marked this conversation as resolved.
Show resolved Hide resolved
@overload
def sub(
self,
other: complex,
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex | None = ...,
) -> Series[complex]: ...
@overload
def sub(
self,
other: num | _ListLike | Series[S1],
Expand Down
4 changes: 2 additions & 2 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2451,10 +2451,9 @@ def test_sum_get_add() -> None:


def test_getset_untyped() -> None:
result: int = 10
df = pd.DataFrame({"x": [1, 2, 3, 4, 5], "y": [10, 20, 30, 40, 50]})
# Tests that Dataframe.__getitem__ needs to return untyped series.
result = df["x"].max()
check(assert_type(df["x"].max(), Any), np.integer)


def test_getmultiindex_columns() -> None:
Expand Down Expand Up @@ -2966,6 +2965,7 @@ def sum_mean(x: pd.DataFrame) -> float:
)

lfunc: Callable[[pd.DataFrame], float] = lambda x: x.sum().mean()

with pytest_warns_bounded(
DeprecationWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
Expand Down
Loading
Loading