ueshin commented on a change in pull request #32611:
URL: https://github.com/apache/spark/pull/32611#discussion_r637338469
##########
File path: python/pyspark/pandas/data_type_ops/num_ops.py
##########
@@ -16,31 +16,46 @@
#
import numbers
-from typing import TYPE_CHECKING, Union
+from typing import Any, TYPE_CHECKING, Union
import numpy as np
from pandas.api.types import CategoricalDtype
from pyspark.sql import Column, functions as F
from pyspark.sql.types import (
+ BooleanType,
NumericType,
StringType,
TimestampType,
)
from pyspark.pandas.base import column_op, IndexOpsMixin, numpy_column_op
-from pyspark.pandas.data_type_ops.base import DataTypeOps
+from pyspark.pandas.data_type_ops.base import DataTypeOps,
transform_boolean_operand_to_numeric
from pyspark.pandas.spark import functions as SF
+from pyspark.sql.column import Column
+
if TYPE_CHECKING:
from pyspark.pandas.indexes import Index # noqa: F401 (SPARK-34943)
from pyspark.pandas.series import Series # noqa: F401 (SPARK-34943)
+def is_valid_operand_for_numeric_arithmetic(operand: Any) -> bool:
+ """Check whether the operand is valid for arithmetic operations against
numerics."""
+ if isinstance(operand, numbers.Number):
+ return True
+ elif isinstance(operand, IndexOpsMixin):
+ if isinstance(operand.dtype, CategoricalDtype):
+ return False
+ else:
+ return isinstance(operand.spark.data_type, NumericType) or
isinstance(
+ operand.spark.data_type, BooleanType)
+ else:
+ return isinstance(operand, Column)
Review comment:
Do we currently allow it?
--
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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]