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 1 commit
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
10 changes: 4 additions & 6 deletions pandas/core/arraylike.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ExtensionArray
"""
import operator
from typing import Any, Callable
from typing import Any
import warnings

import numpy as np
Expand Down Expand Up @@ -149,7 +149,7 @@ def __rpow__(self, other):
return self._arith_method(other, roperator.rpow)


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 @@ -257,9 +257,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 @@ -277,7 +275,7 @@ def reconstruct(result):
mgr = inputs[0]._mgr
result = mgr.apply(getattr(ufunc, method))

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