Esempio n. 1
0
 def pyarrow_meth(data, skipna, **kwargs):
     numerator = pc.stddev(data, skip_nulls=skipna, **kwargs)
     denominator = pc.sqrt_checked(
         pc.subtract_checked(
             pc.count(self._data, skip_nulls=skipna),
             kwargs["ddof"]))
     return pc.divide_checked(numerator, denominator)
Esempio n. 2
0
    def _coerce_timestamp_windows(cls, vector: pa.Array, field: pa.Field):

        scaling_map = {"s": 1, "ms": 1000, "us": 1000000, "ns": 1000000000}
        src_scale = scaling_map.get(vector.type.unit)
        tgt_scale = scaling_map.get(field.type.unit)

        if src_scale is None or tgt_scale is None:
            raise _ex.EUnexpected()  # Invalid timestamp type

        int64_vector: pa.IntegerArray = pc.cast(vector, pa.int64())

        if src_scale > tgt_scale:

            scaling = src_scale / tgt_scale
            scaling_vector = pa.array([scaling for _ in range(len(vector))],
                                      pa.int64())
            scaled_vector = pc.divide_checked(int64_vector,
                                              scaling_vector)  # noqa

        else:

            scaling = tgt_scale / src_scale
            scaling_vector = pa.array([scaling for _ in range(len(vector))],
                                      pa.int64())
            scaled_vector = pc.multiply_checked(int64_vector,
                                                scaling_vector)  # noqa

        return pc.cast(scaled_vector, field.type)
Esempio n. 3
0
 def floordiv_compat(
     left: pa.ChunkedArray | pa.Array | pa.Scalar,
     right: pa.ChunkedArray | pa.Array | pa.Scalar,
 ) -> pa.ChunkedArray:
     # Ensure int // int -> int mirroring Python/Numpy behavior
     # as pc.floor(pc.divide_checked(int, int)) -> float
     result = pc.floor(pc.divide_checked(left, right))
     if pa.types.is_integer(left.type) and pa.types.is_integer(right.type):
         result = result.cast(left.type)
     return result
Esempio n. 4
0
def binary_col(op, l, r):
    """
  interpretor for executing binary operator expressions
  """
    if op == "+": return compute.add_checked(l, r)
    if op == "*": return compute.multiply_checked(l, r)
    if op == '-': return compute.subtract_checked(l, r)
    if op == "=": return compute.equal(l, r)
    if op == "<>": return compute.not_equal(l, r)
    if op == "!=": return compute.not_equal(l, r)
    if op == "or": return compute.or_(l, r)
    if op == "<": return compute.less(l, r)
    if op == ">": return compute.greater(l, r)
    if op == "/": return compute.divide_checked(l, r)
    if op == "and": return compute.and_(l, r)
    if op == "in": return compute.is_in(l, r)
    if op == "==": return compute.equal(l, r)
    if op == "<=": return compute.less_equal(l, r)
    if op == ">=": return compute.greater_equal(l, r)
    raise Exception("binary op not implemented")
Esempio n. 5
0
 "radd":
 NotImplemented
 if pa_version_under2p0 else lambda x, y: pc.add_checked(y, x),
 "sub":
 NotImplemented if pa_version_under2p0 else pc.subtract_checked,
 "rsub":
 NotImplemented
 if pa_version_under2p0 else lambda x, y: pc.subtract_checked(y, x),
 "mul":
 NotImplemented if pa_version_under2p0 else pc.multiply_checked,
 "rmul":
 NotImplemented
 if pa_version_under2p0 else lambda x, y: pc.multiply_checked(y, x),
 "truediv":
 NotImplemented if pa_version_under2p0 else
 lambda x, y: pc.divide_checked(cast_for_truediv(x, y), y),
 "rtruediv":
 NotImplemented if pa_version_under2p0 else
 lambda x, y: pc.divide_checked(y, cast_for_truediv(x, y)),
 "floordiv":
 NotImplemented
 if pa_version_under2p0 else lambda x, y: floordiv_compat(x, y),
 "rfloordiv":
 NotImplemented
 if pa_version_under2p0 else lambda x, y: floordiv_compat(y, x),
 "mod":
 NotImplemented,
 "rmod":
 NotImplemented,
 "divmod":
 NotImplemented,