Skip to content

Commit e571f9e

Browse files
GH1379 Remove PeriodSeries (#1386)
* GH1379 Remove PeriodSeries * GH1379 PR feedback * GH1379 PR feedback * GH1379 PR feedback * GH1379 PR feedback
1 parent b197a8b commit e571f9e

File tree

8 files changed

+107
-51
lines changed

8 files changed

+107
-51
lines changed

pandas-stubs/_libs/tslibs/period.pyi

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ from pandas import (
1414
)
1515
from pandas.core.series import (
1616
OffsetSeries,
17-
PeriodSeries,
1817
)
1918
from typing_extensions import TypeAlias
2019

@@ -85,7 +84,9 @@ class Period(PeriodMixin):
8584
@overload
8685
def __sub__(self, other: PeriodIndex) -> Index: ...
8786
@overload
88-
def __sub__(self, other: Series[Timedelta]) -> PeriodSeries: ...
87+
def __sub__(
88+
self, other: Series[Timedelta]
89+
) -> Series[Period]: ... # pyrefly: ignore[bad-specialization]
8990
@overload
9091
def __sub__(self, other: TimedeltaIndex) -> PeriodIndex: ...
9192
@overload
@@ -95,15 +96,17 @@ class Period(PeriodMixin):
9596
@overload
9697
def __add__(self, other: Index) -> PeriodIndex: ...
9798
@overload
98-
def __add__(self, other: OffsetSeries | Series[Timedelta]) -> PeriodSeries: ...
99+
def __add__(
100+
self, other: OffsetSeries | Series[Timedelta]
101+
) -> Series[Period]: ... # pyrefly: ignore[bad-specialization]
99102
# ignore[misc] here because we know all other comparisons
100103
# are False, so we use Literal[False]
101104
@overload
102105
def __eq__(self, other: Period) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
103106
@overload
104107
def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
105108
@overload
106-
def __eq__(self, other: PeriodSeries) -> Series[bool]: ... # type: ignore[overload-overlap]
109+
def __eq__(self, other: Series[Period]) -> Series[bool]: ... # type: ignore[overload-overlap]
107110
@overload
108111
def __eq__(self, other: np_ndarray[ShapeT, np.object_]) -> np_ndarray[ShapeT, np.bool]: ... # type: ignore[overload-overlap]
109112
@overload
@@ -113,7 +116,9 @@ class Period(PeriodMixin):
113116
@overload
114117
def __ge__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
115118
@overload
116-
def __ge__(self, other: PeriodSeries) -> Series[bool]: ...
119+
def __ge__(
120+
self, other: Series[Period] # pyrefly: ignore[bad-specialization]
121+
) -> Series[bool]: ...
117122
@overload
118123
def __ge__(
119124
self, other: np_ndarray[ShapeT, np.object_]
@@ -123,7 +128,9 @@ class Period(PeriodMixin):
123128
@overload
124129
def __gt__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
125130
@overload
126-
def __gt__(self, other: PeriodSeries) -> Series[bool]: ...
131+
def __gt__(
132+
self, other: Series[Period] # pyrefly: ignore[bad-specialization]
133+
) -> Series[bool]: ...
127134
@overload
128135
def __gt__(
129136
self, other: np_ndarray[ShapeT, np.object_]
@@ -133,7 +140,9 @@ class Period(PeriodMixin):
133140
@overload
134141
def __le__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
135142
@overload
136-
def __le__(self, other: PeriodSeries) -> Series[bool]: ...
143+
def __le__(
144+
self, other: Series[Period] # pyrefly: ignore[bad-specialization]
145+
) -> Series[bool]: ...
137146
@overload
138147
def __le__(
139148
self, other: np_ndarray[ShapeT, np.object_]
@@ -143,7 +152,9 @@ class Period(PeriodMixin):
143152
@overload
144153
def __lt__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
145154
@overload
146-
def __lt__(self, other: PeriodSeries) -> Series[bool]: ...
155+
def __lt__(
156+
self, other: Series[Period] # pyrefly: ignore[bad-specialization]
157+
) -> Series[bool]: ...
147158
@overload
148159
def __lt__(
149160
self, other: np_ndarray[ShapeT, np.object_]
@@ -155,7 +166,7 @@ class Period(PeriodMixin):
155166
@overload
156167
def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
157168
@overload
158-
def __ne__(self, other: PeriodSeries) -> Series[bool]: ... # type: ignore[overload-overlap]
169+
def __ne__(self, other: Series[Period]) -> Series[bool]: ... # type: ignore[overload-overlap]
159170
@overload
160171
def __ne__(self, other: np_ndarray[ShapeT, np.object_]) -> np_ndarray[ShapeT, np.bool]: ... # type: ignore[overload-overlap]
161172
@overload

pandas-stubs/core/indexes/accessors.pyi

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ from pandas.core.arrays import (
2828
from pandas.core.base import NoNewAttributesMixin
2929
from pandas.core.frame import DataFrame
3030
from pandas.core.series import (
31-
PeriodSeries,
3231
Series,
3332
)
3433
from typing_extensions import Never
3534

3635
from pandas._libs.tslibs import BaseOffset
3736
from pandas._libs.tslibs.offsets import DateOffset
37+
from pandas._libs.tslibs.period import Period
3838
from pandas._typing import (
3939
S1,
4040
TimeAmbiguous,
@@ -208,7 +208,7 @@ _DTNormalizeReturnType = TypeVar(
208208
)
209209
_DTStrKindReturnType = TypeVar("_DTStrKindReturnType", bound=Series[str] | Index)
210210
_DTToPeriodReturnType = TypeVar(
211-
"_DTToPeriodReturnType", bound=PeriodSeries | PeriodIndex
211+
"_DTToPeriodReturnType", bound=Series[Period] | PeriodIndex
212212
)
213213

214214
class _DatetimeLikeNoTZMethods(
@@ -385,7 +385,7 @@ class CombinedDatetimelikeProperties(
385385
str,
386386
Series[Timestamp],
387387
Series[str],
388-
PeriodSeries,
388+
Series[Period],
389389
],
390390
_TimedeltaPropertiesNoRounding[Series[int], Series[float]],
391391
_PeriodProperties,
@@ -400,7 +400,7 @@ class TimestampProperties(
400400
str,
401401
Series[Timestamp],
402402
Series[str],
403-
PeriodSeries,
403+
Series[Period],
404404
]
405405
): ...
406406

@@ -438,6 +438,8 @@ class _dtDescriptor(CombinedDatetimelikeProperties, Generic[S1]):
438438
@overload
439439
def __get__(self, instance: Series[Never], owner: Any) -> Never: ...
440440
@overload
441+
def __get__(self, instance: Series[Period], owner: Any) -> PeriodProperties: ...
442+
@overload
441443
def __get__(
442444
self, instance: Series[Timestamp], owner: Any
443445
) -> TimestampProperties: ...

pandas-stubs/core/series.pyi

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ from pandas.core.generic import NDFrame
7070
from pandas.core.groupby.generic import SeriesGroupBy
7171
from pandas.core.groupby.groupby import BaseGroupBy
7272
from pandas.core.indexers import BaseIndexer
73-
from pandas.core.indexes.accessors import (
74-
PeriodProperties,
75-
_dtDescriptor,
76-
)
73+
from pandas.core.indexes.accessors import _dtDescriptor
7774
from pandas.core.indexes.category import CategoricalIndex
7875
from pandas.core.indexes.datetimes import DatetimeIndex
7976
from pandas.core.indexes.interval import IntervalIndex
@@ -363,7 +360,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
363360
dtype: PeriodDtype = ...,
364361
name: Hashable = ...,
365362
copy: bool = ...,
366-
) -> PeriodSeries: ...
363+
) -> Series[Period]: ...
367364
@overload
368365
def __new__(
369366
cls,
@@ -851,6 +848,8 @@ class Series(IndexOpsMixin[S1], NDFrame):
851848
@overload
852849
def diff(self: Series[Timedelta], periods: int = ...) -> Series[Timedelta]: ... # type: ignore[overload-overlap]
853850
@overload
851+
def diff(self: Series[Period], periods: int = ...) -> OffsetSeries: ... # type: ignore[overload-overlap]
852+
@overload
854853
def diff(self, periods: int = ...) -> Series[float]: ...
855854
def autocorr(self, lag: int = 1) -> float: ...
856855
@overload
@@ -1234,8 +1233,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
12341233
Series[_str],
12351234
Series,
12361235
]: ...
1237-
@property
1238-
def dt(self) -> _dtDescriptor[S1]: ...
1236+
dt = _dtDescriptor()
12391237
@property
12401238
def plot(self) -> PlotAccessor: ...
12411239
sparse = ...
@@ -1695,7 +1693,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
16951693
),
16961694
) -> Series[Timedelta]: ...
16971695
@overload
1698-
def __add__(self: Series[Timedelta], other: Period) -> PeriodSeries: ...
1696+
def __add__(self: Series[Timedelta], other: Period) -> Series[Period]: ...
16991697
@overload
17001698
def __add__(self: Series[bool], other: bool | Sequence[bool]) -> Series[bool]: ...
17011699
@overload
@@ -1822,7 +1820,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
18221820
level: Level | None = None,
18231821
fill_value: float | None = None,
18241822
axis: int = 0,
1825-
) -> PeriodSeries: ...
1823+
) -> Series[Period]: ...
18261824
@overload
18271825
def add(
18281826
self: Series[bool],
@@ -1957,7 +1955,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
19571955
),
19581956
) -> Series[Timedelta]: ...
19591957
@overload
1960-
def __radd__(self: Series[Timedelta], other: Period) -> PeriodSeries: ...
1958+
def __radd__(self: Series[Timedelta], other: Period) -> Series[Period]: ...
19611959
@overload
19621960
def __radd__(self: Series[bool], other: bool | Sequence[bool]) -> Series[bool]: ...
19631961
@overload
@@ -2084,7 +2082,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
20842082
level: Level | None = None,
20852083
fill_value: float | None = None,
20862084
axis: int = 0,
2087-
) -> PeriodSeries: ...
2085+
) -> Series[Period]: ...
20882086
@overload
20892087
def radd(
20902088
self: Series[bool],
@@ -3201,6 +3199,10 @@ class Series(IndexOpsMixin[S1], NDFrame):
32013199
),
32023200
) -> Series[Timedelta]: ...
32033201
@overload
3202+
def __sub__(
3203+
self: Series[Period], other: Series[Period] | Period
3204+
) -> Series[BaseOffset]: ...
3205+
@overload
32043206
def sub(
32053207
self: Series[Never],
32063208
other: complex | NumListLike | Index[T_COMPLEX] | Series[T_COMPLEX],
@@ -3372,6 +3374,14 @@ class Series(IndexOpsMixin[S1], NDFrame):
33723374
axis: int = 0,
33733375
) -> Series[Timedelta]: ...
33743376
@overload
3377+
def sub(
3378+
self: Series[Period],
3379+
other: Period | Sequence[Period] | PeriodIndex | Series[Period],
3380+
level: Level | None = None,
3381+
fill_value: float | None = None,
3382+
axis: int = 0,
3383+
) -> Series[BaseOffset]: ...
3384+
@overload
33753385
def __rsub__(
33763386
self: Series[Never],
33773387
other: (
@@ -3502,6 +3512,10 @@ class Series(IndexOpsMixin[S1], NDFrame):
35023512
),
35033513
) -> Series[Timedelta]: ...
35043514
@overload
3515+
def __rsub__(
3516+
self: Series[Period], other: Series[Period] | Period
3517+
) -> Series[BaseOffset]: ...
3518+
@overload
35053519
def rsub(
35063520
self: Series[Never],
35073521
other: (
@@ -3682,6 +3696,14 @@ class Series(IndexOpsMixin[S1], NDFrame):
36823696
axis: int = 0,
36833697
) -> Series[Timedelta]: ...
36843698
@overload
3699+
def rsub(
3700+
self: Series[Period],
3701+
other: Period | Sequence[Period] | PeriodIndex | Series[Period],
3702+
level: Level | None = None,
3703+
fill_value: float | None = None,
3704+
axis: int = 0,
3705+
) -> Series[BaseOffset]: ...
3706+
@overload
36853707
def __truediv__( # type: ignore[overload-overlap]
36863708
self: Series[Never], other: complex | NumListLike | Index | Series
36873709
) -> Series: ...
@@ -4623,6 +4645,22 @@ class Series(IndexOpsMixin[S1], NDFrame):
46234645
**kwargs,
46244646
) -> np_1darray[GenericT]: ...
46254647
@overload
4648+
def to_numpy(
4649+
self: Series[Period],
4650+
dtype: None = None,
4651+
copy: bool = False,
4652+
na_value: Scalar = ...,
4653+
**kwargs,
4654+
) -> np_1darray[np.object_]: ...
4655+
@overload
4656+
def to_numpy(
4657+
self: Series[Period],
4658+
dtype: type[np.int64],
4659+
copy: bool = False,
4660+
na_value: Scalar = ...,
4661+
**kwargs,
4662+
) -> np_1darray[np.int64]: ...
4663+
@overload
46264664
def to_numpy( # pyright: ignore[reportIncompatibleMethodOverride]
46274665
self,
46284666
dtype: DTypeLike | None = None,
@@ -4716,15 +4754,9 @@ class _SeriesSubclassBase(Series[S1], Generic[S1, GenericT_co]):
47164754
**kwargs,
47174755
) -> np_1darray: ...
47184756

