-
-
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
TYP: Arraylike alias change follow up #40398
Conversation
pandas/io/parsers/base_parser.py
Outdated
# error: Argument 2 to "astype_nansafe" has incompatible type | ||
# "Type[str]"; expected "Union[dtype[Any], ExtensionDtype]" | ||
values = astype_nansafe(values, str) # type: ignore[arg-type] | ||
values = astype_nansafe(values, np.string_) |
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 this should be np.dtype(str). will change shortly.
@@ -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 comment
The 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 comment
The 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 flags
. ignoring for the time being seems reasonable
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.
LGTM
pandas/core/arrays/sparse/dtype.py
Outdated
fill_value = astype_nansafe( # type: ignore[union-attr] | ||
np.array(self.fill_value), dtype | ||
).item() | ||
dtype = cast(np.dtype, 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.
@jbrockmendel rather than cast
, should I change the is_extension_array_dtype
above to an isinstance
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.
follow-on from #40379 removing ignores that either changed or were added with the change of the ArrayLike alias to a Union