Skip to content
Merged
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
24 changes: 18 additions & 6 deletions pandas-stubs/_libs/tslibs/period.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ class Period(PeriodMixin):
@overload
def __sub__(self, other: PeriodIndex) -> Index: ...
@overload
def __sub__(self, other: Series[Timedelta]) -> Series[Period]: ...
def __sub__(
self, other: Series[Timedelta]
) -> Series[Period]: ... # pyrefly: ignore[bad-specialization]
@overload
def __sub__(self, other: TimedeltaIndex) -> PeriodIndex: ...
@overload
Expand All @@ -94,7 +96,9 @@ class Period(PeriodMixin):
@overload
def __add__(self, other: Index) -> PeriodIndex: ...
@overload
def __add__(self, other: OffsetSeries | Series[Timedelta]) -> Series[Period]: ...
def __add__(
self, other: OffsetSeries | Series[Timedelta]
) -> Series[Period]: ... # pyrefly: ignore[bad-specialization]
# ignore[misc] here because we know all other comparisons
# are False, so we use Literal[False]
@overload
Expand All @@ -112,7 +116,9 @@ class Period(PeriodMixin):
@overload
def __ge__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
@overload
def __ge__(self, other: Series[Period]) -> Series[bool]: ...
def __ge__(
self, other: Series[Period] # pyrefly: ignore[bad-specialization]
) -> Series[bool]: ...
@overload
def __ge__(
self, other: np_ndarray[ShapeT, np.object_]
Expand All @@ -122,7 +128,9 @@ class Period(PeriodMixin):
@overload
def __gt__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
@overload
def __gt__(self, other: Series[Period]) -> Series[bool]: ...
def __gt__(
self, other: Series[Period] # pyrefly: ignore[bad-specialization]
) -> Series[bool]: ...
@overload
def __gt__(
self, other: np_ndarray[ShapeT, np.object_]
Expand All @@ -132,7 +140,9 @@ class Period(PeriodMixin):
@overload
def __le__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
@overload
def __le__(self, other: Series[Period]) -> Series[bool]: ...
def __le__(
self, other: Series[Period] # pyrefly: ignore[bad-specialization]
) -> Series[bool]: ...
@overload
def __le__(
self, other: np_ndarray[ShapeT, np.object_]
Expand All @@ -142,7 +152,9 @@ class Period(PeriodMixin):
@overload
def __lt__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
@overload
def __lt__(self, other: Series[Period]) -> Series[bool]: ...
def __lt__(
self, other: Series[Period] # pyrefly: ignore[bad-specialization]
) -> Series[bool]: ...
@overload
def __lt__(
self, other: np_ndarray[ShapeT, np.object_]
Expand Down
30 changes: 25 additions & 5 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1233,8 +1233,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
Series[_str],
Series,
]: ...
@property
def dt(self) -> _dtDescriptor[S1]: ...
dt = _dtDescriptor[S1]() # type: ignore[misc]
Copy link
Collaborator

Choose a reason for hiding this comment

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

@cmp0xff indicated that the [S1] here may not be necessary (and then the #type: ignore isn't needed either). Can you test that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes that is correct it works, I had missed the comment

@property
def plot(self) -> PlotAccessor: ...
sparse = ...
Expand Down Expand Up @@ -3078,7 +3077,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
other: complex | NumListLike | Index[T_COMPLEX] | Series[T_COMPLEX],
) -> Series: ...
@overload
def __sub__(self, other: Index[Never] | Series[Never]) -> Series: ... # type: ignore[overload-overlap]
def __sub__(self, other: Index[Never] | Series[Never]) -> Series: ...
@overload
def __sub__(
self: Series[bool],
Expand Down Expand Up @@ -3200,7 +3199,9 @@ class Series(IndexOpsMixin[S1], NDFrame):
),
) -> Series[Timedelta]: ...
@overload
def __sub__(self: Series[Period], other: Series[Period]) -> OffsetSeries: ...
def __sub__(
self: Series[Period], other: Series[Period] | Period
) -> Series[BaseOffset]: ...
@overload
def sub(
self: Series[Never],
Expand Down Expand Up @@ -3373,6 +3374,14 @@ class Series(IndexOpsMixin[S1], NDFrame):
axis: int = 0,
) -> Series[Timedelta]: ...
@overload
def sub(
self: Series[Period],
other: Period | Sequence[Period] | PeriodIndex | Series[Period],
level: Level | None = None,
fill_value: float | None = None,
axis: int = 0,
) -> Series[BaseOffset]: ...
@overload
def __rsub__(
self: Series[Never],
other: (
Expand Down Expand Up @@ -3503,6 +3512,10 @@ class Series(IndexOpsMixin[S1], NDFrame):
),
) -> Series[Timedelta]: ...
@overload
def __rsub__(
self: Series[Period], other: Series[Period] | Period
) -> Series[BaseOffset]: ...
@overload
def rsub(
self: Series[Never],
other: (
Expand Down Expand Up @@ -3683,6 +3696,14 @@ class Series(IndexOpsMixin[S1], NDFrame):
axis: int = 0,
) -> Series[Timedelta]: ...
@overload
def rsub(
self: Series[Period],
other: Period | Sequence[Period] | PeriodIndex | Series[Period],
level: Level | None = None,
fill_value: float | None = None,
axis: int = 0,
) -> Series[BaseOffset]: ...
@overload
def __truediv__( # type: ignore[overload-overlap]
self: Series[Never], other: complex | NumListLike | Index | Series
) -> Series: ...
Expand Down Expand Up @@ -4733,7 +4754,6 @@ class _SeriesSubclassBase(Series[S1], Generic[S1, GenericT_co]):
**kwargs,
) -> np_1darray: ...


class OffsetSeries(_SeriesSubclassBase[BaseOffset, np.object_]):
@overload # type: ignore[override]
def __radd__(self, other: Period) -> Series[Period]: ...
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ scipy = { version = ">=1.9.1", python = "<3.14" }
scipy-stubs = ">=1.15.3.0"
SQLAlchemy = ">=2.0.39"
types-python-dateutil = ">=2.8.19"
beautifulsoup4 = ">=4.12.2"
beautifulsoup4 = "<=4.13.5"
html5lib = ">=1.1"
python-calamine = ">=0.2.0"

Expand Down
Empty file.
20 changes: 20 additions & 0 deletions tests/series/arithmetic/period/test_sub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Test module for subtraction operation on Series[Period]."""

import pandas as pd
from typing_extensions import assert_type

from pandas._libs.tslibs.offsets import BaseOffset

from tests import check


def test_sub() -> None:
"""Test sub method for pd.Series[pd.Period]."""
p = pd.Period("2012-1-1", freq="D")
sr = pd.Series([pd.Period("2012-1-1", freq="D")])

check(assert_type(sr - sr, "pd.Series[BaseOffset]"), pd.Series, BaseOffset)
check(assert_type(p - sr, "pd.Series[BaseOffset]"), pd.Series, BaseOffset)
check(assert_type(sr - p, "pd.Series[BaseOffset]"), pd.Series, BaseOffset)
check(assert_type(sr.sub(p), "pd.Series[BaseOffset]"), pd.Series, BaseOffset)
check(assert_type(sr.rsub(p), "pd.Series[BaseOffset]"), pd.Series, BaseOffset)
10 changes: 1 addition & 9 deletions tests/test_scalars.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import datetime
import datetime as dt
from typing import (
TYPE_CHECKING,
Any,
Literal,
Optional,
Expand Down Expand Up @@ -38,13 +37,6 @@
Day,
)

if TYPE_CHECKING:
from pandas.core.series import (
OffsetSeries,
)
else:
OffsetSeries: TypeAlias = pd.Series

if not PD_LTE_23:
from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore # isort: skip
else:
Expand Down Expand Up @@ -1878,7 +1870,7 @@ def test_period_add_subtract() -> None:
check(assert_type(p + as_timedelta_idx, pd.PeriodIndex), pd.PeriodIndex)
check(assert_type(p + as_nat, NaTType), NaTType)
offset_series = as_period_series - as_period_series
check(assert_type(offset_series, OffsetSeries), pd.Series)
check(assert_type(offset_series, "pd.Series[BaseOffset]"), pd.Series)
check(assert_type(p + offset_series, "pd.Series[pd.Period]"), pd.Series, pd.Period)
check(assert_type(p - as_pd_td, pd.Period), pd.Period)
check(assert_type(p - as_dt_td, pd.Period), pd.Period)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_timefuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
)

if TYPE_CHECKING:
from pandas.core.series import ( # noqa: F401
from pandas.core.series import (
IntervalSeries,
OffsetSeries,
)
Expand Down
Loading