Skip to content

Commit 0f31997

Browse files
committed
Merge branch 'main' into feature/cmp0xff/drop-interval-series
2 parents 46eea6f + e571f9e commit 0f31997

File tree

10 files changed

+109
-60
lines changed

10 files changed

+109
-60
lines changed

pandas-stubs/_libs/tslibs/period.pyi

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ from pandas import (
1212
Timedelta,
1313
TimedeltaIndex,
1414
)
15-
from pandas.core.series import (
16-
OffsetSeries,
17-
PeriodSeries,
18-
)
15+
from pandas.core.series import OffsetSeries
1916
from typing_extensions import TypeAlias
2017

2118
from pandas._libs.tslibs import NaTType
@@ -85,7 +82,9 @@ class Period(PeriodMixin):
8582
@overload
8683
def __sub__(self, other: PeriodIndex) -> Index: ...
8784
@overload
88-
def __sub__(self, other: Series[Timedelta]) -> PeriodSeries: ...
85+
def __sub__(
86+
self, other: Series[Timedelta]
87+
) -> Series[Period]: ... # pyrefly: ignore[bad-specialization]
8988
@overload
9089
def __sub__(self, other: TimedeltaIndex) -> PeriodIndex: ...
9190
@overload
@@ -95,15 +94,17 @@ class Period(PeriodMixin):
9594
@overload
9695
def __add__(self, other: Index) -> PeriodIndex: ...
9796
@overload
98-
def __add__(self, other: OffsetSeries | Series[Timedelta]) -> PeriodSeries: ...
97+
def __add__(
98+
self, other: OffsetSeries | Series[Timedelta]
99+
) -> Series[Period]: ... # pyrefly: ignore[bad-specialization]
99100
# ignore[misc] here because we know all other comparisons
100101
# are False, so we use Literal[False]
101102
@overload
102103
def __eq__(self, other: Period) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
103104
@overload
104105
def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
105106
@overload
106-
def __eq__(self, other: PeriodSeries) -> Series[bool]: ... # type: ignore[overload-overlap]
107+
def __eq__(self, other: Series[Period]) -> Series[bool]: ... # type: ignore[overload-overlap]
107108
@overload
108109
def __eq__(self, other: np_ndarray[ShapeT, np.object_]) -> np_ndarray[ShapeT, np.bool]: ... # type: ignore[overload-overlap]
109110
@overload
@@ -113,7 +114,9 @@ class Period(PeriodMixin):
113114
@overload
114115
def __ge__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
115116
@overload
116-
def __ge__(self, other: PeriodSeries) -> Series[bool]: ...
117+
def __ge__(
118+
self, other: Series[Period] # pyrefly: ignore[bad-specialization]
119+
) -> Series[bool]: ...
117120
@overload
118121
def __ge__(
119122
self, other: np_ndarray[ShapeT, np.object_]
@@ -123,7 +126,9 @@ class Period(PeriodMixin):
123126
@overload
124127
def __gt__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
125128
@overload
126-
def __gt__(self, other: PeriodSeries) -> Series[bool]: ...
129+
def __gt__(
130+
self, other: Series[Period] # pyrefly: ignore[bad-specialization]
131+
) -> Series[bool]: ...
127132
@overload
128133
def __gt__(
129134
self, other: np_ndarray[ShapeT, np.object_]
@@ -133,7 +138,9 @@ class Period(PeriodMixin):
133138
@overload
134139
def __le__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
135140
@overload
136-
def __le__(self, other: PeriodSeries) -> Series[bool]: ...
141+
def __le__(
142+
self, other: Series[Period] # pyrefly: ignore[bad-specialization]
143+
) -> Series[bool]: ...
137144
@overload
138145
def __le__(
139146
self, other: np_ndarray[ShapeT, np.object_]
@@ -143,7 +150,9 @@ class Period(PeriodMixin):
143150
@overload
144151
def __lt__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
145152
@overload
146-
def __lt__(self, other: PeriodSeries) -> Series[bool]: ...
153+
def __lt__(
154+
self, other: Series[Period] # pyrefly: ignore[bad-specialization]
155+
) -> Series[bool]: ...
147156
@overload
148157
def __lt__(
149158
self, other: np_ndarray[ShapeT, np.object_]
@@ -155,7 +164,7 @@ class Period(PeriodMixin):
155164
@overload
156165
def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
157166
@overload
158-
def __ne__(self, other: PeriodSeries) -> Series[bool]: ... # type: ignore[overload-overlap]
167+
def __ne__(self, other: Series[Period]) -> Series[bool]: ... # type: ignore[overload-overlap]
159168
@overload
160169
def __ne__(self, other: np_ndarray[ShapeT, np.object_]) -> np_ndarray[ShapeT, np.bool]: ... # type: ignore[overload-overlap]
161170
@overload

pandas-stubs/core/indexes/accessors.pyi

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ from pandas.core.indexes.base import Index
3030
from pandas.core.indexes.datetimes import DatetimeIndex
3131
from pandas.core.indexes.period import PeriodIndex
3232
from pandas.core.indexes.timedeltas import TimedeltaIndex
33-
from pandas.core.series import (
34-
PeriodSeries,
35-
Series,
36-
)
33+
from pandas.core.series import Series
3734
from typing_extensions import Never
3835

3936
from pandas._libs.interval import Interval
@@ -216,7 +213,7 @@ _DTNormalizeReturnType = TypeVar(
216213
)
217214
_DTStrKindReturnType = TypeVar("_DTStrKindReturnType", bound=Series[str] | Index)
218215
_DTToPeriodReturnType = TypeVar(
219-
"_DTToPeriodReturnType", bound=PeriodSeries | PeriodIndex
216+
"_DTToPeriodReturnType", bound=Series[Period] | PeriodIndex
220217
)
221218

222219
class _DatetimeLikeNoTZMethods(
@@ -393,7 +390,7 @@ class CombinedDatetimelikeProperties(
393390
str,
394391
Series[Timestamp],
395392
Series[str],
396-
PeriodSeries,
393+
Series[Period],
397394
],
398395
_TimedeltaPropertiesNoRounding[Series[int], Series[float]],
399396
_PeriodProperties,
@@ -410,7 +407,7 @@ class TimestampProperties(
410407
str,
411408
Series[Timestamp],
412409
Series[str],
413-
PeriodSeries,
410+
Series[Period],
414411
]
415412
): ...
416413

@@ -460,8 +457,8 @@ class DtDescriptor:
460457
@overload
461458
def __get__(
462459
self,
463-
instance: Series[Period] | PeriodSeries,
464-
owner: type[Series | PeriodSeries],
460+
instance: Series[Period],
461+
owner: type[Series],
465462
) -> PeriodProperties: ...
466463

467464
@type_check_only

pandas-stubs/core/indexes/period.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ from pandas import Index
1111
from pandas.core.indexes.accessors import PeriodIndexFieldOps
1212
from pandas.core.indexes.datetimelike import DatetimeIndexOpsMixin
1313
from pandas.core.indexes.timedeltas import TimedeltaIndex
14-
from pandas.core.series import PeriodSeries
1514
from typing_extensions import Self
1615

1716
from pandas._libs.tslibs import (
@@ -75,7 +74,6 @@ class PeriodIndex(DatetimeIndexOpsMixin[pd.Period, np.object_], PeriodIndexField
7574
@property
7675
def freqstr(self) -> str: ...
7776
def shift(self, periods: int = 1, freq: Frequency | None = None) -> Self: ...
78-
def to_series(self, index=..., name: Hashable = ...) -> PeriodSeries: ...
7977

8078
def period_range(
8179
start: (

pandas-stubs/core/series.pyi

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
300300
copy: bool = ...,
301301
) -> Series[float]: ...
302302
@overload
303-
def __new__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
303+
def __new__(
304304
cls,
305305
data: Sequence[Never],
306306
index: AxesData | None = ...,
@@ -360,7 +360,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
360360
dtype: PeriodDtype = ...,
361361
name: Hashable = ...,
362362
copy: bool = ...,
363-
) -> PeriodSeries: ...
363+
) -> Series[Period]: ...
364364
@overload
365365
def __new__(
366366
cls,
@@ -845,6 +845,8 @@ class Series(IndexOpsMixin[S1], NDFrame):
845845
@overload
846846
def diff(self: Series[Timedelta], periods: int = ...) -> Series[Timedelta]: ... # type: ignore[overload-overlap]
847847
@overload
848+
def diff(self: Series[Period], periods: int = ...) -> OffsetSeries: ... # type: ignore[overload-overlap]
849+
@overload
848850
def diff(self, periods: int = ...) -> Series[float]: ...
849851
def autocorr(self, lag: int = 1) -> float: ...
850852
@overload
@@ -1688,7 +1690,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
16881690
),
16891691
) -> Series[Timedelta]: ...
16901692
@overload
1691-
def __add__(self: Series[Timedelta], other: Period) -> PeriodSeries: ...
1693+
def __add__(self: Series[Timedelta], other: Period) -> Series[Period]: ...
16921694
@overload
16931695
def __add__(self: Series[bool], other: bool | Sequence[bool]) -> Series[bool]: ...
16941696
@overload
@@ -1815,7 +1817,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
18151817
level: Level | None = None,
18161818
fill_value: float | None = None,
18171819
axis: int = 0,
1818-
) -> PeriodSeries: ...
1820+
) -> Series[Period]: ...
18191821
@overload
18201822
def add(
18211823
self: Series[bool],
@@ -1950,7 +1952,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
19501952
),
19511953
) -> Series[Timedelta]: ...
19521954
@overload
1953-
def __radd__(self: Series[Timedelta], other: Period) -> PeriodSeries: ...
1955+
def __radd__(self: Series[Timedelta], other: Period) -> Series[Period]: ...
19541956
@overload
19551957
def __radd__(self: Series[bool], other: bool | Sequence[bool]) -> Series[bool]: ...
19561958
@overload
@@ -2077,7 +2079,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
20772079
level: Level | None = None,
20782080
fill_value: float | None = None,
20792081
axis: int = 0,
2080-
) -> PeriodSeries: ...
2082+
) -> Series[Period]: ...
20812083
@overload
20822084
def radd(
20832085
self: Series[bool],
@@ -3194,6 +3196,10 @@ class Series(IndexOpsMixin[S1], NDFrame):
31943196
),
31953197
) -> Series[Timedelta]: ...
31963198
@overload
3199+
def __sub__(
3200+
self: Series[Period], other: Series[Period] | Period
3201+
) -> Series[BaseOffset]: ...
3202+
@overload
31973203
def sub(
31983204
self: Series[Never],
31993205
other: complex | NumListLike | Index[T_COMPLEX] | Series[T_COMPLEX],
@@ -3365,6 +3371,14 @@ class Series(IndexOpsMixin[S1], NDFrame):
33653371
axis: int = 0,
33663372
) -> Series[Timedelta]: ...
33673373
@overload
3374+
def sub(
3375+
self: Series[Period],
3376+
other: Period | Sequence[Period] | PeriodIndex | Series[Period],
3377+
level: Level | None = None,
3378+
fill_value: float | None = None,
3379+
axis: int = 0,
3380+
) -> Series[BaseOffset]: ...
3381+
@overload
33683382
def __rsub__(
33693383
self: Series[Never],
33703384
other: (
@@ -3495,6 +3509,10 @@ class Series(IndexOpsMixin[S1], NDFrame):
34953509
),
34963510
) -> Series[Timedelta]: ...
34973511
@overload
3512+
def __rsub__(
3513+
self: Series[Period], other: Series[Period] | Period
3514+
) -> Series[BaseOffset]: ...
3515+
@overload
34983516
def rsub(
34993517
self: Series[Never],
35003518
other: (
@@ -3675,6 +3693,14 @@ class Series(IndexOpsMixin[S1], NDFrame):
36753693
axis: int = 0,
36763694
) -> Series[Timedelta]: ...
36773695
@overload
3696+
def rsub(
3697+
self: Series[Period],
3698+
other: Period | Sequence[Period] | PeriodIndex | Series[Period],
3699+
level: Level | None = None,
3700+
fill_value: float | None = None,
3701+
axis: int = 0,
3702+
) -> Series[BaseOffset]: ...
3703+
@overload
36783704
def __truediv__( # type: ignore[overload-overlap]
36793705
self: Series[Never], other: complex | NumListLike | Index | Series
36803706
) -> Series: ...
@@ -4613,6 +4639,22 @@ class Series(IndexOpsMixin[S1], NDFrame):
46134639
**kwargs,
46144640
) -> np_1darray[GenericT]: ...
46154641
@overload
4642+
def to_numpy(
4643+
self: Series[Period],
4644+
dtype: None = None,
4645+
copy: bool = False,
4646+
na_value: Scalar = ...,
4647+
**kwargs,
4648+
) -> np_1darray[np.object_]: ...
4649+
@overload
4650+
def to_numpy(
4651+
self: Series[Period],
4652+
dtype: type[np.int64],
4653+
copy: bool = False,
4654+
na_value: Scalar = ...,
4655+
**kwargs,
4656+
) -> np_1darray[np.int64]: ...
4657+
@overload
46164658
def to_numpy(
46174659
self: Series[Interval],
46184660
dtype: type[np.object_] | None = None,
@@ -4722,14 +4764,9 @@ class _SeriesSubclassBase(Series[S1], Generic[S1, GenericT_co]):
47224764
**kwargs,
47234765
) -> np_1darray: ...
47244766

