-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: Arraylike alias change follow up #40398
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
Changes from 4 commits
193ff2f
a6500c7
1570db3
c5374e3
e151708
c8740e5
683d441
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
Type, | ||
Union, | ||
cast, | ||
overload, | ||
) | ||
import warnings | ||
|
||
|
@@ -107,6 +108,8 @@ | |
) | ||
|
||
if TYPE_CHECKING: | ||
from typing import Literal | ||
|
||
from pandas import Series | ||
from pandas.core.arrays import ( | ||
DatetimeArray, | ||
|
@@ -1164,6 +1167,20 @@ def astype_td64_unit_conversion( | |
return result | ||
|
||
|
||
@overload | ||
def astype_nansafe( | ||
arr: np.ndarray, dtype: np.dtype, copy: bool = ..., skipna: bool = ... | ||
) -> np.ndarray: | ||
... | ||
|
||
|
||
@overload | ||
def astype_nansafe( | ||
arr: np.ndarray, dtype: ExtensionDtype, copy: bool = ..., skipna: bool = ... | ||
) -> ExtensionArray: | ||
... | ||
|
||
|
||
def astype_nansafe( | ||
arr: np.ndarray, dtype: DtypeObj, copy: bool = True, skipna: bool = False | ||
) -> ArrayLike: | ||
|
@@ -1190,14 +1207,10 @@ def astype_nansafe( | |
flags = arr.flags | ||
flat = arr.ravel("K") | ||
result = astype_nansafe(flat, dtype, copy=copy, skipna=skipna) | ||
order = "F" if flags.f_contiguous else "C" | ||
order: Literal["C", "F"] = "F" if flags.f_contiguous else "C" | ||
# error: Item "ExtensionArray" of "Union[ExtensionArray, ndarray]" has no | ||
# attribute "reshape" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jbrockmendel this is not necessarily a false positive. I think this maybe assuming that if ndim > 1, we have a numpy array. but a 2d EA will have additional methods such as reshape. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yah even if we got here with NDArrayBackedExtensionArray (which does have reshape) itd break bc it doesn't have |
||
# error: No overload variant of "reshape" of "_ArrayOrScalarCommon" matches | ||
# argument types "Tuple[int, ...]", "str" | ||
return result.reshape( # type: ignore[union-attr,call-overload] | ||
arr.shape, order=order | ||
) | ||
return result.reshape(arr.shape, order=order) # type: ignore[union-attr] | ||
|
||
# We get here with 0-dim from sparse | ||
arr = np.atleast_1d(arr) | ||
|
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.
@jbrockmendel rather than
cast
, should I change theis_extension_array_dtype
above to anisinstance
check for consistency with the other PRs to remove ignores?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.
as long as you've reliably got a DtypeObj, then yes. the isinstance checks are more performant
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.
cool. done that. i'll take your LGTM as an approval and self merge this soon.