From 89f61c2164ba1bed6fd878fc6327bac120f44e3d Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Fri, 16 Aug 2019 16:57:40 -0700 Subject: [PATCH 1/2] dispatch to extension --- pandas/core/ops/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/core/ops/__init__.py b/pandas/core/ops/__init__.py index dbcf09a401f27..7fd385adf7246 100644 --- a/pandas/core/ops/__init__.py +++ b/pandas/core/ops/__init__.py @@ -818,6 +818,12 @@ def wrapper(self, other): # Defer to DataFrame implementation; fail early return NotImplemented + elif is_extension_array_dtype(self): + # e.g. SparseArray + res_values = op(self._values, other) + return self._constructor(res_values, index=self.index, name=res_name) + # TODO: finalize? + elif isinstance(other, (ABCSeries, ABCIndexClass)): is_other_int_dtype = is_integer_dtype(other.dtype) other = fill_int(other) if is_other_int_dtype else fill_bool(other) From 748058035c64487d57de9ba7124b3803364d6928 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Fri, 16 Aug 2019 17:25:33 -0700 Subject: [PATCH 2/2] use extension dispatch --- pandas/core/ops/__init__.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pandas/core/ops/__init__.py b/pandas/core/ops/__init__.py index 7fd385adf7246..e917a5c999238 100644 --- a/pandas/core/ops/__init__.py +++ b/pandas/core/ops/__init__.py @@ -818,11 +818,10 @@ def wrapper(self, other): # Defer to DataFrame implementation; fail early return NotImplemented - elif is_extension_array_dtype(self): + elif should_extension_dispatch(self, other): # e.g. SparseArray - res_values = op(self._values, other) - return self._constructor(res_values, index=self.index, name=res_name) - # TODO: finalize? + res_values = dispatch_to_extension_op(op, self, other) + return _construct_result(self, res_values, index=self.index, name=res_name) elif isinstance(other, (ABCSeries, ABCIndexClass)): is_other_int_dtype = is_integer_dtype(other.dtype)