-
-
Notifications
You must be signed in to change notification settings - Fork 124
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
Series(Mapping) #843
Series(Mapping) #843
Conversation
pandas-stubs/core/series.pyi
Outdated
@@ -294,7 +297,7 @@ class Series(IndexOpsMixin[S1], NDFrame): | |||
@overload | |||
def __new__( | |||
cls, | |||
data: S1 | _ListLike[S1] | dict[int, S1] | dict[_str, S1], | |||
data: S1 | Mapping[Any, S1] | _ListLike[S1], |
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.
I'm not happy with _ListLike
but a Mapping
is also Iterable
.
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.
I think we should consider using Mapping[Hashable, _appropriate_type_here]
instead of Mapping[Any, _approprirate_type_here]
, since we know that the keys of the dict will end up as column names.
pandas-stubs/core/series.pyi
Outdated
@@ -284,7 +287,7 @@ class Series(IndexOpsMixin[S1], NDFrame): | |||
@overload | |||
def __new__( | |||
cls, | |||
data: Scalar | _ListLike | dict[int, Any] | dict[_str, Any] | None, | |||
data: Scalar | Iterable | None, |
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.
I don't think Iterable
is correct here, because we don't (or shouldn't) accept a set
.
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.
Would it be correct to have one Never-overload for set
and then simply use data: Any
+ specified dtype
?
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.
I don't know. I'd rather keep things narrow by just using Scalar | _ListLike | dict[Hashable, Any] | None
. Or maybe we can use Mapping[Hashable, Scalar] instead of dict[Hashable, Any]
.
My feeling is that we should make small increments when we change the stubs so as to not widen things too much.
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.
My feeling is that we should make small increments when we change the stubs so as to not widen things too much.
[sorry, I edited your comment by accident - wanted to quote reply]
I agree about that! But I also feel like we are making ourselves too much work by trying to be as restrictive as possible.
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.
I agree about that! But I also feel like we are making ourselves too much work by trying to be as restrictive as possible.
Possibly. But I'd rather let the community report issues, and we really haven't had too many issues where we made things too restrictive.
See what I wrote here 18 months ago about this topic: https://github.com/pandas-dev/pandas-stubs/blob/main/docs/philosophy.md#narrow-vs-wide-arguments
pandas-stubs/core/series.pyi
Outdated
@@ -304,7 +307,7 @@ class Series(IndexOpsMixin[S1], NDFrame): | |||
@overload | |||
def __new__( | |||
cls, | |||
data: Scalar | _ListLike | dict[int, Any] | dict[_str, Any] | None = ..., | |||
data: Scalar | Iterable | None = ..., |
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.
same comment as above about Iterable
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.
Thanks @twoertwein
pd.Series
constructor should allowTimestamp
andtuple
as keys #831 (Replace xxxx with the Github issue number)assert_type()
to assert the type of any return value