diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 4a93287bb..dd831af46 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -1143,12 +1143,8 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]): def __div__(self, other: num | _ListLike | Series[S1]) -> Series[S1]: ... def __eq__(self, other: object) -> Series[_bool]: ... # type: ignore[override] def __floordiv__(self, other: num | _ListLike | Series[S1]) -> Series[int]: ... - def __ge__( - self, other: num | _ListLike | Series[S1] | Timestamp - ) -> Series[_bool]: ... - def __gt__( - self, other: num | _ListLike | Series[S1] | Timestamp - ) -> Series[_bool]: ... + def __ge__(self, other: S1 | _ListLike | Series[S1]) -> Series[_bool]: ... + def __gt__(self, other: S1 | _ListLike | Series[S1]) -> Series[_bool]: ... # def __iadd__(self, other: S1) -> Series[S1]: ... # def __iand__(self, other: S1) -> Series[_bool]: ... # def __idiv__(self, other: S1) -> Series[S1]: ... @@ -1161,12 +1157,8 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]): # def __itruediv__(self, other: S1) -> Series[S1]: ... # def __itruediv__(self, other) -> None: ... # def __ixor__(self, other: S1) -> Series[_bool]: ... - def __le__( - self, other: num | _ListLike | Series[S1] | Timestamp - ) -> Series[_bool]: ... - def __lt__( - self, other: num | _ListLike | Series[S1] | Timestamp - ) -> Series[_bool]: ... + def __le__(self, other: S1 | _ListLike | Series[S1]) -> Series[_bool]: ... + def __lt__(self, other: S1 | _ListLike | Series[S1]) -> Series[_bool]: ... @overload def __mul__(self, other: Timedelta | TimedeltaSeries) -> TimedeltaSeries: ... @overload diff --git a/tests/test_series.py b/tests/test_series.py index 898b91323..c592a652e 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -1,5 +1,6 @@ from __future__ import annotations +import datetime from pathlib import Path import re import tempfile @@ -948,3 +949,72 @@ def test_series_overloads_extract(): assert_type(s.str.extract(r"[ab](\d)", re.IGNORECASE, False), pd.Series), pd.Series, ) + + +def test_relops() -> None: + # GH 175 + s: str = "abc" + check(assert_type(pd.Series([s]) > s, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([s]) < s, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([s]) <= s, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([s]) >= s, "pd.Series[bool]"), pd.Series, bool) + + b: bytes = b"def" + check(assert_type(pd.Series([b]) > b, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([b]) < b, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([b]) <= b, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([b]) >= b, "pd.Series[bool]"), pd.Series, bool) + + dtd = datetime.date(2022, 7, 31) + check(assert_type(pd.Series([dtd]) > dtd, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([dtd]) < dtd, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([dtd]) <= dtd, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([dtd]) >= dtd, "pd.Series[bool]"), pd.Series, bool) + + dtdt = datetime.datetime(2022, 7, 31, 8, 32, 21) + check(assert_type(pd.Series([dtdt]) > dtdt, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([dtdt]) < dtdt, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([dtdt]) <= dtdt, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([dtdt]) >= dtdt, "pd.Series[bool]"), pd.Series, bool) + + dttd = datetime.timedelta(seconds=10) + check(assert_type(pd.Series([dttd]) > dttd, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([dttd]) < dttd, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([dttd]) <= dttd, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([dttd]) >= dttd, "pd.Series[bool]"), pd.Series, bool) + + bo: bool = True + check(assert_type(pd.Series([bo]) > bo, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([bo]) < bo, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([bo]) <= bo, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([bo]) >= bo, "pd.Series[bool]"), pd.Series, bool) + + ai: int = 10 + check(assert_type(pd.Series([ai]) > ai, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([ai]) < ai, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([ai]) <= ai, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([ai]) >= ai, "pd.Series[bool]"), pd.Series, bool) + + af: float = 3.14 + check(assert_type(pd.Series([af]) > af, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([af]) < af, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([af]) <= af, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([af]) >= af, "pd.Series[bool]"), pd.Series, bool) + + ac: complex = 1 + 2j + check(assert_type(pd.Series([ac]) > ac, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([ac]) < ac, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([ac]) <= ac, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([ac]) >= ac, "pd.Series[bool]"), pd.Series, bool) + + ts = pd.Timestamp("2022-07-31 08:35:12") + check(assert_type(pd.Series([ts]) > ts, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([ts]) < ts, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([ts]) <= ts, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([ts]) >= ts, "pd.Series[bool]"), pd.Series, bool) + + td = pd.Timedelta(seconds=10) + check(assert_type(pd.Series([td]) > td, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([td]) < td, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([td]) <= td, "pd.Series[bool]"), pd.Series, bool) + check(assert_type(pd.Series([td]) >= td, "pd.Series[bool]"), pd.Series, bool)