<s> from blaze . expr . optimize import lean_projection , _lean <EOL> from blaze . expr import * <EOL> t = symbol ( '<STR_LIT:t>' , '<STR_LIT>' ) <EOL> def test_lean_on_Symbol ( ) : <EOL> assert _lean ( t , fields = [ '<STR_LIT:x>' ] ) [ <NUM_LIT:0> ] == t [ [ '<STR_LIT:x>' ] ] <EOL> assert _lean ( t , fields = [ '<STR_LIT:x>' , '<STR_LIT:y>' , '<STR_LIT:z>' , '<STR_LIT:w>' ] ) [ <NUM_LIT:0> ] == t <EOL> def test_lean_projection ( ) : <EOL> assert lean_projection ( t [ t . x > <NUM_LIT:0> ] . y ) . _child . _child . isidentical ( t [ [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ] ) <EOL> def test_lean_projection_by ( ) : <EOL> assert lean_projection ( by ( t . x , total = t . y . sum ( ) ) ) . _child . isidentical ( <EOL> t [ [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ] ) <EOL> def test_lean_by_with_summary ( ) : <EOL> assert lean_projection ( by ( t . x , total = t . y . sum ( ) ) ) . _child . isidentical ( <EOL> t [ [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ] ) <EOL> tt = t [ [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ] <EOL> result = lean_projection ( by ( t . x , a = t . y . sum ( ) , b = t . z . sum ( ) ) [ [ '<STR_LIT:x>' , '<STR_LIT:a>' ] ] ) <EOL> expected = Projection ( <EOL> By ( Field ( tt , '<STR_LIT:x>' ) , summary ( a = sum ( Field ( tt , '<STR_LIT:y>' ) ) ) ) , <EOL> ( '<STR_LIT:x>' , '<STR_LIT:a>' ) ) <EOL> assert result . isidentical ( expected ) <EOL> def test_summary ( ) : <EOL> expr , fields = _lean ( summary ( a = t . x . sum ( ) , b = t . y . sum ( ) ) , fields = [ '<STR_LIT:a>' ] ) <EOL> assert expr . isidentical ( summary ( a = t . x . sum ( ) ) ) <EOL> assert fields == set ( [ '<STR_LIT:x>' ] ) <EOL> def test_sort ( ) : <EOL> assert lean_projection ( t . sort ( '<STR_LIT:x>' ) . y ) . isidentical ( t [ [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ] . sort ( '<STR_LIT:x>' ) . y ) <EOL> def test_merge ( ) : <EOL> expr = lean_projection ( merge ( a = t . x + <NUM_LIT:1> , y = t . y ) ) <EOL> assert expr . _child . isidentical ( t [ [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ] ) <EOL> def test_add ( ) : <EOL> expr = t . x + <NUM_LIT:1> <EOL> expr2 , fields = _lean ( expr , fields = set ( [ '<STR_LIT:x>' ] ) ) <EOL> assert expr2 . isidentical ( expr ) <EOL> assert fields == set ( [ '<STR_LIT:x>' ] ) <EOL> expr = ( t . x + t . y ) . label ( '<STR_LIT:a>' ) <EOL> expr2 , fields = _lean ( expr , fields = set ( [ '<STR_LIT:a>' ] ) ) <EOL> assert expr2 . isidentical ( expr ) <EOL> assert fields == set ( [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ) <EOL> def test_label ( ) : <EOL> expr = t . x . label ( '<STR_LIT:foo>' ) <EOL> expr2 , fields = _lean ( expr , fields = set ( [ '<STR_LIT:foo>' ] ) ) <EOL> assert expr2 . isidentical ( expr ) <EOL> assert fields == set ( [ '<STR_LIT:x>' ] ) <EOL> def test_relabel ( ) : <EOL> expr = t . relabel ( x = '<STR_LIT:X>' , y = '<STR_LIT:Y>' ) <EOL> expr2 , fields = _lean ( expr , fields = set ( [ '<STR_LIT:X>' , '<STR_LIT:z>' ] ) ) <EOL> assert expr2 . isidentical ( t [ [ '<STR_LIT:x>' , '<STR_LIT:z>' ] ] . relabel ( x = '<STR_LIT:X>' ) ) <EOL> assert fields == set ( [ '<STR_LIT:x>' , '<STR_LIT:z>' ] ) <EOL> def test_merge_with_table ( ) : <EOL> expr = lean_projection ( merge ( t , a = t . x + <NUM_LIT:1> ) ) <EOL> assert expr . isidentical ( expr ) <EOL> def test_head ( ) : <EOL> assert lean_projection ( t . sort ( '<STR_LIT:x>' ) . y . head ( <NUM_LIT:5> ) ) . isidentical ( <EOL> t [ [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ] . sort ( '<STR_LIT:x>' ) . y . head ( <NUM_LIT:5> ) ) <EOL> def test_elemwise_thats_also_a_column ( ) : <EOL> t = symbol ( '<STR_LIT:t>' , '<STR_LIT>' ) <EOL> expr = t [ t . x > <NUM_LIT:0> ] . time . truncate ( months = <NUM_LIT:1> ) <EOL> expected = t [ [ '<STR_LIT:time>' , '<STR_LIT:x>' ] ] <EOL> result = lean_projection ( expr ) <EOL> assert result . _child . _child . _child . isidentical ( t [ [ '<STR_LIT:time>' , '<STR_LIT:x>' ] ] ) <EOL> def test_distinct ( ) : <EOL> expr = t . distinct ( ) [ [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ] <EOL> assert lean_projection ( expr ) . isidentical ( expr ) <EOL> def test_like ( ) : <EOL> t = symbol ( '<STR_LIT:t>' , '<STR_LIT>' ) <EOL> expr = t [ t . name . like ( '<STR_LIT>' ) ] . y <EOL> result = lean_projection ( expr ) <EOL> assert result . _child . _child . isidentical ( t [ [ '<STR_LIT:name>' , '<STR_LIT:y>' ] ] ) </s>
