From 029b1dbbaf4aa7f2eb19f29a68589e574c0c7230 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Thu, 6 Oct 2022 10:41:33 -0700 Subject: [PATCH] Fix RangeIndex unary operators. (#11868) These operators rely on a method that was renamed in #11272 and are also out of sync with the rest of the `RangeIndex` design now that the `__getattr__` overload has been removed (#10538). Authors: - Vyas Ramasubramani (https://github.com/vyasr) Approvers: - GALI PREM SAGAR (https://github.com/galipremsagar) URL: https://github.com/rapidsai/cudf/pull/11868 --- 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):