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



##########
File path: python/pyspark/pandas/data_type_ops/boolean_ops.py
##########
@@ -26,3 +39,144 @@ class BooleanOps(DataTypeOps):
     @property
     def pretty_name(self) -> str:
         return 'booleans'
+
+    def add(self, left, right) -> Union["Series", "Index"]:
+        if not is_valid_operand_for_numeric_arithmetic(right, 
allow_bool=False):
+            raise TypeError(
+                "Addition can not be applied to %s and the given type." % 
self.pretty_name)
+
+        if isinstance(right, numbers.Number) and not isinstance(right, bool):
+            left = left.spark.transform(lambda scol: 
scol.cast(as_spark_type(type(right))))
+            return left + right
+        else:
+            assert isinstance(right, IndexOpsMixin)

Review comment:
       You mentioned that `spark.Column` is allowed to be operands 
(https://github.com/apache/spark/pull/32611#discussion_r636607352), and if so, 
we should handle it properly.
   
   > And mypy likes this. Would you prefer to use cast instead?
   What do you mean?

##########
File path: python/pyspark/pandas/data_type_ops/boolean_ops.py
##########
@@ -26,3 +39,144 @@ class BooleanOps(DataTypeOps):
     @property
     def pretty_name(self) -> str:
         return 'booleans'
+
+    def add(self, left, right) -> Union["Series", "Index"]:
+        if not is_valid_operand_for_numeric_arithmetic(right, 
allow_bool=False):
+            raise TypeError(
+                "Addition can not be applied to %s and the given type." % 
self.pretty_name)
+
+        if isinstance(right, numbers.Number) and not isinstance(right, bool):
+            left = left.spark.transform(lambda scol: 
scol.cast(as_spark_type(type(right))))
+            return left + right
+        else:
+            assert isinstance(right, IndexOpsMixin)

Review comment:
       You mentioned that `spark.Column` is allowed to be operands 
(https://github.com/apache/spark/pull/32611#discussion_r636607352), and if so, 
we should handle it properly.
   
   > And mypy likes this. Would you prefer to use cast instead?
   
   What do you mean?




-- 
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.

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