-
-
Notifications
You must be signed in to change notification settings - Fork 141
ENH: Add support for dtype string aliases to Series#astype
#556
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
ENH: Add support for dtype string aliases to Series#astype
#556
Conversation
Series#astype
Series#astype
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 @skatsuta . I had a feeling that someone would pick up many of the possibilities that were missed when we put this together.
@Dr-Irv Thanks for merging quickly! Your hunch was right on the money ;) Will this fix be released in a few days? |
I should be able to do a release by Friday 3/3, if not earlier. |
Looks like |
No, it's there. pandas-stubs/pandas-stubs/_typing.pyi Line 151 in d2faa7f
|
Weird, using v1.5.3.230227, which has that, I got this message
I guess because pandas-stubs/pandas-stubs/_typing.pyi Lines 153 to 164 in d2faa7f
|
Yes, you are correct. Can you open up a new issue for |
…dev#556) * Add support for nullable integer data types to Series#astype * Add support for nullable float data types to Series#astype * Add support for nullable boolean data type to Series#astype * Add support for nullable string data type to Series#astype * Refactor dtype arg type aliases and add missing dtype aliases
assert_type()
to assert the type of any return valueProblem
Series#astype
has been improved in #519 to allow specific types to be inferred based on a value of thedtype
argument.I really appreciate the hard work that has been put into it.
However, that PR lacked support for aliases that specify dtype as a string.
Therefore, starting with version v1.5.3.230227, type checkers now report the following errors for code like below:
Sample code
Errors reported by Pyright
Specifying dtype as a string is perfectly fine in pandas, so we need to fix the stub so that the errors are not reported for code like the above.
Solution
Add support for various dtype string aliases to
(Boolean|Int|Str|Float|Complex)DtypeArg
types, and add tests for passing each of those aliases as arguments toSeries#astype
.Along with this, I have also refactored the stubs and tests to group code for the same dtype together so that it is easier to see what kind of dtype arguments are supported.