def test_or_and_not(): assert c.or_(None, 0).gen_converter()(100) == 0 assert c.and_(None, 0).gen_converter()(100) is None assert c.not_(True).gen_converter()(100) is False assert (~c.this).gen_converter()(True) is False assert c.naive(None).not_().execute(100) is True with pytest.raises(ValueError): c.or_()
def test_naive_conversion_or_and(): assert c.naive(False).or_(c.naive(False)).gen_converter()(100) is False assert (c.naive(False) | c.naive(False)).gen_converter()(100) is False assert c.naive(0).or_(c.naive(10)).gen_converter()(100) == 10 assert c.naive(10).and_(c.naive(0)).gen_converter()(100) == 0 assert (c.naive(10) & c.naive(0)).gen_converter()(100) == 0 assert (c.this.and_(1).and_(2).execute(1) == c.and_(c.this, 1, 2).execute(1) == 2) assert (c.this.or_(1).or_(2).execute(1) == c.or_(c.this, 1, 2).execute(1) == 1) assert (c.this.and_(1).and_(2).or_(3).execute(1) == c.and_( c.this, 1, 2).or_(3).execute(1) == 2)
def test_reducer_reuse(dict_series): f = lambda a, b: a + b reducer = c.reduce(f, c.item("value"), initial=0) reducer2 = c.reduce(f, c.item("value"), initial=0, where=c.or_(default=True)) output = (c.group_by(c.item("name")).aggregate(( c.item("name"), reducer + 10, reducer2 + 20, )).execute(dict_series)) assert output == [ ("Nick", 13, 23), ("John", 73, 83), ]
def test_join_conditions(): join_conditions = _JoinConditions.from_condition(c.LEFT == c.RIGHT) assert (True and join_conditions.inner_loop_conditions == [] and join_conditions.left_collection_filters == [] and join_conditions.left_row_filters == [] and join_conditions.left_row_hashers == [c.LEFT] and join_conditions.pre_filter == [] and join_conditions.right_collection_filters == [] and join_conditions.right_row_filters == [] and join_conditions.right_row_hashers == [c.RIGHT]) join_conditions = _JoinConditions.from_condition( c.or_(c.LEFT == c.RIGHT, c.LEFT == c.RIGHT)) c11 = c.LEFT.item(0) c12 = c.RIGHT.item(1) c21 = c.LEFT.item(1) c22 = c.RIGHT.item(0) c13 = c.LEFT.item(2) > 10 c23 = c.RIGHT.item(2) < 10 c01 = c.input_arg("x") > 100 join_conditions = _JoinConditions.from_condition( c.and_(c11 == c12, c22 == c21, c13).and_(c23, c01)) assert (True and join_conditions.inner_loop_conditions == [] and join_conditions.left_collection_filters == [c13] and join_conditions.left_row_filters == [] and join_conditions.left_row_hashers == [c11, c21] and join_conditions.pre_filter == [c01] and join_conditions.right_collection_filters == [c23] and join_conditions.right_row_filters == [] and join_conditions.right_row_hashers == [c12, c22]) join_conditions = _JoinConditions.from_condition(c.and_( c11 == c12, c22 == c21, c13).and_(c23, c01), how="left") assert (True and join_conditions.inner_loop_conditions == [] and join_conditions.left_collection_filters == [] and join_conditions.left_row_filters == [c13] and join_conditions.left_row_hashers == [c11, c21] and join_conditions.pre_filter == [c01] and join_conditions.right_collection_filters == [c23] and join_conditions.right_row_filters == [] and join_conditions.right_row_hashers == [c12, c22]) join_conditions = _JoinConditions.from_condition(c.and_( c11 == c12, c22 == c21, c13).and_(c23, c01), how="right") assert (True and join_conditions.inner_loop_conditions == [] and join_conditions.left_collection_filters == [c13] and join_conditions.left_row_filters == [] and join_conditions.left_row_hashers == [c11, c21] and join_conditions.pre_filter == [c01] and join_conditions.right_collection_filters == [] and join_conditions.right_row_filters == [c23] and join_conditions.right_row_hashers == [c12, c22]) join_conditions = _JoinConditions.from_condition(c.and_( c11 == c12, c22 == c21, c13).and_(c23, c01), how="outer") assert (True and join_conditions.inner_loop_conditions == [] and join_conditions.left_collection_filters == [] and join_conditions.left_row_filters == [c13] and join_conditions.left_row_hashers == [c11, c21] and join_conditions.pre_filter == [c01] and join_conditions.right_collection_filters == [] and join_conditions.right_row_filters == [c23] and join_conditions.right_row_hashers == [c12, c22]) with pytest.raises(AssertionError): _JoinConditions.from_condition(c.and_(True, False), how="abc") c1 = c.LEFT != c.RIGHT join_conditions = _JoinConditions.from_condition(c1) assert (True and join_conditions.inner_loop_conditions == [c1] and join_conditions.left_collection_filters == [] and join_conditions.left_row_filters == [] and join_conditions.left_row_hashers == [] and join_conditions.pre_filter == [] and join_conditions.right_collection_filters == [] and join_conditions.right_row_filters == [] and join_conditions.right_row_hashers == []) cond = c.LEFT > c.RIGHT join_conditions = _JoinConditions.from_condition(cond) assert (True and join_conditions.inner_loop_conditions == [cond] and join_conditions.left_collection_filters == [] and join_conditions.left_row_filters == [] and join_conditions.left_row_hashers == [] and join_conditions.pre_filter == [] and join_conditions.right_collection_filters == [] and join_conditions.right_row_filters == [] and join_conditions.right_row_hashers == []) c1 = c.LEFT == 1 c2 = c.RIGHT == 1 c3 = c.input_arg("x") == 1 join_conditions = _JoinConditions.from_condition(c1.and_(c2, c3), how="outer") assert (True and join_conditions.inner_loop_conditions == [] and join_conditions.left_collection_filters == [] and join_conditions.left_row_filters == [c1] and join_conditions.left_row_hashers == [] and join_conditions.pre_filter == [c3] and join_conditions.right_collection_filters == [] and join_conditions.right_row_filters == [c2] and join_conditions.right_row_hashers == []) c1 = c.LEFT + c.RIGHT + 10 c2 = c.LEFT + 1 c3 = c.RIGHT + 1 join_conditions = _JoinConditions.from_condition(c.and_(c1, c2, c3)) assert (True and join_conditions.inner_loop_conditions == [c1] and join_conditions.left_collection_filters == [c2] and join_conditions.left_row_filters == [] and join_conditions.left_row_hashers == [] and join_conditions.pre_filter == [] and join_conditions.right_collection_filters == [c3] and join_conditions.right_row_filters == [] and join_conditions.right_row_hashers == [])
def test_or_and_not(): assert c.or_(None, 0).gen_converter()(100) == 0 assert c.and_(None, 0).gen_converter()(100) is None assert c.not_(True).gen_converter()(100) is False assert (~c.this()).gen_converter()(True) is False assert c.naive(None).not_().execute(100) is True