You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/06/08 16:42:36 UTC

[GitHub] [spark] xinrong-databricks commented on a change in pull request #32785: [SPARK-35601][PYTHON] Support arithmetic operations against bool literals

xinrong-databricks commented on a change in pull request #32785:
URL: https://github.com/apache/spark/pull/32785#discussion_r647616907



##########
File path: python/pyspark/pandas/data_type_ops/base.py
##########
@@ -52,33 +52,42 @@
     from pyspark.pandas.series import Series  # noqa: F401 (SPARK-34943)
 
 
-def is_valid_operand_for_numeric_arithmetic(operand: Any, *, allow_bool: bool = True) -> bool:
-    """Check whether the operand is valid for arithmetic operations against numerics."""
+def is_valid_operand_for_numeric_arithmetic(
+    operand: Any, *, allow_bool_index_ops: bool = True, allow_bool: bool = True

Review comment:
       There is a case `allow_bool_index_ops` is not allowed, thus, `allow_bool` is allowed alone.
   
   `allow_bool_index_ops` is set `True` for arithmetics operations against numeric Series and Indexes in order to enable cases as
   ```py
   >>> ps.Series([1, 2, 3]) + ps.Series([True, False, True])
   0    2                                                                          
   1    2
   2    4
   dtype: int64
   ```
   
   However, the case below is not supported now.
   ```py
   >>> ps.Series([True, False, True]) + ps.Series([True, False, True])
   Traceback (most recent call last):
   ...
   TypeError: Addition can not be applied to booleans and the given type.
   ```
   
   The two cases above both use `is_valid_operand_for_numeric_arithmetic` as an input validation, so `allow_bool_index_ops` might be needed.
   
   How do you think about that?




-- 
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:
users@infra.apache.org



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