コード例 #1
0
ファイル: signature.py プロジェクト: cloudera/ibis
    def __init__(self, validator, default=_undefined, show=True):
        """Argument constructor

        Parameters
        ----------
        validator : Union[Callable[[arg], coerced], Type, Tuple[Type]]
            Function which handles validation and/or coercion of the given
            argument.
        default : Union[Any, Callable[[], str]]
            In case of missing (None) value for validation this will be used.
            Note, that default value (except for None) must also pass the inner
            validator.
            If callable is passed, it will be executed just before the inner,
            and itsreturn value will be treaded as default.
        show : bool
            Whether to show this argument in an :class:`~ibis.expr.types.Expr`
            that contains it.
        """
        self.default = default
        self.show = show
        if isinstance(validator, type):
            self.validator = rlz.instance_of(validator)
        elif isinstance(validator, tuple):
            assert util.all_of(validator, type)
            self.validator = rlz.instance_of(validator)
        elif callable(validator):
            self.validator = validator
        else:
            raise TypeError(
                'Argument validator must be a callable, type or '
                'tuple of types, given: {}'.format(validator)
            )
コード例 #2
0
ファイル: compiler.py プロジェクト: wangxiong2015/ibis
    def _walk_join_tree(self, op):
        left = op.left.op()
        right = op.right.op()

        if util.all_of([left, right], ops.Join):
            raise NotImplementedError('Do not support joins between '
                                      'joins yet')

        self._validate_join_predicates(op.predicates)

        jname = self._get_join_type(op)

        # Read off tables and join predicates left-to-right in
        # depth-first order
        if isinstance(left, ops.Join):
            self._walk_join_tree(left)
            self.join_tables.append(self._format_table(op.right))
            self.join_types.append(jname)
            self.join_predicates.append(op.predicates)
        elif isinstance(right, ops.Join):
            # When rewrites are possible at the expression IR stage, we should
            # do them. Otherwise subqueries might be necessary in some cases
            # here
            raise NotImplementedError('not allowing joins on right '
                                      'side yet')
        else:
            # Both tables
            self.join_tables.append(self._format_table(op.left))
            self.join_tables.append(self._format_table(op.right))
            self.join_types.append(jname)
            self.join_predicates.append(op.predicates)
コード例 #3
0
ファイル: compiler.py プロジェクト: hyunsik/ibis
    def _walk_join_tree(self, op):
        left = op.left.op()
        right = op.right.op()

        if util.all_of([left, right], ops.Join):
            raise NotImplementedError('Do not support joins between '
                                      'joins yet')

        self._validate_join_predicates(op.predicates)

        jname = self._get_join_type(op)

        # Read off tables and join predicates left-to-right in
        # depth-first order
        if isinstance(left, ops.Join):
            self._walk_join_tree(left)
            self.join_tables.append(self._format_table(op.right))
            self.join_types.append(jname)
            self.join_predicates.append(op.predicates)
        elif isinstance(right, ops.Join):
            # When rewrites are possible at the expression IR stage, we should
            # do them. Otherwise subqueries might be necessary in some cases
            # here
            raise NotImplementedError('not allowing joins on right '
                                      'side yet')
        else:
            # Both tables
            self.join_tables.append(self._format_table(op.left))
            self.join_tables.append(self._format_table(op.right))
            self.join_types.append(jname)
            self.join_predicates.append(op.predicates)
コード例 #4
0
ファイル: signature.py プロジェクト: ibis-project/ibis
def Argument(validator, default=EMPTY):
    """Argument constructor
    Parameters
    ----------
    validator : Union[Callable[[arg], coerced], Type, Tuple[Type]]
        Function which handles validation and/or coercion of the given
        argument.
    default : Union[Any, Callable[[], str]]
        In case of missing (None) value for validation this will be used.
        Note, that default value (except for None) must also pass the inner
        validator.
        If callable is passed, it will be executed just before the inner,
        and itsreturn value will be treaded as default.
    """
    if isinstance(validator, Validator):
        pass
    elif isinstance(validator, type):
        validator = _InstanceOf(validator)
    elif isinstance(validator, tuple):
        assert all_of(validator, type)
        validator = _InstanceOf(validator)
    elif isinstance(validator, Validator):
        validator = validator
    elif callable(validator):
        validator = _ValidatorFunction(validator)
    else:
        raise TypeError(
            'Argument validator must be a callable, type or '
            'tuple of types, given: {}'.format(validator)
        )

    if default is EMPTY:
        return validator
    else:
        return Optional(validator, default=default)
