-
-
Notifications
You must be signed in to change notification settings - Fork 152
Type ExtensionArray.view, ExtensionArray.astype, ExtensionArray.fillna and ExtensionArray.searchsorted
#1435
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
f64cbef to
54ebfc3
Compare
54ebfc3 to
479c397
Compare
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.
- It adds types to
.astype,.fillna,.viewand.searchsortedwith tests (addresses #1317) - It also adds
Anyto.tolistand adds default values._reduce - Just minor comment, otherwise good to go
| @overload | ||
| def astype(self, dtype: np.dtype, copy: bool = True) -> np.ndarray: ... | ||
| @overload | ||
| def astype(self, dtype: ExtensionDtype, copy: bool = True) -> ExtensionArray: ... |
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 would try
| def astype(self, dtype: ExtensionDtype, copy: bool = True) -> ExtensionArray: ... | |
| def astype(self, dtype: ExtensionDtype, copy: bool = True) -> Self: ... |
because I guess you can't convert an IntervalArray to an IntegerArray by .astype. But I understand that this is unspecified in the docs, so keeping -> ExtensionArray is also fine.
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 it possible though?
In [34]: arr = pd.Series([1.]).array
In [35]: arr
Out[35]:
<NumpyExtensionArray>
[1.0]
Length: 1, dtype: float64
In [36]: arr.astype('Int64')
Out[36]:
<IntegerArray>
[1]
Length: 1, dtype: Int64There 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 see, my assumption was not correct.
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.
Looks good to me. I hope one day we can get rid of -> ExtensionArray, but we can leave it for another project. Thank you @MarcoGorelli !
| @overload | ||
| def astype(self, dtype: np.dtype, copy: bool = True) -> np.ndarray: ... | ||
| @overload | ||
| def astype(self, dtype: ExtensionDtype, copy: bool = True) -> ExtensionArray: ... |
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 see, my assumption was not correct.
assert_type()to assert the type of any return value