From bedb58a11636dc08a2d122583d16f244477f52fd Mon Sep 17 00:00:00 2001 From: Hiromasa Ihara Date: Mon, 3 Jan 2022 16:01:48 +0900 Subject: [PATCH 1/3] allow multiple series argument calling in ufunc --- pandas/core/arraylike.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/arraylike.py b/pandas/core/arraylike.py index e505d97d04a47..b8fbe5ab42e6a 100644 --- a/pandas/core/arraylike.py +++ b/pandas/core/arraylike.py @@ -247,6 +247,8 @@ def array_ufunc(self, ufunc: np.ufunc, method: str, *inputs: Any, **kwargs: Any) -------- numpy.org/doc/stable/reference/arrays.classes.html#numpy.class.__array_ufunc__ """ + from pandas import DataFrame + from pandas import Series from pandas.core.generic import NDFrame from pandas.core.internals import BlockManager @@ -295,7 +297,7 @@ def array_ufunc(self, ufunc: np.ufunc, method: str, *inputs: Any, **kwargs: Any) # so this ends up just being x1.index | x2.index, but we write # it to handle *args. - if len(set(types)) > 1: + if any([isinstance(t, DataFrame) for t in types]) and any([isinstance(t, Series) for t in types]): # We currently don't handle ufunc(DataFrame, Series) # well. Previously this raised an internal ValueError. We might # support it someday, so raise a NotImplementedError. From 2312cc7a2a122dae9ec7ce8ab72b57bf8303416b Mon Sep 17 00:00:00 2001 From: Hiromasa Ihara Date: Mon, 3 Jan 2022 16:05:58 +0900 Subject: [PATCH 2/3] fix lint --- pandas/core/arraylike.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/arraylike.py b/pandas/core/arraylike.py index b8fbe5ab42e6a..17ecb0edceff1 100644 --- a/pandas/core/arraylike.py +++ b/pandas/core/arraylike.py @@ -297,7 +297,8 @@ def array_ufunc(self, ufunc: np.ufunc, method: str, *inputs: Any, **kwargs: Any) # so this ends up just being x1.index | x2.index, but we write # it to handle *args. - if any([isinstance(t, DataFrame) for t in types]) and any([isinstance(t, Series) for t in types]): + if (any([isinstance(t, DataFrame) for t in types]) and + any([isinstance(t, Series) for t in types])): # We currently don't handle ufunc(DataFrame, Series) # well. Previously this raised an internal ValueError. We might # support it someday, so raise a NotImplementedError. From af455c5316b37cd2be1e0424d2fe4b229c79e179 Mon Sep 17 00:00:00 2001 From: Hiromasa Ihara Date: Mon, 3 Jan 2022 17:45:28 +0900 Subject: [PATCH 3/3] change wrong comparation from isinstance() to is --- pandas/core/arraylike.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/core/arraylike.py b/pandas/core/arraylike.py index 17ecb0edceff1..3b7eab91fff10 100644 --- a/pandas/core/arraylike.py +++ b/pandas/core/arraylike.py @@ -297,8 +297,7 @@ def array_ufunc(self, ufunc: np.ufunc, method: str, *inputs: Any, **kwargs: Any) # so this ends up just being x1.index | x2.index, but we write # it to handle *args. - if (any([isinstance(t, DataFrame) for t in types]) and - any([isinstance(t, Series) for t in types])): + if (any([t is DataFrame for t in types]) and any([t is Series for t in types])): # We currently don't handle ufunc(DataFrame, Series) # well. Previously this raised an internal ValueError. We might # support it someday, so raise a NotImplementedError.