def output_type(self): arg, digits = self.args if isinstance(arg, ir.DecimalValue): return arg._factory elif digits is None: return rules.shape_like(arg, 'int64') else: return rules.shape_like(arg, 'double')
def _ceil_floor_output(self): arg = self.args[0] if isinstance(arg, ir.DecimalValue): return arg._factory else: return rules.shape_like(arg, 'int32')
def output_type(self): return rules.shape_like(self.args[0], self.args[1].type())
def output_type(self): # TODO: error handling for invalid casts return rules.shape_like(self.args[0], self.args[1])
def test_shape_like_with_no_arguments(): with pytest.raises(ValueError) as e: rlz.shape_like([]) assert str(e.value) == 'Must pass at least one expression'
def output_type(self): base, cases, results, default = self.args out_exprs = results + [default] typename = rules.highest_precedence_type(out_exprs) return rules.shape_like(base, typename)
def output_type(self): return rules.shape_like(self.arg, 'string')
def _type_signature(self): input_type = _ibis_signature(self.inputs) output_type = rlz.shape_like('args', dt.dtype(self.output)) return input_type, output_type
def wrapper(f): if not callable(f): raise TypeError('f must be callable, got {}'.format(f)) signature = inspect.signature(f) parameter_names = signature.parameters.keys() udf_node_fields = collections.OrderedDict( [(name, Arg(rlz.value(type))) for name, type in zip(parameter_names, input_type)] + [ ( 'output_type', lambda self, output_type=output_type: rlz.shape_like( self.args, dtype=output_type), ), ('__slots__', ('js', )), ]) udf_node = create_udf_node(f.__name__, udf_node_fields) @compiles(udf_node) def compiles_udf_node(t, expr): return '{}({})'.format(udf_node.__name__, ', '.join(map(t.translate, expr.op().args))) type_translation_context = UDFContext() return_type = ibis_type_to_bigquery_type(dt.dtype(output_type), type_translation_context) bigquery_signature = ', '.join('{name} {type}'.format( name=name, type=ibis_type_to_bigquery_type(dt.dtype(type), type_translation_context), ) for name, type in zip(parameter_names, input_type)) source = PythonToJavaScriptTranslator(f).compile() js = '''\ CREATE TEMPORARY FUNCTION {external_name}({signature}) RETURNS {return_type} LANGUAGE js AS """ {strict}{source} return {internal_name}({args}); """{libraries};'''.format( external_name=udf_node.__name__, internal_name=f.__name__, return_type=return_type, source=source, signature=bigquery_signature, strict=repr('use strict') + ';\n' if strict else '', args=', '.join(parameter_names), libraries=('\nOPTIONS (\n library={}\n)'.format( repr(list(libraries))) if libraries else ''), ) @functools.wraps(f) def wrapped(*args, **kwargs): node = udf_node(*args, **kwargs) node.js = js return node.to_expr() wrapped.__signature__ = signature wrapped.js = js return wrapped
def wrapper(f): if not callable(f): raise TypeError('f must be callable, got {}'.format(f)) signature = inspect.signature(f) parameter_names = signature.parameters.keys() udf_node_fields = collections.OrderedDict( [ (name, Arg(rlz.value(type))) for name, type in zip(parameter_names, input_type) ] + [ ( 'output_type', lambda self, output_type=output_type: rlz.shape_like( self.args, dtype=output_type ), ), ('__slots__', ('js',)), ] ) udf_node = create_udf_node(f.__name__, udf_node_fields) @compiles(udf_node) def compiles_udf_node(t, expr): return '{}({})'.format( udf_node.__name__, ', '.join(map(t.translate, expr.op().args)) ) type_translation_context = UDFContext() return_type = ibis_type_to_bigquery_type( dt.dtype(output_type), type_translation_context ) bigquery_signature = ', '.join( '{name} {type}'.format( name=name, type=ibis_type_to_bigquery_type( dt.dtype(type), type_translation_context ), ) for name, type in zip(parameter_names, input_type) ) source = PythonToJavaScriptTranslator(f).compile() js = '''\ CREATE TEMPORARY FUNCTION {external_name}({signature}) RETURNS {return_type} LANGUAGE js AS """ {strict}{source} return {internal_name}({args}); """{libraries};'''.format( external_name=udf_node.__name__, internal_name=f.__name__, return_type=return_type, source=source, signature=bigquery_signature, strict=repr('use strict') + ';\n' if strict else '', args=', '.join(parameter_names), libraries=( '\nOPTIONS (\n library={}\n)'.format(repr(list(libraries))) if libraries else '' ), ) @functools.wraps(f) def wrapped(*args, **kwargs): node = udf_node(*args, **kwargs) node.js = js return node.to_expr() wrapped.__signature__ = signature wrapped.js = js return wrapped