Skip to content

TYP: fix mypy errors in pandas/core/arraylike.py #39104

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

Merged
merged 4 commits into from
Feb 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions pandas/core/arraylike.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def _maybe_fallback(ufunc: Callable, method: str, *inputs: Any, **kwargs: Any):
return NotImplemented


def array_ufunc(self, ufunc: Callable, method: str, *inputs: Any, **kwargs: Any):
def array_ufunc(self, ufunc: np.ufunc, method: str, *inputs: Any, **kwargs: Any):
Copy link
Member

Choose a reason for hiding this comment

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

np.ufunc currently resolves to Any. I would mothball this PR till we have numpy types.

maybe you could just remove the annotation for now so that the ignores can be removed.

or test this with numpy 1.20.0rc2

"""
Compatibility with numpy ufuncs.
Expand Down Expand Up @@ -341,9 +341,7 @@ def reconstruct(result):
result = result.__finalize__(self)
return result

if self.ndim > 1 and (
len(inputs) > 1 or ufunc.nout > 1 # type: ignore[attr-defined]
):
if self.ndim > 1 and (len(inputs) > 1 or ufunc.nout > 1):
# Just give up on preserving types in the complex case.
# In theory we could preserve them for them.
# * nout>1 is doable if BlockManager.apply took nout and
Expand All @@ -367,7 +365,7 @@ def reconstruct(result):
# Those can have an axis keyword and thus can't be called block-by-block
result = getattr(ufunc, method)(np.asarray(inputs[0]), **kwargs)

if ufunc.nout > 1: # type: ignore[attr-defined]
if ufunc.nout > 1:
result = tuple(reconstruct(x) for x in result)
else:
result = reconstruct(result)
Expand Down