Skip to content

Commit 10fe362

Browse files
GH1379 Drop OffsetSeries replacing it with Series[BaseOffset] (#1390)
* GH1379 Drop OffsetSeries replacing it with Series[BaseOffset] * GH1379 Release beautifulsoup version lock * GH1379 PR feedback * GH1379 PR feedback
1 parent 50a9aa5 commit 10fe362

File tree

5 files changed

+39
-27
lines changed

5 files changed

+39
-27
lines changed

pandas-stubs/_libs/tslibs/period.pyi

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ from pandas import (
1212
Timedelta,
1313
TimedeltaIndex,
1414
)
15-
from pandas.core.series import (
16-
OffsetSeries,
17-
)
1815
from typing_extensions import TypeAlias
1916

2017
from pandas._libs.tslibs import NaTType
@@ -97,7 +94,7 @@ class Period(PeriodMixin):
9794
def __add__(self, other: Index) -> PeriodIndex: ...
9895
@overload
9996
def __add__(
100-
self, other: OffsetSeries | Series[Timedelta]
97+
self, other: Series[BaseOffset] | Series[Timedelta]
10198
) -> Series[Period]: ... # pyrefly: ignore[bad-specialization]
10299
# ignore[misc] here because we know all other comparisons
103100
# are False, so we use Literal[False]

pandas-stubs/core/series.pyi

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,15 @@ class Series(IndexOpsMixin[S1], NDFrame):
362362
copy: bool = ...,
363363
) -> Series[Period]: ...
364364
@overload
365+
def __new__(
366+
cls,
367+
data: Sequence[BaseOffset],
368+
index: AxesData | None = ...,
369+
dtype: PeriodDtype = ...,
370+
name: Hashable = ...,
371+
copy: bool = ...,
372+
) -> Series[BaseOffset]: ...
373+
@overload
365374
def __new__(
366375
cls,
367376
data: (
@@ -848,7 +857,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
848857
@overload
849858
def diff(self: Series[Timedelta], periods: int = ...) -> Series[Timedelta]: ... # type: ignore[overload-overlap]
850859
@overload
851-
def diff(self: Series[Period], periods: int = ...) -> OffsetSeries: ... # type: ignore[overload-overlap]
860+
def diff(self: Series[Period], periods: int = ...) -> Series[BaseOffset]: ... # type: ignore[overload-overlap]
852861
@overload
853862
def diff(self, periods: int = ...) -> Series[float]: ...
854863
def autocorr(self, lag: int = 1) -> float: ...
@@ -1061,7 +1070,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
10611070
convertDType: _bool = ...,
10621071
args: tuple = ...,
10631072
**kwargs: Any,
1064-
) -> OffsetSeries: ...
1073+
) -> Series[BaseOffset]: ...
10651074
@overload
10661075
def apply(
10671076
self,
@@ -2014,6 +2023,10 @@ class Series(IndexOpsMixin[S1], NDFrame):
20142023
other: _str | Sequence[_str] | np_ndarray_str | Index[_str] | Series[_str],
20152024
) -> Series[_str]: ...
20162025
@overload
2026+
def __radd__(self: Series[BaseOffset], other: Period) -> Series[Period]: ...
2027+
@overload
2028+
def __radd__(self: Series[BaseOffset], other: BaseOffset) -> Series[BaseOffset]: ...
2029+
@overload
20172030
def radd(
20182031
self: Series[Never],
20192032
other: complex | _ListLike | Index | Series,
@@ -4669,6 +4682,22 @@ class Series(IndexOpsMixin[S1], NDFrame):
46694682
**kwargs,
46704683
) -> np_1darray[np.int64]: ...
46714684
@overload
4685+
def to_numpy(
4686+
self: Series[BaseOffset],
4687+
dtype: None = None,
4688+
copy: bool = False,
4689+
na_value: Scalar = ...,
4690+
**kwargs,
4691+
) -> np_1darray[np.object_]: ...
4692+
@overload
4693+
def to_numpy(
4694+
self: Series[BaseOffset],
4695+
dtype: type[np.bytes_],
4696+
copy: bool = False,
4697+
na_value: Scalar = ...,
4698+
**kwargs,
4699+
) -> np_1darray[np.bytes_]: ...
4700+
@overload
46724701
def to_numpy( # pyright: ignore[reportIncompatibleMethodOverride]
46734702
self,
46744703
dtype: DTypeLike | None = None,
@@ -4762,14 +4791,6 @@ class _SeriesSubclassBase(Series[S1], Generic[S1, GenericT_co]):
47624791
**kwargs,
47634792
) -> np_1darray: ...
47644793

