From 9f32b93948830195a37c5dd5e4dc9ca346bb6d70 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Mon, 11 Jan 2021 20:25:26 +0700 Subject: [PATCH 1/3] TYP: fix mypy errors in pandas/core/arraylike.py --- pandas/core/arraylike.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pandas/core/arraylike.py b/pandas/core/arraylike.py index 6b28f8f135769..3ee93e0c11ff4 100644 --- a/pandas/core/arraylike.py +++ b/pandas/core/arraylike.py @@ -5,7 +5,7 @@ ExtensionArray """ import operator -from typing import Any, Callable +from typing import Any import warnings import numpy as np @@ -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): """ Compatibility with numpy ufuncs. @@ -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 @@ -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) From 8b8348621799ef64f1da2434c0e0f1f6f6874064 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Thu, 11 Feb 2021 18:37:34 +0700 Subject: [PATCH 2/3] TYP: remove type annotation --- pandas/core/arraylike.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pandas/core/arraylike.py b/pandas/core/arraylike.py index e17ba45f30d6c..3eff8799c8397 100644 --- a/pandas/core/arraylike.py +++ b/pandas/core/arraylike.py @@ -228,10 +228,16 @@ def _maybe_fallback(ufunc: Callable, method: str, *inputs: Any, **kwargs: Any): return NotImplemented -def array_ufunc(self, ufunc: np.ufunc, method: str, *inputs: Any, **kwargs: Any): +def array_ufunc(self, ufunc, method: str, *inputs: Any, **kwargs: Any): """ Compatibility with numpy ufuncs. + Note + ---- + ``ufunc`` should be of type ``np.ufunc``, but the typing is removed here + because for now ``np.ufunc`` resolves to ``Any``. + Consider adding the annotation when numpy types are implemented. + See also -------- numpy.org/doc/stable/reference/arrays.classes.html#numpy.class.__array_ufunc__ From 75a7a7049ed5703c9e295e9d79ff9ea7cae3433f Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Thu, 11 Feb 2021 20:57:05 +0700 Subject: [PATCH 3/3] Revert "TYP: remove type annotation" This reverts commit 8b8348621799ef64f1da2434c0e0f1f6f6874064. --- pandas/core/arraylike.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pandas/core/arraylike.py b/pandas/core/arraylike.py index 3eff8799c8397..e17ba45f30d6c 100644 --- a/pandas/core/arraylike.py +++ b/pandas/core/arraylike.py @@ -228,16 +228,10 @@ def _maybe_fallback(ufunc: Callable, method: str, *inputs: Any, **kwargs: Any): return NotImplemented -def array_ufunc(self, ufunc, method: str, *inputs: Any, **kwargs: Any): +def array_ufunc(self, ufunc: np.ufunc, method: str, *inputs: Any, **kwargs: Any): """ Compatibility with numpy ufuncs. - Note - ---- - ``ufunc`` should be of type ``np.ufunc``, but the typing is removed here - because for now ``np.ufunc`` resolves to ``Any``. - Consider adding the annotation when numpy types are implemented. - See also -------- numpy.org/doc/stable/reference/arrays.classes.html#numpy.class.__array_ufunc__