4725-
class PeriodSeries(_SeriesSubclassBase[Period, np.object_]):
4726-
dt: ClassVar = DtDescriptor() # noqa
4727-
def __sub__(self, other: PeriodSeries) -> OffsetSeries: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
4728-
def diff(self, periods: int = ...) -> OffsetSeries: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
4729-
47304767
class OffsetSeries(_SeriesSubclassBase[BaseOffset, np.object_]):
47314768
@overload # type: ignore[override]
4732-
def __radd__(self, other: Period) -> PeriodSeries: ...
4769+
def __radd__(self, other: Period) -> Series[Period]: ...
47334770
@overload
47344771
def __radd__( # pyright: ignore[reportIncompatibleMethodOverride]
47354772
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,!=4.14.0" # pandas-dev/pandas#62492
68+
beautifulsoup4 = ">=4.14.2"
6969
html5lib = ">=1.1"
7070
python-calamine = ">=0.2.0"
7171

tests/indexes/test_indexes.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
)
3333

3434
if TYPE_CHECKING:
35-
from pandas.core.series import PeriodSeries # noqa: F401
36-
3735
from tests import Dtype # noqa: F401
3836

3937

@@ -1576,7 +1574,8 @@ def test_to_series() -> None:
15761574
)
15771575
check(
15781576
assert_type(
1579-
pd.period_range(start="2022-06-01", periods=10).to_series(), "PeriodSeries"
1577+
pd.period_range(start="2022-06-01", periods=10).to_series(),
1578+
"pd.Series[pd.Period]",
15801579
),
15811580
pd.Series,
15821581
pd.Period,

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)