Skip to content

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

Conversation

simonjayhawkins
Copy link
Member

follow-on from #40379 removing ignores that either changed or were added with the change of the ArrayLike alias to a Union

@simonjayhawkins simonjayhawkins added the Typing type annotations, mypy/pyright type checking label Mar 12, 2021
# 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_)
Copy link
Member Author

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"
Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member

@jbrockmendel jbrockmendel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

fill_value = astype_nansafe( # type: ignore[union-attr]
np.array(self.fill_value), dtype
).item()
dtype = cast(np.dtype, dtype)
Copy link
Member Author

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?

Copy link
Member

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

Copy link
Member Author

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.

@simonjayhawkins simonjayhawkins merged commit 0203f8d into pandas-dev:master Mar 13, 2021
@simonjayhawkins simonjayhawkins deleted the arraylike-alias-change-follow-up branch March 13, 2021 15:42
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants