<s> from ibis . expr . tests . mocks import MockConnection <EOL> from ibis . compat import unittest <EOL> from ibis . tests . util import assert_equal <EOL> import ibis . expr . operations as ops <EOL> import ibis . expr . types as ir <EOL> import ibis <EOL> class TestBuiltins ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . con = MockConnection ( ) <EOL> self . alltypes = self . con . table ( '<STR_LIT>' ) <EOL> self . lineitem = self . con . table ( '<STR_LIT>' ) <EOL> def test_abs ( self ) : <EOL> colnames = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> fname = '<STR_LIT>' <EOL> op = ops . Abs <EOL> for col in colnames : <EOL> expr = self . alltypes [ col ] <EOL> self . _check_unary_op ( expr , fname , op , type ( expr ) ) <EOL> expr = self . lineitem . l_extendedprice <EOL> self . _check_unary_op ( expr , fname , op , type ( expr ) ) <EOL> def test_group_concat ( self ) : <EOL> col = self . alltypes . string_col <EOL> expr = col . group_concat ( ) <EOL> assert isinstance ( expr . op ( ) , ops . GroupConcat ) <EOL> arg , sep = expr . op ( ) . args <EOL> assert sep == '<STR_LIT:U+002C>' <EOL> expr = col . group_concat ( '<STR_LIT:|>' ) <EOL> arg , sep = expr . op ( ) . args <EOL> assert sep == '<STR_LIT:|>' <EOL> def test_zeroifnull ( self ) : <EOL> dresult = self . alltypes . double_col . zeroifnull ( ) <EOL> iresult = self . alltypes . int_col . zeroifnull ( ) <EOL> assert type ( dresult . op ( ) ) == ops . ZeroIfNull <EOL> assert type ( dresult ) == ir . DoubleArray <EOL> assert type ( iresult ) == type ( iresult ) <EOL> def test_fillna ( self ) : <EOL> result = self . alltypes . double_col . fillna ( <NUM_LIT:5> ) <EOL> assert isinstance ( result , ir . DoubleArray ) <EOL> assert isinstance ( result . op ( ) , ops . IfNull ) <EOL> result = self . alltypes . bool_col . fillna ( True ) <EOL> assert isinstance ( result , ir . BooleanArray ) <EOL> result = self . alltypes . int_col . fillna ( self . alltypes . bigint_col ) <EOL> assert isinstance ( result , ir . Int32Array ) <EOL> def test_ceil_floor ( self ) : <EOL> cresult = self . alltypes . double_col . ceil ( ) <EOL> fresult = self . alltypes . double_col . floor ( ) <EOL> assert isinstance ( cresult , ir . Int64Array ) <EOL> assert isinstance ( fresult , ir . Int64Array ) <EOL> assert type ( cresult . op ( ) ) == ops . Ceil <EOL> assert type ( fresult . op ( ) ) == ops . Floor <EOL> cresult = ibis . literal ( <NUM_LIT> ) . ceil ( ) <EOL> fresult = ibis . literal ( <NUM_LIT> ) . floor ( ) <EOL> assert isinstance ( cresult , ir . Int64Scalar ) <EOL> assert isinstance ( fresult , ir . Int64Scalar ) <EOL> dec_col = self . lineitem . l_extendedprice <EOL> cresult = dec_col . ceil ( ) <EOL> fresult = dec_col . floor ( ) <EOL> assert isinstance ( cresult , ir . DecimalArray ) <EOL> assert cresult . meta == dec_col . meta <EOL> assert isinstance ( fresult , ir . DecimalArray ) <EOL> assert fresult . meta == dec_col . meta <EOL> def test_sign ( self ) : <EOL> result = self . alltypes . double_col . sign ( ) <EOL> assert isinstance ( result , ir . FloatArray ) <EOL> assert type ( result . op ( ) ) == ops . Sign <EOL> result = ibis . literal ( <NUM_LIT> ) . sign ( ) <EOL> assert isinstance ( result , ir . FloatScalar ) <EOL> dec_col = self . lineitem . l_extendedprice <EOL> result = dec_col . sign ( ) <EOL> assert isinstance ( result , ir . FloatArray ) <EOL> def test_round ( self ) : <EOL> result = self . alltypes . double_col . round ( ) <EOL> assert isinstance ( result , ir . Int64Array ) <EOL> assert result . op ( ) . args [ <NUM_LIT:1> ] is None <EOL> result = self . alltypes . double_col . round ( <NUM_LIT:2> ) <EOL> assert isinstance ( result , ir . DoubleArray ) <EOL> assert result . op ( ) . args [ <NUM_LIT:1> ] == <NUM_LIT:2> <EOL> result = self . alltypes . int_col . round ( <NUM_LIT:2> ) <EOL> assert isinstance ( result , ir . DoubleArray ) <EOL> dec = self . lineitem . l_extendedprice <EOL> result = dec . round ( ) <EOL> assert isinstance ( result , ir . DecimalArray ) <EOL> result = dec . round ( <NUM_LIT:2> ) <EOL> assert isinstance ( result , ir . DecimalArray ) <EOL> result = ibis . literal ( <NUM_LIT> ) . round ( ) <EOL> assert isinstance ( result , ir . Int64Scalar ) <EOL> def _check_unary_op ( self , expr , fname , ex_op , ex_type ) : <EOL> result = getattr ( expr , fname ) ( ) <EOL> assert type ( result . op ( ) ) == ex_op <EOL> assert type ( result ) == ex_type <EOL> class TestCoalesceLikeFunctions ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . table = ibis . table ( [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:float>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:string>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ] , '<STR_LIT>' ) <EOL> self . functions = [ ibis . coalesce , ibis . greatest , ibis . least ] <EOL> def test_coalesce_instance_method ( self ) : <EOL> v7 = self . table . v7 <EOL> v5 = self . table . v5 . cast ( '<STR_LIT:string>' ) <EOL> v8 = self . table . v8 . cast ( '<STR_LIT:string>' ) <EOL> result = v7 . coalesce ( v5 , v8 , '<STR_LIT:foo>' ) <EOL> expected = ibis . coalesce ( v7 , v5 , v8 , '<STR_LIT:foo>' ) <EOL> assert_equal ( result , expected ) <EOL> def test_integer_promotions ( self ) : <EOL> t = self . table <EOL> for f in self . functions : <EOL> expr = f ( t . v3 , t . v4 ) <EOL> assert isinstance ( expr , ir . Int64Array ) <EOL> expr = f ( <NUM_LIT:5> , t . v3 ) <EOL> assert isinstance ( expr , ir . Int64Array ) <EOL> expr = f ( <NUM_LIT:5> , <NUM_LIT:12> ) <EOL> assert isinstance ( expr , ir . Int64Scalar ) <EOL> def test_floats ( self ) : <EOL> t = self . table <EOL> for f in self . functions : <EOL> expr = f ( t . v5 ) <EOL> assert isinstance ( expr , ir . DoubleArray ) <EOL> expr = f ( <NUM_LIT> , t . v5 ) <EOL> assert isinstance ( expr , ir . DoubleArray ) <EOL> expr = f ( <NUM_LIT> , <NUM_LIT:5> ) <EOL> assert isinstance ( expr , ir . DoubleScalar ) <EOL> def test_bools ( self ) : <EOL> pass <EOL> def test_decimal_promotions ( self ) : <EOL> pass </s>
