From dfb4b914389545eb7007c13f2c578618701537b5 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Wed, 5 Oct 2022 15:38:28 -0700 Subject: [PATCH] Fix RangeIndex unary operators. --- python/cudf/cudf/core/index.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/python/cudf/cudf/core/index.py b/python/cudf/cudf/core/index.py index b6ae7beebc5..3734893627f 100644 --- a/python/cudf/cudf/core/index.py +++ b/python/cudf/cudf/core/index.py @@ -867,15 +867,14 @@ def min(self): def max(self): return self._minmax("max") + def __neg__(self): + return -self._as_int_index() -# Patch in all binops and unary ops, which bypass __getattr__ on the instance -# and prevent the above overload from working. -for unaop in ("__neg__", "__pos__", "__abs__"): - setattr( - RangeIndex, - unaop, - lambda self, op=unaop: getattr(self._as_int64(), op)(), - ) + def __pos__(self): + return +self._as_int_index() + + def __abs__(self): + return abs(self._as_int_index()) class GenericIndex(SingleColumnFrame, BaseIndex):