-
-
Notifications
You must be signed in to change notification settings - Fork 150
GH1379 Remove PeriodSeries #1386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,10 +70,7 @@ from pandas.core.generic import NDFrame | |
from pandas.core.groupby.generic import SeriesGroupBy | ||
from pandas.core.groupby.groupby import BaseGroupBy | ||
from pandas.core.indexers import BaseIndexer | ||
from pandas.core.indexes.accessors import ( | ||
PeriodProperties, | ||
_dtDescriptor, | ||
) | ||
from pandas.core.indexes.accessors import _dtDescriptor | ||
from pandas.core.indexes.category import CategoricalIndex | ||
from pandas.core.indexes.datetimes import DatetimeIndex | ||
from pandas.core.indexes.interval import IntervalIndex | ||
|
@@ -363,7 +360,7 @@ class Series(IndexOpsMixin[S1], NDFrame): | |
dtype: PeriodDtype = ..., | ||
name: Hashable = ..., | ||
copy: bool = ..., | ||
) -> PeriodSeries: ... | ||
) -> Series[Period]: ... | ||
@overload | ||
def __new__( | ||
cls, | ||
|
@@ -851,6 +848,8 @@ class Series(IndexOpsMixin[S1], NDFrame): | |
@overload | ||
def diff(self: Series[Timedelta], periods: int = ...) -> Series[Timedelta]: ... # type: ignore[overload-overlap] | ||
@overload | ||
def diff(self: Series[Period], periods: int = ...) -> OffsetSeries: ... # type: ignore[overload-overlap] | ||
@overload | ||
def diff(self, periods: int = ...) -> Series[float]: ... | ||
def autocorr(self, lag: int = 1) -> float: ... | ||
@overload | ||
|
@@ -1234,8 +1233,7 @@ class Series(IndexOpsMixin[S1], NDFrame): | |
Series[_str], | ||
Series, | ||
]: ... | ||
@property | ||
def dt(self) -> _dtDescriptor[S1]: ... | ||
dt = _dtDescriptor[S1]() # type: ignore[misc] | ||
|
||
@property | ||
def plot(self) -> PlotAccessor: ... | ||
sparse = ... | ||
|
@@ -1695,7 +1693,7 @@ class Series(IndexOpsMixin[S1], NDFrame): | |
), | ||
) -> Series[Timedelta]: ... | ||
@overload | ||
def __add__(self: Series[Timedelta], other: Period) -> PeriodSeries: ... | ||
def __add__(self: Series[Timedelta], other: Period) -> Series[Period]: ... | ||
@overload | ||
def __add__(self: Series[bool], other: bool | Sequence[bool]) -> Series[bool]: ... | ||
@overload | ||
|
@@ -1822,7 +1820,7 @@ class Series(IndexOpsMixin[S1], NDFrame): | |
level: Level | None = None, | ||
fill_value: float | None = None, | ||
axis: int = 0, | ||
) -> PeriodSeries: ... | ||
) -> Series[Period]: ... | ||
@overload | ||
def add( | ||
self: Series[bool], | ||
|
@@ -1957,7 +1955,7 @@ class Series(IndexOpsMixin[S1], NDFrame): | |
), | ||
) -> Series[Timedelta]: ... | ||
@overload | ||
def __radd__(self: Series[Timedelta], other: Period) -> PeriodSeries: ... | ||
def __radd__(self: Series[Timedelta], other: Period) -> Series[Period]: ... | ||
@overload | ||
def __radd__(self: Series[bool], other: bool | Sequence[bool]) -> Series[bool]: ... | ||
@overload | ||
|
@@ -2084,7 +2082,7 @@ class Series(IndexOpsMixin[S1], NDFrame): | |
level: Level | None = None, | ||
fill_value: float | None = None, | ||
axis: int = 0, | ||
) -> PeriodSeries: ... | ||
) -> Series[Period]: ... | ||
@overload | ||
def radd( | ||
self: Series[bool], | ||
|
@@ -3201,6 +3199,10 @@ class Series(IndexOpsMixin[S1], NDFrame): | |
), | ||
) -> Series[Timedelta]: ... | ||
@overload | ||
def __sub__( | ||
self: Series[Period], other: Series[Period] | Period | ||
) -> Series[BaseOffset]: ... | ||
@overload | ||
def sub( | ||
self: Series[Never], | ||
other: complex | NumListLike | Index[T_COMPLEX] | Series[T_COMPLEX], | ||
|
@@ -3372,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: ( | ||
|
@@ -3502,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: ( | ||
|
@@ -3682,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: ... | ||
|
@@ -4623,6 +4645,22 @@ class Series(IndexOpsMixin[S1], NDFrame): | |
**kwargs, | ||
) -> np_1darray[GenericT]: ... | ||
@overload | ||
def to_numpy( | ||
self: Series[Period], | ||
dtype: None = None, | ||
copy: bool = False, | ||
na_value: Scalar = ..., | ||
**kwargs, | ||
) -> np_1darray[np.object_]: ... | ||
@overload | ||
def to_numpy( | ||
self: Series[Period], | ||
dtype: type[np.int64], | ||
copy: bool = False, | ||
na_value: Scalar = ..., | ||
**kwargs, | ||
) -> np_1darray[np.int64]: ... | ||
@overload | ||
def to_numpy( # pyright: ignore[reportIncompatibleMethodOverride] | ||
self, | ||
dtype: DTypeLike | None = None, | ||
|
@@ -4716,15 +4754,9 @@ class _SeriesSubclassBase(Series[S1], Generic[S1, GenericT_co]): | |
**kwargs, | ||
) -> np_1darray: ... | ||
|
||
class PeriodSeries(_SeriesSubclassBase[Period, np.object_]): | ||
@property | ||
def dt(self) -> PeriodProperties: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] | ||
def __sub__(self, other: PeriodSeries) -> OffsetSeries: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] | ||
def diff(self, periods: int = ...) -> OffsetSeries: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] | ||
|
||
class OffsetSeries(_SeriesSubclassBase[BaseOffset, np.object_]): | ||
@overload # type: ignore[override] | ||
def __radd__(self, other: Period) -> PeriodSeries: ... | ||
def __radd__(self, other: Period) -> Series[Period]: ... | ||
@overload | ||
def __radd__( # pyright: ignore[reportIncompatibleMethodOverride] | ||
self, other: BaseOffset | ||
|
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could try the following idea to simplify, if you want.
And
I've first seen the idea in #1362 and it worked again in #1374