コード例 #1
0
ファイル: window.py プロジェクト: shubhampachori12110095/ibis
    def _validate_frame(self):
        p_tuple = has_p = False
        f_tuple = has_f = False
        if self.preceding is not None:
            p_tuple = isinstance(self.preceding, tuple)
            has_p = True

        if self.following is not None:
            f_tuple = isinstance(self.following, tuple)
            has_f = True

        if ((p_tuple and has_f) or (f_tuple and has_p)):
            raise com.IbisInputError('Can only specify one window side '
                                     ' when you want an off-center '
                                     'window')
        elif p_tuple:
            start, end = self.preceding
            if start is None:
                assert end >= 0
            else:
                assert start > end
        elif f_tuple:
            start, end = self.following
            if end is None:
                assert start >= 0
            else:
                assert start < end
        else:
            if has_p and self.preceding < 0:
                raise com.IbisInputError('Window offset must be positive')

            if has_f and self.following < 0:
                raise com.IbisInputError('Window offset must be positive')
コード例 #2
0
ファイル: client.py プロジェクト: zuxfoucault/ibis
def _validate_compatible(from_schema, to_schema):
    if from_schema.names != to_schema.names:
        raise com.IbisInputError('Schemas have different names')

    for lt, rt in zip(from_schema.types, to_schema.types):
        if not rt.can_implicit_cast(lt):
            raise com.IbisInputError(
                'Cannot safely cast {0!r} to {1!r}'.format(lt, rt))
コード例 #3
0
ファイル: client.py プロジェクト: tonyfast/ibis
def _validate_compatible(from_schema, to_schema):
    if set(from_schema.names) != set(to_schema.names):
        raise com.IbisInputError('Schemas have different names')

    for name in from_schema:
        lt = from_schema[name]
        rt = to_schema[name]
        if not lt.castable(rt):
            raise com.IbisInputError(
                'Cannot safely cast {0!r} to {1!r}'.format(lt, rt))
    return
コード例 #4
0
    def _validate_frame(self):
        preceding_tuple = has_preceding = False
        following_tuple = has_following = False
        if self.preceding is not None:
            preceding_tuple = isinstance(self.preceding, tuple)
            has_preceding = True

        if self.following is not None:
            following_tuple = isinstance(self.following, tuple)
            has_following = True

        if ((preceding_tuple and has_following) or
                (following_tuple and has_preceding)):
            raise com.IbisInputError(
                'Can only specify one window side when you want an '
                'off-center window'
            )
        elif preceding_tuple:
            start, end = self.preceding
            if start is None:
                assert end >= 0
            else:
                assert start > end
        elif following_tuple:
            start, end = self.following
            if end is None:
                assert start >= 0
            else:
                assert start < end
        else:
            if not isinstance(self.preceding, ir.Expr):
                if has_preceding and self.preceding < 0:
                    raise com.IbisInputError(
                        "'preceding' must be positive, got {}".format(
                            self.preceding
                        )
                    )

            if not isinstance(self.following, ir.Expr):
                if has_following and self.following < 0:
                    raise com.IbisInputError(
                        "'following' must be positive, got {}".format(
                            self.following
                        )
                    )
        if self.how not in {'rows', 'range'}:
            raise com.IbisInputError(
                "'how' must be 'rows' or 'range', got {}"
                .format(
                    self.how
                )
            )
コード例 #5
0
ファイル: window.py プロジェクト: tonyfast/ibis
 def combine(self, window):
     if self.how != window.how:
         raise com.IbisInputError(
             "Window types must match. Expecting '{}' Window, got '{}'".
             format(self.how.upper(), window.how.upper()))
     kwds = dict(preceding=self.preceding or window.preceding,
                 following=self.following or window.following,
                 group_by=self._group_by + window._group_by,
                 order_by=self._order_by + window._order_by)
     return Window(**kwds)
コード例 #6
0
    def __init__(self, *args, **kwargs):
        if 'prefixes' in kwargs:
            raise NotImplementedError

        if len(args) < 2:
            raise com.IbisInputError('Must pass at least 2 tables')

        left = args[0]
        right = args[1]
        for t in args[2:]:
            right = right.cross_join(t)
        InnerJoin.__init__(self, left, right, [])
