def test_compare_of_transform(es): day = Day(es['log']['datetime']) to_test = [(Equals, [False, True]), (NotEquals, [True, False]), (LessThan, [True, False]), (LessThanEqualTo, [True, True]), (GreaterThan, [False, False]), (GreaterThanEqualTo, [False, True])] features = [] for test in to_test: features.append(test[0](day, 10)) pandas_backend = PandasBackend(es, features) df = pandas_backend.calculate_all_features(instance_ids=[0, 14], time_last=None) for i, test in enumerate(to_test): v = df[features[i].get_name()].values.tolist() assert v == test[1]
def test_arithmetic(es): # P TODO: return hour = Hour(es['log']['datetime']) day = Day(es['log']['datetime']) to_test = [(Add, [19, 19, 19, 19]), (Subtract, [-1, -1, -1, -1]), (Multiply, [90, 90, 90, 90]), (Divide, [.9, .9, .9, .9])] features = [] features.append(day + hour) features.append(day - hour) features.append(day * hour) features.append(day / hour) pandas_backend = PandasBackend(es, features) df = pandas_backend.calculate_all_features(instance_ids=[0, 3, 5, 7], time_last=None) for i, test in enumerate(to_test): v = df[features[i].get_name()].values.tolist() assert v == test[1]
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