コード例 #5
0
    def __init__(self, validator, default=_undefined, show=True):
        """Argument constructor

        Parameters
        ----------
        validator : Union[Callable[[arg], coerced], Type, Tuple[Type]]
            Function which handles validation and/or coercion of the given
            argument.
        default : Union[Any, Callable[[], str]]
            In case of missing (None) value for validation this will be used.
            Note, that default value (except for None) must also pass the inner
            validator.
            If callable is passed, it will be executed just before the inner,
            and itsreturn value will be treaded as default.
        show : bool
            Whether to show this argument in an :class:`~ibis.expr.types.Expr`
            that contains it.
        """
        self.default = default
        self.show = show
        if isinstance(validator, type):
            self.validator = rlz.instance_of(validator)
        elif isinstance(validator, tuple):
            assert util.all_of(validator, type)
            self.validator = rlz.instance_of(validator)
        elif callable(validator):
            self.validator = validator
        else:
            raise TypeError('Argument validator must be a callable, type or '
                            'tuple of types, given: {}'.format(validator))
コード例 #6
0
ファイル: util.py プロジェクト: wangxiong2015/ibis
def assert_equal(left, right):
    if util.all_of([left, right], Schema):
        assert left.equals(right),\
            'Comparing schemas: \n%s !=\n%s' % (repr(left), repr(right))
    else:
        assert left.equals(right), ('Objects unequal: {0}\nvs\n{1}'.format(
            repr(left), repr(right)))
コード例 #7
0
ファイル: util.py プロジェクト: zuxfoucault/ibis
def assert_equal(left, right):
    if util.all_of([left, right], Schema):
        assert left.equals(right),\
            'Comparing schemas: \n%s !=\n%s' % (repr(left), repr(right))
    else:
        assert left.equals(right), ('Objects unequal: {0}\nvs\n{1}'
                                    .format(repr(left), repr(right)))
コード例 #8
0
ファイル: operations.py プロジェクト: nataliaking/ibis
 def root_tables(self):
     if util.all_of([self.left.op(), self.right.op()],
                    (Join, Projection)):
         # Unraveling is not possible
         return [self.left.op(), self.right.op()]
     else:
         return ir.distinct_roots(self.left, self.right)
コード例 #9
0
    def _walk_join_tree(self, op):
        left = op.left.op()
        right = op.right.op()

        if util.all_of([left, right], ops.Join):
            raise NotImplementedError('Do not support joins between '
                                      'joins yet')

        self._validate_join_predicates(op.predicates)

        jname = self._get_join_type(op)

        # Read off tables and join predicates left-to-right in
        # depth-first order
        if isinstance(left, ops.Join):
            self._walk_join_tree(left)
            self.join_tables.append(self._format_table(op.right))
        elif isinstance(right, ops.Join):
            self.join_tables.append(self._format_table(op.left))
            self._walk_join_tree(right)
        else:
            # Both tables
            self.join_tables.append(self._format_table(op.left))
            self.join_tables.append(self._format_table(op.right))

        self.join_types.append(jname)
        self.join_predicates.append(op.predicates)
コード例 #10
0
    def output_dtype(self):
        args = getattr(self, name)
        if util.all_of(args, ir.IntegerValue):
            result = _promote_numeric_binop(args, op)
        else:
            result = highest_precedence_dtype(args)

        return result