コード例 #7
0
def _truncate_unit_validate(unit):
    orig_unit = unit
    unit = unit.upper()

    # TODO: truncate autocompleter

    unit = _truncate_unit_aliases.get(unit, unit)
    valid_units = set(_truncate_units)

    if unit not in valid_units:
        raise com.IbisInputError('Passed unit {0} was not one of'
                                 ' {1}'.format(orig_unit, repr(valid_units)))

    return unit
コード例 #8
0
ファイル: window.py プロジェクト: martint/ibis
    def combine(self, window):
        if self.how != window.how:
            raise com.IbisInputError(
                ("Window types must match. "
                 "Expecting '{}' Window, got '{}'").format(
                     self.how.upper(), window.how.upper()))

        kwds = dict(
            preceding=_choose_non_empty_val(self.preceding, window.preceding),
            following=_choose_non_empty_val(self.following, window.following),
            max_lookback=self.max_lookback or window.max_lookback,
            group_by=self._group_by + window._group_by,
            order_by=self._order_by + window._order_by,
        )
        return Window(**kwds)
コード例 #9
0
ファイル: compiler.py プロジェクト: wkusnierczyk/ibis
def _time_range_to_range_window(translator, window):
    # Check that ORDER BY column is a single time column:
    order_by_vars = [x.op().args[0] for x in window._order_by]
    if len(order_by_vars) > 1:
        raise com.IbisInputError("Expected 1 order-by variable, got {}".format(
            len(order_by_vars)))

    order_var = window._order_by[0].op().args[0]
    timestamp_order_var = order_var.cast('int64')
    window = window._replace(order_by=timestamp_order_var, how='range')

    # Need to change preceding interval expression to scalars
    preceding = window.preceding
    if isinstance(preceding, ir.IntervalScalar):
        new_preceding = _replace_interval_with_scalar(preceding)
        window = window._replace(preceding=new_preceding)

    return window
コード例 #10
0
ファイル: window.py プロジェクト: martint/ibis
    def _validate_frame(self):
        preceding_tuple = has_preceding = False
        following_tuple = has_following = False
        if self.preceding is not None:
            preceding_tuple = isinstance(self.preceding, tuple)
            has_preceding = True

        if self.following is not None:
            following_tuple = isinstance(self.following, tuple)
            has_following = True

        if (preceding_tuple and has_following) or (following_tuple
                                                   and has_preceding):
            raise com.IbisInputError(
                'Can only specify one window side when you want an '
                'off-center window')
        elif preceding_tuple:
            start, end = self.preceding
            if end is None:
                raise com.IbisInputError("preceding end point cannot be None")
            if end < 0:
                raise com.IbisInputError(
                    "preceding end point must be non-negative")
            if start is not None:
                if start < 0:
                    raise com.IbisInputError(
                        "preceding start point must be non-negative")
                if start <= end:
                    raise com.IbisInputError(
                        "preceding start must be greater than preceding end")
        elif following_tuple:
            start, end = self.following
            if start is None:
                raise com.IbisInputError(
                    "following start point cannot be None")
            if start < 0:
                raise com.IbisInputError(
                    "following start point must be non-negative")
            if end is not None:
                if end < 0:
                    raise com.IbisInputError(
                        "following end point must be non-negative")
                if start >= end:
                    raise com.IbisInputError(
                        "following start must be less than following end")
        else:
            if not isinstance(self.preceding, ir.Expr):
                if has_preceding and self.preceding < 0:
                    raise com.IbisInputError(
                        "'preceding' must be positive, got {}".format(
                            self.preceding))

            if not isinstance(self.following, ir.Expr):
                if has_following and self.following < 0:
                    raise com.IbisInputError(
                        "'following' must be positive, got {}".format(
                            self.following))
        if self.how not in {'rows', 'range'}:
            raise com.IbisInputError(
                "'how' must be 'rows' or 'range', got {}".format(self.how))

        if self.max_lookback is not None:
            if not isinstance(self.preceding,
                              (ir.IntervalValue, pd.Timedelta)):
                raise com.IbisInputError(
                    "'max_lookback' must be specified as an interval "
                    "or pandas.Timedelta object")
コード例 #11
0
 def _check_library(self):
     suffix = self.lib_path[-3:]
     if suffix == '.ll':
         raise com.IbisInputError('LLVM IR UDAs are not yet supported')
     elif suffix != '.so':
         raise ValueError('Invalid file type. Must be .so')
コード例 #12
0
 def __init__(self, expr, window):
     if not is_analytic(expr):
         raise com.IbisInputError('Expression does not contain a valid '
                                  'window operation')
     ValueNode.__init__(self, expr, window)