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

Closed
Closed
Show file tree
Hide file tree
Changes from 3 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
156 changes: 142 additions & 14 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,16 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def __add__(self, other: S1 | Self) -> Self: ...
@overload
def __add__(
self: Series[int] | Series[float],
other: float | Series[float],
) -> Series[float]: ...
@overload
def __add__(
self: Series[float],
other: int | Series[int],
) -> Series[float]: ...
@overload
def __add__(
self,
other: complex,
Expand All @@ -1629,6 +1639,9 @@ class Series(IndexOpsMixin[S1], NDFrame):
) -> Series[int]: ...
# def __array__(self, dtype: Optional[_bool] = ...) -> _np_ndarray
def __eq__(self, other: object) -> Series[_bool]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
@overload
def __floordiv__(self: Series[float], other: Series[float] | Series[int] | float) -> Series[float]: ... # type: ignore[overload-overlap]
@overload
def __floordiv__(self, other: num | _ListLike | Series[S1]) -> Series[int]: ...
def __ge__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
self, other: S1 | _ListLike | Series[S1] | datetime | timedelta | date
Expand Down Expand Up @@ -1657,11 +1670,29 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def __mul__(self: Series[int], other: Series[float] | float) -> Series[float]: ...
@overload
def __mul__(self: Series[float], other: Series[int] | int) -> Series[float]: ...
@overload
def __mul__(self: Series[Any], other: Series[Any]) -> Series: ...
@overload
def __mul__(self, other: num | _ListLike | Series) -> Series: ...
@overload
def __mod__( # pyright: ignore[reportOverlappingOverload]
self: Series[int], other: int | Series[int]
) -> Series[int]: ...
@overload
def __mod__(self: Series[int], other: float | Series[float]) -> Series[float]: ...
@overload
def __mod__(
self: Series[float], other: float | Series[int] | Series[float]
) -> Series[float]: ...
@overload
def __mod__(self, other: num | _ListLike | Series[S1]) -> Series[S1]: ...
def __ne__(self, other: object) -> Series[_bool]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
@overload
def __pow__(self: Series[int], other: Series[int] | int) -> Series[int]: ...
@overload
def __pow__(self, other: Series[float] | float) -> Series[float]: ...
@overload
def __pow__(self, other: num | _ListLike | Series[S1]) -> Series[S1]: ...
# ignore needed for mypy as we want different results based on the arguments
@overload # type: ignore[override]
Expand All @@ -1686,7 +1717,12 @@ class Series(IndexOpsMixin[S1], NDFrame):
self, other: int | np_ndarray_anyint | Series[int]
) -> Series[int]: ...
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]: ...
@overload
def __rfloordiv__(self: Series[float], other: float | Series[int] | Series[float]) -> Series[float]: ... # type: ignore[misc]
@overload
def __rfloordiv__(
self, other: num | _ListLike | Series[float]
) -> Series[float]: ...
def __rmod__(self, other: num | _ListLike | Series[S1]) -> Series[S1]: ...
@overload
def __rmul__(
Expand Down Expand Up @@ -1731,25 +1767,35 @@ class Series(IndexOpsMixin[S1], NDFrame):
self, other: Timestamp | datetime | TimestampSeries
) -> TimedeltaSeries: ...
@overload
def __sub__(
def __sub__(self, other: S1 | Self) -> Self: ...
@overload
def __sub__( # pyright: ignore[reportOverlappingOverload]
self: Series[int],
other: int | Series[int],
) -> Series[int]: ...
@overload
def __sub__(
self: Series[int],
other: float | Series[float],
) -> Series[float]: ...
@overload
def __sub__(
self: Series[float],
other: int | Series[int],
) -> Series[float]: ...
@overload
def __sub__(
self,
other: complex,
) -> Series[complex]: ...
@overload
def __sub__(self, other: S1 | Self) -> Self: ...
@overload
def __sub__(self, other: num | _ListLike | Series) -> Series: ...
@overload
def __truediv__(self: Series[int], other: Series[int] | int) -> Series[float]: ...
@overload
def __truediv__(
self, other: num | _ListLike | Series[S1] | Path
) -> Series | Self: ...
def __truediv__(self, other: Path) -> Series: ...
@overload
def __truediv__(self, other: num | _ListLike | Series[S1]) -> Series[float]: ...
# ignore needed for mypy as we want different results based on the arguments
@overload # type: ignore[override]
def __xor__( # pyright: ignore[reportOverlappingOverload]
Expand All @@ -1773,7 +1819,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
def iloc(self) -> _iLocIndexerSeries[S1]: ...
@property
def loc(self) -> _LocIndexerSeries[S1]: ...
# Methods
# Met @overload
@overload
def add(
self: Series[int],
Expand All @@ -1783,6 +1829,22 @@ class Series(IndexOpsMixin[S1], NDFrame):
axis: int = ...,
) -> Series[int]: ...
@overload
def add( # pyright: ignore[reportOverlappingOverload]
self,
other: float | Series[float],
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series[float]: ...
@overload
def add(
self: Series[float],
other: int | Series[int],
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series[float]: ...
@overload
def add(
self,
other: complex,
Expand All @@ -1798,6 +1860,14 @@ class Series(IndexOpsMixin[S1], NDFrame):
fill_value: float | None = ...,
axis: int = ...,
) -> Series[S1]: ...
@overload
def add(
self,
other: S1 | Self,
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series: ...
def all(
self,
axis: AxisIndex = ...,
Expand Down Expand Up @@ -1861,13 +1931,30 @@ class Series(IndexOpsMixin[S1], NDFrame):
min_periods: int = ...,
method: CalculationMethod = ...,
) -> Expanding[Series]: ...
@overload
def floordiv( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
self: Series[int],
other: Series[int] | int,
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex | None = ...,
) -> Series[int]: ...
@overload
def floordiv(
self: Series[int] | Series[float],
other: num | _ListLike | Series[S1],
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex | None = ...,
) -> Series[float]: ...
@overload
def floordiv(
self,
other: num | _ListLike | Series[S1],
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex | None = ...,
) -> Series[int]: ...
) -> Self: ...
def ge(
self,
other: Scalar | Series[S1],
Expand Down Expand Up @@ -1945,6 +2032,31 @@ class Series(IndexOpsMixin[S1], NDFrame):
numeric_only: _bool = ...,
**kwargs,
) -> S1: ...
@overload
def mod( # pyright: ignore[reportOverlappingOverload]
self: Series[int],
other: Series[int] | int,
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex | None = ...,
) -> Series[int]: ...
@overload
def mod(
self: Series[int],
other: Series[float] | float,
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex | None = ...,
) -> Series[float]: ...
@overload
def mod(
self: Series[float],
other: Series[int] | Series[float] | float,
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex | None = ...,
) -> Series[float]: ...
@overload
def mod(
self,
other: num | _ListLike | Series[S1],
Expand All @@ -1953,17 +2065,33 @@ class Series(IndexOpsMixin[S1], NDFrame):
axis: AxisIndex | None = ...,
) -> Series[S1]: ...
@overload
def mul(
def mul( # type: ignore[overload-overlap]
self,
other: Series[S1] | Self,
level: Level | None = ...,
fill_value: int | None = ...,
axis: AxisIndex | None = ...,
) -> Self: ...
@overload
def mul( # pyright: ignore[reportOverlappingOverload]
self: Series[int],
other: Series[int] | int,
level: Level | None = ...,
fill_value: int | None = ...,
axis: AxisIndex | None = ...,
) -> Series[int]: ...
@overload
def mul(
self: Series[float],
other: Series[int] | Series[float] | int,
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex | None = ...,
) -> Series[float]: ...
@overload
def mul(
self: Series[int],
other: Series[float],
other: Series[float] | float,
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex | None = ...,
Expand All @@ -1983,7 +2111,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex | None = ...,
) -> Series: ...
) -> Self: ...
def multiply(
self,
other: num | _ListLike | Series[S1],
Expand All @@ -2002,7 +2130,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def pow(
self: Series[int],
other: float,
other: float | Series[float],
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex | None = ...,
Expand Down Expand Up @@ -2161,7 +2289,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def sub(
self: Series[int],
other: float,
other: float | Series[float],
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex | None = ...,
Expand Down
51 changes: 3 additions & 48 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,45 +646,6 @@ def get_depth(url: str) -> int:
check(assert_type(s.apply(lambda x: pd.NA), pd.Series), pd.Series, NAType)


def test_types_element_wise_arithmetic() -> None:
s = pd.Series([0, 1, -10])
s2 = pd.Series([7, -5, 10])

check(assert_type(s + s2, "pd.Series[int]"), pd.Series, np.integer)
check(assert_type(s.add(s2, fill_value=0), "pd.Series[int]"), pd.Series, np.integer)

check(assert_type(s - s2, "pd.Series[int]"), pd.Series, np.integer)
check(assert_type(s.sub(s2, fill_value=0), "pd.Series[int]"), pd.Series, np.integer)

check(assert_type(s * s2, "pd.Series[int]"), pd.Series, np.integer)
check(assert_type(s.mul(s2, fill_value=0), "pd.Series[int]"), pd.Series, np.integer)

# GH1089 should be the following
check(assert_type(s / s2, "pd.Series[float]"), pd.Series, np.float64)
check(
assert_type(s.div(s2, fill_value=0), "pd.Series[float]"), pd.Series, np.float64
)

check(assert_type(s // s2, "pd.Series[int]"), pd.Series, np.integer)
check(
assert_type(s.floordiv(s2, fill_value=0), "pd.Series[int]"),
pd.Series,
np.integer,
)

check(assert_type(s % s2, "pd.Series[int]"), pd.Series, np.integer)
check(assert_type(s.mod(s2, fill_value=0), "pd.Series[int]"), pd.Series, np.integer)

check(assert_type(s ** s2.abs(), "pd.Series[int]"), pd.Series, np.integer)
check(
assert_type(s.pow(s2.abs(), fill_value=0), "pd.Series[int]"),
pd.Series,
np.integer,
)

check(assert_type(divmod(s, s2), tuple["pd.Series[int]", "pd.Series[int]"]), tuple)


def test_types_scalar_arithmetic() -> None:
s = pd.Series([0, 1, -10])

Expand Down Expand Up @@ -714,7 +675,7 @@ def test_types_scalar_arithmetic() -> None:

check(assert_type(s**2, "pd.Series[int]"), pd.Series, np.integer)
check(assert_type(s**0, "pd.Series[int]"), pd.Series, np.integer)
check(assert_type(s**0.213, "pd.Series[int]"), pd.Series, np.float64)
check(assert_type(s**0.213, "pd.Series[float]"), pd.Series, np.float64)
check(assert_type(s.pow(0.5), "pd.Series[float]"), pd.Series, np.float64)


Expand Down Expand Up @@ -1335,15 +1296,9 @@ def test_series_min_max_sub_axis() -> None:
sm = s1 * s2
sd = s1 / s2
check(assert_type(sa, pd.Series), pd.Series)
check(
assert_type(ss, pd.Series), # pyright: ignore[reportAssertTypeFailure]
pd.Series,
)
check(assert_type(ss, pd.Series), pd.Series)
check(assert_type(sm, pd.Series), pd.Series)
check(
assert_type(sd, pd.Series), # pyright: ignore[reportAssertTypeFailure]
pd.Series,
)
check(assert_type(sd, "pd.Series[float]"), pd.Series)


def test_series_index_isin() -> None:
Expand Down
Loading
Loading