-
-
Notifications
You must be signed in to change notification settings - Fork 143
Fix Series.__new__ #722
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
Fix Series.__new__ #722
Changes from 3 commits
0aca7c2
0ab4641
434d02b
32faa92
367de21
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 |
---|---|---|
|
@@ -27,6 +27,7 @@ from matplotlib.axes import ( | |
import numpy as np | ||
from pandas import ( | ||
Period, | ||
PeriodDtype, | ||
Timedelta, | ||
Timestamp, | ||
) | ||
|
@@ -104,6 +105,7 @@ from pandas._typing import ( | |
CategoryDtypeArg, | ||
ComplexDtypeArg, | ||
CompressionOptions, | ||
Dtype, | ||
DtypeBackend, | ||
DtypeObj, | ||
FilePath, | ||
|
@@ -208,92 +210,55 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]): | |
_ListLike: TypeAlias = ArrayLike | dict[_str, np.ndarray] | list | tuple | Index | ||
__hash__: ClassVar[None] | ||
|
||
# TODO: can __new__ be converted to __init__? Pandas implements __init__ | ||
@overload | ||
def __new__( | ||
cls, | ||
data: DatetimeIndex | Sequence[Timestamp | np.datetime64 | datetime], | ||
index: Axes | None = ..., | ||
dtype=..., | ||
dtype: TimestampDtypeArg = ..., | ||
name: Hashable | None = ..., | ||
copy: bool = ..., | ||
fastpath: bool = ..., | ||
) -> TimestampSeries: ... | ||
@overload | ||
def __new__( | ||
cls, | ||
data: _ListLike, | ||
dtype: Literal["datetime64[ns]"], | ||
index: Axes | None = ..., | ||
*, | ||
dtype: Literal["datetime64[ns]"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think all the other overloads would also need that: one overload with a specific There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My concern there would be that it would be too wide. In other words, there would be contents of lists that wouldn't work with certain dtypes. I think the one is in there for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think this is the only change left to make. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed |
||
name: Hashable | None = ..., | ||
copy: bool = ..., | ||
fastpath: bool = ..., | ||
) -> TimestampSeries: ... | ||
@overload | ||
def __new__( | ||
cls, | ||
data: PeriodIndex, | ||
index: Axes | None = ..., | ||
dtype=..., | ||
dtype: PeriodDtype = ..., | ||
name: Hashable | None = ..., | ||
copy: bool = ..., | ||
fastpath: bool = ..., | ||
) -> PeriodSeries: ... | ||
@overload | ||
def __new__( | ||
cls, | ||
data: TimedeltaIndex | Sequence[Timedelta | np.timedelta64 | timedelta], | ||
index: Axes | None = ..., | ||
dtype=..., | ||
dtype: TimedeltaDtypeArg = ..., | ||
name: Hashable | None = ..., | ||
copy: bool = ..., | ||
fastpath: bool = ..., | ||
) -> TimedeltaSeries: ... | ||
@overload | ||
def __new__( | ||
cls, | ||
data: IntervalIndex[Interval[int]] | Interval[int] | Sequence[Interval[int]], | ||
index: Axes | None = ..., | ||
dtype=..., | ||
name: Hashable | None = ..., | ||
copy: bool = ..., | ||
fastpath: bool = ..., | ||
) -> IntervalSeries[int]: ... | ||
@overload | ||
def __new__( | ||
cls, | ||
data: IntervalIndex[Interval[float]] | ||
| Interval[float] | ||
| Sequence[Interval[float]], | ||
index: Axes | None = ..., | ||
dtype=..., | ||
name: Hashable | None = ..., | ||
copy: bool = ..., | ||
fastpath: bool = ..., | ||
) -> IntervalSeries[float]: ... | ||
@overload | ||
def __new__( | ||
cls, | ||
data: IntervalIndex[Interval[Timestamp]] | ||
| Interval[Timestamp] | ||
| Sequence[Interval[Timestamp]], | ||
index: Axes | None = ..., | ||
dtype=..., | ||
name: Hashable | None = ..., | ||
copy: bool = ..., | ||
fastpath: bool = ..., | ||
) -> IntervalSeries[Timestamp]: ... | ||
@overload | ||
def __new__( | ||
cls, | ||
data: IntervalIndex[Interval[Timedelta]] | ||
| Interval[Timedelta] | ||
| Sequence[Interval[Timedelta]], | ||
data: IntervalIndex[Interval[_OrderableT]] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needed to switch to |
||
| Interval[_OrderableT] | ||
| Sequence[Interval[_OrderableT]], | ||
index: Axes | None = ..., | ||
dtype=..., | ||
dtype: Literal["Interval"] = ..., | ||
name: Hashable | None = ..., | ||
copy: bool = ..., | ||
fastpath: bool = ..., | ||
) -> IntervalSeries[Timedelta]: ... | ||
) -> IntervalSeries[_OrderableT]: ... | ||
@overload | ||
def __new__( | ||
cls, | ||
|
@@ -302,27 +267,24 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]): | |
index: Axes | None = ..., | ||
name: Hashable | None = ..., | ||
copy: bool = ..., | ||
fastpath: bool = ..., | ||
) -> Self: ... | ||
@overload | ||
def __new__( | ||
cls, | ||
data: Series[S1] | dict[int, S1] | dict[_str, S1] = ..., | ||
index: Axes | None = ..., | ||
dtype=..., | ||
dtype: Dtype = ..., | ||
name: Hashable | None = ..., | ||
copy: bool = ..., | ||
fastpath: bool = ..., | ||
) -> Self: ... | ||
@overload | ||
def __new__( | ||
cls, | ||
data: object | _ListLike | None = ..., | ||
index: Axes | None = ..., | ||
dtype=..., | ||
dtype: Dtype = ..., | ||
name: Hashable | None = ..., | ||
copy: bool = ..., | ||
fastpath: bool = ..., | ||
) -> Series: ... | ||
@property | ||
def hasnans(self) -> bool: ... | ||
|
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.
Can probably be done if #718 is possible