From a930a111c7998694e10655142a74e554bf549183 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Wed, 5 May 2021 16:41:29 -0700 Subject: [PATCH] Error gracefully on attempts to perform bitwise binops with extension dtypes. --- python/cudf/cudf/core/frame.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/python/cudf/cudf/core/frame.py b/python/cudf/cudf/core/frame.py index 3d1866cffeb..2e6a3c54885 100644 --- a/python/cudf/cudf/core/frame.py +++ b/python/cudf/cudf/core/frame.py @@ -3630,8 +3630,15 @@ def _normalize_binop_value(self, other): def _bitwise_binop(self, other, op): """Type-coercing wrapper around _binaryop for bitwise operations.""" - self_is_bool = np.issubdtype(self.dtype, np.bool_) - other_is_bool = np.issubdtype(other.dtype, np.bool_) + # This will catch attempts at bitwise ops on extension dtypes. + try: + self_is_bool = np.issubdtype(self.dtype, np.bool_) + other_is_bool = np.issubdtype(other.dtype, np.bool_) + except TypeError: + raise TypeError( + f"Operation 'bitwise {op}' not supported between " + f"{self.dtype.type.__name__} and {other.dtype.type.__name__}" + ) if (self_is_bool or np.issubdtype(self.dtype, np.integer)) and ( other_is_bool or np.issubdtype(other.dtype, np.integer)