def _py_arithmetic_op()

in torcharrow/icolumn.py [0:0]


    def _py_arithmetic_op(self, other, fun, div=""):
        others = None
        other_dtype = None
        if isinstance(other, IColumn):
            others = other._items()
            other_dtype = other.dtype
        else:
            others = itertools.repeat((False, other))
            other_dtype = dt.infer_dtype_from_value(other)

        # TODO: should we just move _py_arithmetic_op to INumericColumn since it only works for boolean/numeric types
        if not dt.is_boolean_or_numerical(self.dtype) or not dt.is_boolean_or_numerical(
            other_dtype
        ):
            raise TypeError(f"{type(self).__name__}.{fun.__name__} is not supported")

        res = []
        if div != "":
            res_dtype = dt.Float64(self.dtype.nullable or other_dtype.nullable)
            for (m, i), (n, j) in zip(self._items(), others):
                # TODO Use error handling to mke this more efficient..
                if m or n:
                    res.append(None)
                elif div == "__truediv__" and j == 0:
                    res.append(None)
                elif div == "__rtruediv__" and i == 0:
                    res.append(None)
                else:
                    res.append(fun(i, j))
        else:
            res_dtype = dt.promote(self.dtype, other_dtype)
            if res_dtype is None:
                raise TypeError(f"{self.dtype} and {other_dtype} are incompatible")
            for (m, i), (n, j) in zip(self._items(), others):
                if m or n:
                    res.append(None)
                else:
                    res.append(fun(i, j))
        return Scope._FromPyList(res, res_dtype)