4765-
class OffsetSeries(_SeriesSubclassBase[BaseOffset, np.object_]):
4766-
@overload # type: ignore[override]
4767-
def __radd__(self, other: Period) -> Series[Period]: ...
4768-
@overload
4769-
def __radd__( # pyright: ignore[reportIncompatibleMethodOverride]
4770-
self, other: BaseOffset
4771-
) -> OffsetSeries: ...
4772-
47734794
class IntervalSeries(
47744795
_SeriesSubclassBase[Interval[_OrderableT], np.object_], Generic[_OrderableT]
47754796
):

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.13.5"
68+
beautifulsoup4 = ">=4.14.2"
6969
html5lib = ">=1.1"
7070
python-calamine = ">=0.2.0"
7171

tests/series/test_series.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@
7272
)
7373

7474
if TYPE_CHECKING:
75-
from pandas.core.series import OffsetSeries
76-
7775
from tests import (
7876
BooleanDtypeArg,
7977
BytesDtypeArg,
@@ -89,9 +87,6 @@
8987
VoidDtypeArg,
9088
)
9189

92-
else:
93-
OffsetSeries: TypeAlias = pd.Series
94-
9590
if not PD_LTE_23:
9691
from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore # isort: skip
9792
else:
@@ -3487,7 +3482,7 @@ def test_diff() -> None:
34873482
pd.Series(
34883483
pd.period_range(start="2017-01-01", end="2017-02-01", freq="D")
34893484
).diff(),
3490-
"OffsetSeries",
3485+
"pd.Series[BaseOffset]",
34913486
),
34923487
pd.Series,
34933488
BaseOffset,
@@ -3499,7 +3494,7 @@ def test_diff() -> None:
34993494
pd.Series(
35003495
pd.period_range(start="2017-01-01", end="2017-02-01", freq="D")
35013496
).diff(),
3502-
"OffsetSeries",
3497+
"pd.Series[BaseOffset]",
35033498
),
35043499
pd.Series,
35053500
BaseOffset,
@@ -3672,7 +3667,9 @@ def test_apply_dateoffset() -> None:
36723667
months = [1, 2, 3]
36733668
s = pd.Series(months)
36743669
check(
3675-
assert_type(s.apply(lambda x: pd.DateOffset(months=x)), "OffsetSeries"),
3670+
assert_type(
3671+
s.apply(lambda x: pd.DateOffset(months=x)), "pd.Series[BaseOffset]"
3672+
),
36763673
pd.Series,
36773674
pd.DateOffset,
36783675
)

tests/test_timefuncs.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
if TYPE_CHECKING:
5353
from pandas.core.series import (
5454
IntervalSeries,
55-
OffsetSeries,
5655
)
5756

5857
if not PD_LTE_23:
@@ -946,9 +945,7 @@ def test_series_types_to_numpy() -> None:
946945
td_s = pd.to_timedelta(pd.Series([10, 20]), "minutes")
947946
ts_s = pd.to_datetime(pd.Series(["2020-01-01", "2020-01-02"]))
948947
p_s = pd.Series(pd.period_range("2012-1-1", periods=10, freq="D"))
949-
o_s = cast(
950-
"OffsetSeries", pd.Series([pd.DateOffset(days=1), pd.DateOffset(days=2)])
951-
)
948+
o_s = pd.Series([pd.DateOffset(days=1), pd.DateOffset(days=2)])
952949
i_s = cast("IntervalSeries", pd.interval_range(1, 2).to_series())
953950

954951
# default dtype

0 commit comments

Comments
 (0)