-
-
Notifications
You must be signed in to change notification settings - Fork 145
Add type parameter to remaining Series.astype overloads. #949
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
Conversation
pandas-stubs/core/series.pyi
Outdated
@@ -1320,14 +1320,14 @@ class Series(IndexOpsMixin[S1], NDFrame): | |||
dtype: CategoryDtypeArg, | |||
copy: _bool = ..., | |||
errors: IgnoreRaise = ..., | |||
) -> Series: ... | |||
) -> Series[CategoryDtypeArg]: ... |
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.
This needs to be CategoryDtype
as it is value in 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.
Made the change
tests/test_series.py
Outdated
assert_type(s.astype(pd.CategoricalDtype()), "pd.Series[CategoryDtypeArg]") | ||
assert_type(s.astype("category"), "pd.Series[CategoryDtypeArg]") |
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.
Should be CategoryDtype
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.
Here too
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 @JanEricNitschke
assert_type()
to assert the type of any return valueCloses #948
Verified that some of the test statements here pass pyright strict with this change that do not do so without.
Tested using
object
instead ofAny
as that is the runtime behaviour, but that did not work due to the parameter bounds.Other option (maybe better?) would be to explicitely return as series matching the specified parameter? But i think that does not work either because the bounds of the type parameter for series are more restrictive than the input arguments for
astype
.