ueshin commented on a change in pull request #33162:
URL: https://github.com/apache/spark/pull/33162#discussion_r663194748



##########
File path: python/pyspark/pandas/base.py
##########
@@ -317,7 +317,7 @@ def copy(self: IndexOpsLike) -> IndexOpsLike:
 
     # arithmetic operators
     def __neg__(self: IndexOpsLike) -> IndexOpsLike:
-        return cast(IndexOpsLike, column_op(Column.__neg__)(self))
+        return cast(IndexOpsLike, self._dtype_op.__neg__(self))

Review comment:
       Shall we move `cast(IndexOpsLike, ...)` in the data type ops?

##########
File path: python/pyspark/pandas/base.py
##########
@@ -394,22 +394,29 @@ def __rpow__(self, other: Any) -> SeriesOrIndex:
         return self._dtype_op.rpow(self, other)
 
     def __abs__(self: IndexOpsLike) -> IndexOpsLike:
-        return cast(IndexOpsLike, column_op(F.abs)(self))
+        return cast(IndexOpsLike, self._dtype_op.__abs__(self))

Review comment:
       ditto.

##########
File path: python/pyspark/pandas/base.py
##########
@@ -394,22 +394,29 @@ def __rpow__(self, other: Any) -> SeriesOrIndex:
         return self._dtype_op.rpow(self, other)
 
     def __abs__(self: IndexOpsLike) -> IndexOpsLike:
-        return cast(IndexOpsLike, column_op(F.abs)(self))
+        return cast(IndexOpsLike, self._dtype_op.__abs__(self))
 
     # comparison operators
     def __eq__(self, other: Any) -> SeriesOrIndex:  # type: ignore[override]
-        return column_op(Column.__eq__)(self, other)
+        return self._dtype_op.eq(self, other)
 
     def __ne__(self, other: Any) -> SeriesOrIndex:  # type: ignore[override]
-        return column_op(Column.__ne__)(self, other)
+        return self._dtype_op.ne(self, other)
 
-    __lt__ = column_op(Column.__lt__)
-    __le__ = column_op(Column.__le__)
-    __ge__ = column_op(Column.__ge__)
-    __gt__ = column_op(Column.__gt__)
+    def __lt__(self, other: Any) -> SeriesOrIndex:
+        return self._dtype_op.lt(self, other)
+
+    def __le__(self, other: Any) -> SeriesOrIndex:
+        return self._dtype_op.le(self, other)
+
+    def __ge__(self, other: Any) -> SeriesOrIndex:
+        return self._dtype_op.ge(self, other)
+
+    def __gt__(self, other: Any) -> SeriesOrIndex:
+        return self._dtype_op.gt(self, other)
 
     def __invert__(self: IndexOpsLike) -> IndexOpsLike:
-        return cast(IndexOpsLike, column_op(Column.__invert__)(self))
+        return cast(IndexOpsLike, self._dtype_op.__invert__(self))

Review comment:
       ditto.