コード例 #11
0
ファイル: alchemy.py プロジェクト: reshma-katkar/ibis
def _true_divide(t, expr):
    op = expr.op()
    left, right = args = op.args

    if util.all_of(args, ir.IntegerValue):
        return t.translate(left.div(right.cast('double')))

    return fixed_arity(lambda x, y: x / y, 2)(t, expr)
コード例 #12
0
ファイル: alchemy.py プロジェクト: obswork/ibis
def _true_divide(t, expr):
    op = expr.op()
    left, right = op.args

    if util.all_of(op.args, ir.IntegerValue):
        new_expr = left.div(right.cast('double'))
        return t.translate(new_expr)

    return fixed_arity(lambda x, y: x / y, 2)(t, expr)
コード例 #13
0
ファイル: util.py プロジェクト: ibis-project/ibis
def assert_equal(left, right):
    """Assert that two ibis objects are equal."""

    if util.all_of([left, right], ibis.Schema):
        assert left.equals(right), 'Comparing schemas: \n{!r} !=\n{!r}'.format(
            left, right)
    else:
        assert left.equals(right), 'Objects unequal: \n{}\nvs\n{}'.format(
            repr(left), repr(right))
コード例 #14
0
ファイル: rules.py プロジェクト: chris-b1/ibis
 def _get_type(self):
     if util.any_of(self.args, ir.FloatingValue):
         if util.any_of(self.args, ir.DoubleValue):
             return 'double'
         else:
             return 'float'
     elif util.all_of(self.args, ir.IntegerValue):
         return self._get_int_type()
     elif util.any_of(self.args, ir.DecimalValue):
         return _decimal_promoted_type(self.args)
     else:
         raise NotImplementedError
コード例 #15
0
ファイル: rules.py プロジェクト: zuxfoucault/ibis
 def _get_type(self):
     if util.any_of(self.args, ir.FloatingValue):
         if util.any_of(self.args, ir.DoubleValue):
             return 'double'
         else:
             return 'float'
     elif util.all_of(self.args, ir.IntegerValue):
         return self._get_int_type()
     elif util.any_of(self.args, ir.DecimalValue):
         return _decimal_promoted_type(self.args)
     else:
         raise NotImplementedError
コード例 #16
0
 def _get_type(self):
     if util.any_of(self.args, ir.FloatingValue):
         if util.any_of(self.args, ir.DoubleValue):
             return 'double'
         else:
             return 'float'
     elif util.any_of(self.args, ir.DecimalValue):
         return _decimal_promoted_type(self.args)
     elif util.all_of(self.args, ir.IntegerValue):
         return 'double'
     else:
         raise NotImplementedError(
             'Operands {}, {} not supported for binary operation {}'.format(
                 type(self.left).__name__,
                 type(self.right).__name__, self.op.__name__))
コード例 #17
0
ファイル: rules.py プロジェクト: cpcloud/ibis
    def _get_int_type(self):
        deps = [x.op() for x in self.args]

        if util.all_of(deps, ir.Literal):
            return _smallest_int_containing([self.op(deps[0].value, deps[1].value)])
        elif util.any_of(deps, ir.Literal):
            if isinstance(deps[0], ir.Literal):
                val = deps[0].value
                atype = self.args[1].type()
            else:
                val = deps[1].value
                atype = self.args[0].type()
            return _int_one_literal_promotion(atype, val, self.op)
        else:
            return _int_bounds_promotion(self.left.type(), self.right.type(), self.op)
コード例 #18
0
ファイル: rules.py プロジェクト: zuxfoucault/ibis
    def _get_type(self):
        rval = self.args[1].op()

        if util.any_of(self.args, ir.FloatingValue):
            if util.any_of(self.args, ir.DoubleValue):
                return 'double'
            else:
                return 'float'
        elif util.any_of(self.args, ir.DecimalValue):
            return _decimal_promoted_type(self.args)
        elif isinstance(rval, ir.Literal) and rval.value < 0:
            return 'double'
        elif util.all_of(self.args, ir.IntegerValue):
            return self._get_int_type()
        else:
            raise NotImplementedError
