Skip to content
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

Merged
merged 5 commits into from
Jun 5, 2023
Merged

Fix Series.__new__ #722

merged 5 commits into from
Jun 5, 2023

Conversation

twoertwein
Copy link
Member

I only added * for one overload as the implementation does not requires keyword-only arguments.

I also removed fastpath as it is not documented.

@@ -208,55 +209,52 @@ 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__
Copy link
Member Author

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

@twoertwein twoertwein requested a review from Dr-Irv May 31, 2023 13:38
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For astype, we created valid argument types for various types. It may not be fully inclusive, but we can do some restrictions in various places.

index: Axes | None = ...,
*,
dtype: Literal["datetime64[ns]"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should be TimestampDtypeArg

Copy link
Member Author

Choose a reason for hiding this comment

The 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 data and one for _ListLike but a specific dtype?

Copy link
Collaborator

Choose a reason for hiding this comment

The 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 TimestampSeries because it handles any kind of list.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should be TimestampDtypeArg

I think this is the only change left to make.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

) -> TimestampSeries: ...
@overload
def __new__(
cls,
data: PeriodIndex,
index: Axes | None = ...,
dtype=...,
dtype: Dtype = ...,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we need to create a PeriodDtypeArg in _typing.pyi with the valid values here

data: IntervalIndex[Interval[Timedelta]]
| Interval[Timedelta]
| Sequence[Interval[Timedelta]],
data: IntervalIndex[Interval[_OrderableT]]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to switch to bound to simplify these overloads. All the other changes are related to this change.

Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good. Can you merge to main to resolve conflicts?

Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @twoertwein

@Dr-Irv Dr-Irv merged commit 52f2f0c into pandas-dev:main Jun 5, 2023
@twoertwein twoertwein deleted the series branch August 14, 2023 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLEAN: Fix overloads for Series.__new__() to be consistent in argument ordering.
2 participants