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



##########
File path: python/pyspark/pandas/data_type_ops/base.py
##########
@@ -0,0 +1,115 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+from abc import ABCMeta, abstractmethod
+
+from pandas.api.types import CategoricalDtype
+
+from pyspark.sql.types import (
+    BooleanType,
+    DataType,
+    DateType,
+    FractionalType,
+    IntegralType,
+    StringType,
+    TimestampType,
+)
+
+from pyspark.pandas.typedef import Dtype
+
+
+class DataTypeOps(object, metaclass=ABCMeta):
+    """The base class for binary operations of pandas-on-Spark objects (of 
different data types)."""
+
+    def __new__(cls, dtype: Dtype, spark_type: DataType):
+        from pyspark.pandas.data_type_ops.boolean_ops import BooleanOps
+        from pyspark.pandas.data_type_ops.categorical_ops import CategoricalOps
+        from pyspark.pandas.data_type_ops.date_ops import DateOps
+        from pyspark.pandas.data_type_ops.datetime_ops import DatetimeOps
+        from pyspark.pandas.data_type_ops.num_ops import (
+            IntegralOps,
+            FractionalOps,
+        )
+        from pyspark.pandas.data_type_ops.string_ops import StringOps
+
+        if isinstance(dtype, CategoricalDtype):
+            return object.__new__(CategoricalOps)
+        elif isinstance(spark_type, FractionalType):
+            return object.__new__(FractionalOps)
+        elif isinstance(spark_type, IntegralType):
+            return object.__new__(IntegralOps)
+        elif isinstance(spark_type, StringType):
+            return object.__new__(StringOps)
+        elif isinstance(spark_type, BooleanType):
+            return object.__new__(BooleanOps)
+        elif isinstance(spark_type, TimestampType):
+            return object.__new__(DatetimeOps)
+        elif isinstance(spark_type, DateType):
+            return object.__new__(DateOps)
+        else:
+            raise TypeError("Type %s was not understood." % dtype)
+
+    def __init__(self, dtype: Dtype, spark_type: DataType):
+        self.dtype = dtype
+        self.spark_type = spark_type
+
+    @property
+    @abstractmethod
+    def pretty_name(self):
+        raise NotImplementedError()
+
+    def __add__(self, left, right):
+        raise TypeError("Addition can not be applied to %s." % 
self.pretty_name)
+
+    def __sub__(self, left, right):
+        raise TypeError("Subtraction can not be applied to %s." % 
self.pretty_name)
+
+    def __mul__(self, left, right):
+        raise TypeError("Multiplication can not be applied to %s." % 
self.pretty_name)
+
+    def __truediv__(self, left, right):
+        raise TypeError("True division can not be applied to %s." % 
self.pretty_name)
+
+    def __floordiv__(self, left, right):
+        raise TypeError("Floor division can not be applied to %s." % 
self.pretty_name)
+
+    def __mod__(self, left, right):
+        raise TypeError("Modulo can not be applied to %s." % self.pretty_name)
+
+    def __pow__(self, left, right):
+        raise TypeError("Exponentiation can not be applied to %s." % 
self.pretty_name)
+
+    def __radd__(self, left, right=None):

Review comment:
       Do we need `=None` here and in the following functions?




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

Reply via email to