コード例 #19
0
ファイル: rules.py プロジェクト: chris-b1/ibis
    def _get_type(self):
        rval = self.args[1].op()

        if util.any_of(self.args, ir.FloatingValue):
            if util.any_of(self.args, ir.DoubleValue):
                return 'double'
            else:
                return 'float'
        elif util.any_of(self.args, ir.DecimalValue):
            return _decimal_promoted_type(self.args)
        elif isinstance(rval, ir.Literal) and rval.value < 0:
            return 'double'
        elif util.all_of(self.args, ir.IntegerValue):
            return self._get_int_type()
        else:
            raise NotImplementedError
コード例 #20
0
ファイル: rules.py プロジェクト: chris-b1/ibis
    def _get_int_type(self):
        deps = [x.op() for x in self.args]

        if util.all_of(deps, ir.Literal):
            return _smallest_int_containing(
                [self.op(deps[0].value, deps[1].value)])
        elif util.any_of(deps, ir.Literal):
            if isinstance(deps[0], ir.Literal):
                val = deps[0].value
                atype = self.args[1].type()
            else:
                val = deps[1].value
                atype = self.args[0].type()
            return _int_one_literal_promotion(atype, val, self.op)
        else:
            return _int_bounds_promotion(self.left.type(), self.right.type(),
                                         self.op)
コード例 #21
0
ファイル: rules.py プロジェクト: chris-b1/ibis
 def _check_compatibility(self):
     if (util.any_of(self.args, ir.StringValue)
             and not util.all_of(self.args, ir.StringValue)):
         raise TypeError('String and non-string incompatible')
コード例 #22
0
ファイル: numeric.py プロジェクト: ibis-project/ibis
 def output_dtype(self):
     if util.all_of(self.args, ir.IntegerValue):
         return dt.float64
     else:
         return rlz.highest_precedence_dtype(self.args)
コード例 #23
0
ファイル: rules.py プロジェクト: cloudera/ibis
def numeric_like(args, op):
    if util.all_of(args, ir.IntegerValue):
        dtype = _promote_numeric_binop(args, op)
        return shape_like(args, dtype=dtype)
    else:
        return shape_like(args)
コード例 #24
0
def numeric_like(args, op):
    if util.all_of(args, ir.IntegerValue):
        dtype = _promote_numeric_binop(args, op)
        return shape_like(args, dtype=dtype)
    else:
        return shape_like(args)
コード例 #25
0
 def root_tables(self):
     if util.all_of([self.left.op(), self.right.op()], (Join, Projection)):
         # Unraveling is not possible
         return [self.left.op(), self.right.op()]
     else:
         return ir.distinct_roots(self.left, self.right)
コード例 #26
0
    def output_type(self):
        if not util.all_of(self.args, ir.NumericValue):
            raise TypeError('One argument was non-numeric')

        return rules.shape_like_args(self.args, 'double')
コード例 #27
0
 def output_type(self):
     if not util.all_of(self.args, ir.BooleanValue):
         raise TypeError('Only valid with boolean data')
     return rules.shape_like_args(self.args, 'boolean')
コード例 #28
0
ファイル: operations.py プロジェクト: nataliaking/ibis
 def output_type(self):
     if not util.all_of(self.args, ir.BooleanValue):
         raise TypeError('Only valid with boolean data')
     return rules.shape_like_args(self.args, 'boolean')
コード例 #29
0
ファイル: operations.py プロジェクト: nataliaking/ibis
    def output_type(self):
        if not util.all_of(self.args, ir.NumericValue):
            raise TypeError('One argument was non-numeric')

        return rules.shape_like_args(self.args, 'double')
コード例 #30
0
ファイル: rules.py プロジェクト: zuxfoucault/ibis
 def _check_compatibility(self):
     if (util.any_of(self.args, ir.StringValue) and
             not util.all_of(self.args, ir.StringValue)):
         raise TypeError('String and non-string incompatible')