4719-
class PeriodSeries(_SeriesSubclassBase[Period, np.object_]):
4720-
@property
4721-
def dt(self) -> PeriodProperties: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
4722-
def __sub__(self, other: PeriodSeries) -> OffsetSeries: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
4723-
def diff(self, periods: int = ...) -> OffsetSeries: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
4724-
47254757
class OffsetSeries(_SeriesSubclassBase[BaseOffset, np.object_]):
47264758
@overload # type: ignore[override]
4727-
def __radd__(self, other: Period) -> PeriodSeries: ...
4759+
def __radd__(self, other: Period) -> Series[Period]: ...
47284760
@overload
47294761
def __radd__( # pyright: ignore[reportIncompatibleMethodOverride]
47304762
self, other: BaseOffset

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ scipy = { version = ">=1.9.1", python = "<3.14" }
6565
scipy-stubs = ">=1.15.3.0"
6666
SQLAlchemy = ">=2.0.39"
6767
types-python-dateutil = ">=2.8.19"
68-
beautifulsoup4 = ">=4.12.2"
68+
beautifulsoup4 = "<=4.13.5"
6969
html5lib = ">=1.1"
7070
python-calamine = ">=0.2.0"
7171

tests/series/arithmetic/period/__init__.py

Whitespace-only changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""Test module for subtraction operation on Series[Period]."""
2+
3+
import pandas as pd
4+
from typing_extensions import assert_type
5+
6+
from pandas._libs.tslibs.offsets import BaseOffset
7+
8+
from tests import check
9+
10+
11+
def test_sub() -> None:
12+
"""Test sub method for pd.Series[pd.Period]."""
13+
p = pd.Period("2012-1-1", freq="D")
14+
sr = pd.Series([pd.Period("2012-1-1", freq="D")])
15+
16+
check(assert_type(sr - sr, "pd.Series[BaseOffset]"), pd.Series, BaseOffset)
17+
check(assert_type(p - sr, "pd.Series[BaseOffset]"), pd.Series, BaseOffset)
18+
check(assert_type(sr - p, "pd.Series[BaseOffset]"), pd.Series, BaseOffset)
19+
check(assert_type(sr.sub(p), "pd.Series[BaseOffset]"), pd.Series, BaseOffset)
20+
check(assert_type(sr.rsub(p), "pd.Series[BaseOffset]"), pd.Series, BaseOffset)

0 commit comments

Comments
 (0)