예제 #1
0
    def rtruediv(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
        _sanitize_list_like(right)
        if not isinstance(right, numbers.Number):
            raise TypeError("True division can not be applied to given types.")

        def rtruediv(left: Column, right: Any) -> Column:
            return F.when(left == 0,
                          SF.lit(np.inf).__div__(right)).otherwise(
                              SF.lit(right).__truediv__(left))

        right = transform_boolean_operand_to_numeric(
            right, spark_type=left.spark.data_type)
        return numpy_column_op(rtruediv)(left, right)
예제 #2
0
    def floordiv(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
        if not is_valid_operand_for_numeric_arithmetic(right):
            raise TypeError("Floor division can not be applied to given types.")

        def floordiv(left: Column, right: Any) -> Column:
            return F.when(SF.lit(right is np.nan), np.nan).otherwise(
                F.when(
                    SF.lit(right != 0) | SF.lit(right).isNull(), F.floor(left.__div__(right))
                ).otherwise(SF.lit(np.inf).__div__(left))
            )

        right = transform_boolean_operand_to_numeric(right, spark_type=left.spark.data_type)
        return numpy_column_op(floordiv)(left, right)
예제 #3
0
    def rfloordiv(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
        if not isinstance(right, numbers.Number):
            raise TypeError("Floor division can not be applied to given types.")

        def rfloordiv(left: Column, right: Any) -> Column:
            return F.when(SF.lit(left == 0), SF.lit(np.inf).__div__(right)).otherwise(
                F.when(SF.lit(left) == np.nan, np.nan).otherwise(
                    F.floor(SF.lit(right).__div__(left))
                )
            )

        right = transform_boolean_operand_to_numeric(right, spark_type=left.spark.data_type)
        return numpy_column_op(rfloordiv)(left, right)
예제 #4
0
    def rtruediv(self, left, right) -> Union["Series", "Index"]:
        if isinstance(right, str):
            raise TypeError(
                "division can not be applied on string series or literals.")
        if not isinstance(right, numbers.Number) or isinstance(right, bool):
            raise TypeError("division can not be applied to given types.")

        def rtruediv(left, right):
            return F.when(left == 0,
                          F.lit(np.inf).__div__(right)).otherwise(
                              F.lit(right).__truediv__(left))

        return numpy_column_op(rtruediv)(left, right)
예제 #5
0
파일: num_ops.py 프로젝트: kangdw0x80/spark
    def rtruediv(self, left: T_IndexOps, right: Any) -> IndexOpsLike:
        if isinstance(right, str):
            raise TypeError(
                "division can not be applied on string series or literals.")
        if not isinstance(right, numbers.Number):
            raise TypeError("division can not be applied to given types.")

        def rtruediv(left: Column, right: Any) -> Column:
            return F.when(left == 0,
                          F.lit(np.inf).__div__(right)).otherwise(
                              F.lit(right).__truediv__(left))

        right = transform_boolean_operand_to_numeric(right,
                                                     left.spark.data_type)
        return numpy_column_op(rtruediv)(left, right)
예제 #6
0
    def rfloordiv(self, left, right) -> Union["Series", "Index"]:
        if isinstance(right, str):
            raise TypeError(
                "division can not be applied on string series or literals.")
        if not isinstance(right, numbers.Number):
            raise TypeError("division can not be applied to given types.")

        def rfloordiv(left, right):
            return F.when(F.lit(left == 0),
                          F.lit(np.inf).__div__(right)).otherwise(
                              F.floor(F.lit(right).__div__(left)))

        right = transform_boolean_operand_to_numeric(right,
                                                     left.spark.data_type)
        return numpy_column_op(rfloordiv)(left, right)
예제 #7
0
파일: num_ops.py 프로젝트: kangdw0x80/spark
    def truediv(self, left: T_IndexOps, right: Any) -> IndexOpsLike:
        if (isinstance(right, IndexOpsMixin) and isinstance(
                right.spark.data_type, StringType)) or isinstance(right, str):
            raise TypeError(
                "division can not be applied on string series or literals.")

        if not is_valid_operand_for_numeric_arithmetic(right):
            raise TypeError("division can not be applied to given types.")

        right = transform_boolean_operand_to_numeric(right,
                                                     left.spark.data_type)

        def truediv(left: Column, right: Any) -> Column:
            return F.when(
                F.lit(right != 0) | F.lit(right).isNull(),
                left.__div__(right)).otherwise(F.lit(np.inf).__div__(left))

        return numpy_column_op(truediv)(left, right)
예제 #8
0
    def truediv(self, left, right) -> Union["Series", "Index"]:
        if (isinstance(right, IndexOpsMixin) and isinstance(
                right.spark.data_type, StringType)) or isinstance(right, str):
            raise TypeError(
                "division can not be applied on string series or literals.")

        if (isinstance(right, IndexOpsMixin) and
            (isinstance(right.dtype, CategoricalDtype) or
             (not isinstance(right.spark.data_type, NumericType)))
            ) and not isinstance(right, numbers.Number):
            raise TypeError("division can not be applied to given types.")

        def truediv(left, right):
            return F.when(
                F.lit(right != 0) | F.lit(right).isNull(),
                left.__div__(right)).otherwise(F.lit(np.inf).__div__(left))

        return numpy_column_op(truediv)(left, right)
예제 #9
0
    def floordiv(self, left, right) -> Union["Series", "Index"]:
        if (isinstance(right, IndexOpsMixin) and isinstance(
                right.spark.data_type, StringType)) or isinstance(right, str):
            raise TypeError(
                "division can not be applied on string series or literals.")

        if not is_valid_operand_for_numeric_arithmetic(right):
            raise TypeError("division can not be applied to given types.")

        right = transform_boolean_operand_to_numeric(right,
                                                     left.spark.data_type)

        def floordiv(left, right):
            return F.when(F.lit(right is np.nan), np.nan).otherwise(
                F.when(
                    F.lit(right != 0) | F.lit(right).isNull(),
                    F.floor(left.__div__(right))).otherwise(
                        F.lit(np.inf).__div__(left)))

        return numpy_column_op(floordiv)(left, right)