##########
File path: python/pyspark/pandas/data_type_ops/base.py
##########
@@ -318,6 +318,54 @@ def rand(self, left: IndexOpsLike, right: Any) -> 
SeriesOrIndex:
     def ror(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
         return left.__or__(right)
 
+    def __neg__(self, operand: IndexOpsLike) -> SeriesOrIndex:
+        from pyspark.pandas.base import column_op
+
+        return column_op(Column.__neg__)(operand)
+
+    def __abs__(self, operand: IndexOpsLike) -> SeriesOrIndex:

Review comment:
       ditto.

##########
File path: python/pyspark/pandas/data_type_ops/base.py
##########
@@ -318,6 +318,54 @@ def rand(self, left: IndexOpsLike, right: Any) -> 
SeriesOrIndex:
     def ror(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
         return left.__or__(right)
 
+    def __neg__(self, operand: IndexOpsLike) -> SeriesOrIndex:
+        from pyspark.pandas.base import column_op
+
+        return column_op(Column.__neg__)(operand)
+
+    def __abs__(self, operand: IndexOpsLike) -> SeriesOrIndex:
+        from pyspark.pandas.base import column_op
+
+        return column_op(F.abs)(operand)
+
+    def lt(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
+        from pyspark.pandas.base import column_op
+
+        return column_op(Column.__lt__)(left, right)
+
+    def le(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
+        from pyspark.pandas.base import column_op
+
+        return column_op(Column.__le__)(left, right)
+
+    def ge(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
+        from pyspark.pandas.base import column_op
+
+        return column_op(Column.__ge__)(left, right)
+
+    def gt(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
+        from pyspark.pandas.base import column_op
+
+        return column_op(Column.__gt__)(left, right)
+
+    def eq(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
+        from pyspark.pandas.base import column_op
+
+        return column_op(Column.__eq__)(left, right)
+
+    def ne(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
+        from pyspark.pandas.base import column_op
+
+        return column_op(Column.__ne__)(left, right)
+
+    def __invert__(self, operand: IndexOpsLike) -> SeriesOrIndex:

Review comment:
       ditto for the name `invert`?

##########
File path: python/pyspark/pandas/data_type_ops/base.py
##########
@@ -318,6 +318,54 @@ def rand(self, left: IndexOpsLike, right: Any) -> 
SeriesOrIndex:
     def ror(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
         return left.__or__(right)
 
+    def __neg__(self, operand: IndexOpsLike) -> SeriesOrIndex:
+        from pyspark.pandas.base import column_op
+
+        return column_op(Column.__neg__)(operand)
+
+    def __abs__(self, operand: IndexOpsLike) -> SeriesOrIndex:
+        from pyspark.pandas.base import column_op
+
+        return column_op(F.abs)(operand)
+
+    def lt(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
+        from pyspark.pandas.base import column_op
+
+        return column_op(Column.__lt__)(left, right)
+
+    def le(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
+        from pyspark.pandas.base import column_op
+
+        return column_op(Column.__le__)(left, right)
+
+    def ge(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
+        from pyspark.pandas.base import column_op
+
+        return column_op(Column.__ge__)(left, right)
+
+    def gt(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
+        from pyspark.pandas.base import column_op
+
+        return column_op(Column.__gt__)(left, right)
+
+    def eq(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
+        from pyspark.pandas.base import column_op
+
+        return column_op(Column.__eq__)(left, right)
+
+    def ne(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
+        from pyspark.pandas.base import column_op
+
+        return column_op(Column.__ne__)(left, right)
+
+    def __invert__(self, operand: IndexOpsLike) -> SeriesOrIndex:

Review comment:
       ditto.

##########
File path: python/pyspark/pandas/base.py
##########
@@ -426,7 +433,7 @@ def __ror__(self, other: Any) -> SeriesOrIndex:
         return self._dtype_op.ror(self, other)
 
     def __len__(self) -> int:
-        return len(self._psdf)
+        return self._dtype_op.__len__(self)

Review comment:
       I don't think we need to move this to data type ops?

##########
File path: python/pyspark/pandas/data_type_ops/base.py
##########
@@ -318,6 +318,54 @@ def rand(self, left: IndexOpsLike, right: Any) -> 
SeriesOrIndex:
     def ror(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
         return left.__or__(right)
 
+    def __neg__(self, operand: IndexOpsLike) -> SeriesOrIndex:

Review comment:
       Btw, can't we use the name `neg` here?

##########
File path: python/pyspark/pandas/data_type_ops/binary_ops.py
##########
@@ -63,6 +63,15 @@ def radd(self, left: IndexOpsLike, right: Any) -> 
SeriesOrIndex:
                 "Concatenation can not be applied to %s and the given type." % 
self.pretty_name
             )
 
+    def __neg__(self, operand: IndexOpsLike) -> SeriesOrIndex:
+        raise TypeError("Unary - can not be applied to %s." % self.pretty_name)
+
+    def __invert__(self, operand: IndexOpsLike) -> SeriesOrIndex:
+        raise TypeError("Unary ~ can not be applied to %s." % self.pretty_name)
+
+    def __abs__(self, operand: IndexOpsLike) -> SeriesOrIndex:
+        raise TypeError("abs() can not be applied to %s." % self.pretty_name)
+

Review comment:
       Those findings are really nice! 👍 

##########
File path: python/pyspark/pandas/data_type_ops/base.py
##########
@@ -318,6 +318,54 @@ def rand(self, left: IndexOpsLike, right: Any) -> 
SeriesOrIndex:
     def ror(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
         return left.__or__(right)
 
+    def __neg__(self, operand: IndexOpsLike) -> SeriesOrIndex:

Review comment:
       This should be `def __neg__(self, operand: IndexOpsLike) -> 
IndexOpsLike`?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to