Ejemplo n.º 1
0
def test_to_dictionary_trans(es):
    primitive = Negate()
    trans_feature = ft.Feature(es["customers"].ww["age"], primitive=primitive)

    expected = {
        "type": "TransformFeature",
        "dependencies": ["customers: age"],
        "arguments": {
            "name": "-(age)",
            "base_features": ["customers: age"],
            "primitive": primitive,
        },
    }

    assert expected == trans_feature.to_dictionary()
Ejemplo n.º 2
0
def test_to_dictionary_groupby_trans(es):
    primitive = Negate()
    id_feat = ft.Feature(es["log"].ww["product_id"])
    groupby_feature = ft.Feature(
        es["log"].ww["value"], primitive=primitive, groupby=id_feat
    )

    expected = {
        "type": "GroupByTransformFeature",
        "dependencies": ["log: value", "log: product_id"],
        "arguments": {
            "name": "-(value) by product_id",
            "base_features": ["log: value"],
            "primitive": primitive,
            "groupby": "log: product_id",
        },
    }

    assert expected == groupby_feature.to_dictionary()
def test_overrides(es):
    # P TODO:
    return
    hour = Hour(es['log']['datetime'])
    day = Day(es['log']['datetime'])

    feats = [Add, Subtract, Multiply, Divide, Mod, And, Or]
    compare_ops = [
        GreaterThan, LessThan, Equals, NotEquals, GreaterThanEqualTo,
        LessThanEqualTo
    ]
    assert Negate(hour).hash() == (-hour).hash()

    compares = [(hour, hour), (hour, day), (day, 2)]
    overrides = [
        hour + hour,
        hour - hour,
        hour * hour,
        hour / hour,
        hour % hour,
        hour & hour,
        hour | hour,
        hour > hour,
        hour < hour,
        hour == hour,
        hour != hour,
        hour >= hour,
        hour <= hour,
        hour + day,
        hour - day,
        hour * day,
        hour / day,
        hour % day,
        hour & day,
        hour | day,
        hour > day,
        hour < day,
        hour == day,
        hour != day,
        hour >= day,
        hour <= day,
        day + 2,
        day - 2,
        day * 2,
        day / 2,
        day % 2,
        day & 2,
        day | 2,
        day > 2,
        day < 2,
        day == 2,
        day != 2,
        day >= 2,
        day <= 2,
    ]

    i = 0
    for left, right in compares:
        for feat in feats:
            f = feat(left, right)
            o = overrides[i]
            assert o.hash() == f.hash()
            i += 1

        for compare_op in compare_ops:
            f = compare_op(left, right)
            o = overrides[i]
            assert o.hash() == f.hash()
            i += 1

    our_reverse_overrides = [
        2 + day, 2 - day, 2 * day, 2 / day, 2 & day, 2 | day
    ]
    i = 0
    for feat in feats:
        if feat != Mod:
            f = feat(2, day)
            o = our_reverse_overrides[i]
            assert o.hash() == f.hash()
            i += 1

    python_reverse_overrides = [
        2 < day, 2 > day, 2 == day, 2 != day, 2 <= day, 2 >= day
    ]
    i = 0
    for compare_op in compare_ops:
        f = compare_op(day, 2)
        o = python_reverse_overrides[i]
        assert o.hash() == f.hash()
        i += 1
Ejemplo n.º 4
0
def test_overrides(es):
    value = Feature(es['log']['value'])
    value2 = Feature(es['log']['value_2'])

    feats = [Add, Subtract, Multiply, Divide]
    compare_ops = [
        GreaterThan, LessThan, Equals, NotEquals, GreaterThanEqualTo,
        LessThanEqualTo
    ]
    assert Negate(value).hash() == (-value).hash()

    compares = [(value, value), (value, value2), (value2, 2)]
    overrides = [
        value + value,
        value - value,
        value * value,
        value / value,
        value > value,
        value < value,
        value == value,
        value != value,
        value >= value,
        value <= value,
        value + value2,
        value - value2,
        value * value2,
        value / value2,
        value > value2,
        value < value2,
        value == value2,
        value != value2,
        value >= value2,
        value <= value2,
        value2 + 2,
        value2 - 2,
        value2 * 2,
        value2 / 2,
        value2 > 2,
        value2 < 2,
        value2 == 2,
        value2 != 2,
        value2 >= 2,
        value2 <= 2,
    ]

    i = 0
    for left, right in compares:
        for feat in feats:
            f = feat(left, right)
            o = overrides[i]
            assert o.hash() == f.hash()
            i += 1

        for compare_op in compare_ops:
            f = compare_op(left, right)
            o = overrides[i]
            assert o.hash() == f.hash()
            i += 1

    our_reverse_overrides = [2 + value2, 2 - value2, 2 * value2, 2 / value2]
    i = 0
    for feat in feats:
        if feat != Mod:
            f = feat(2, value2)
            o = our_reverse_overrides[i]
            assert o.hash() == f.hash()
            i += 1

    python_reverse_overrides = [
        2 < value2, 2 > value2, 2 == value2, 2 != value2, 2 <= value2,
        2 >= value2
    ]
    i = 0
    for compare_op in compare_ops:
        f = compare_op(value2, 2)
        o = python_reverse_overrides[i]
        assert o.hash() == f.hash()
        i += 1
Ejemplo n.º 5
0
 def __neg__(self):
     from featuretools.primitives import Negate
     return Negate(self)