def test_arithmetic_of_val(es): to_test = [(Add, [2.0, 7.0, 12.0, 17.0], [2.0, 7.0, 12.0, 17.0]), (Subtract, [-2.0, 3.0, 8.0, 13.0], [2.0, -3.0, -8.0, -13.0]), (Multiply, [0, 10, 20, 30], [0, 10, 20, 30]), (Divide, [0, 2.5, 5, 7.5], [np.inf, 0.4, 0.2, 2 / 15.0], [np.nan, np.inf, np.inf, np.inf])] features = [] logs = es['log'] for test in to_test: features.append(test[0](logs['value'], 2)) features.append(test[0](2, logs['value'])) features.append(Divide(logs['value'], 0)) pandas_backend = PandasBackend(es, features) df = pandas_backend.calculate_all_features(instance_ids=[0, 1, 2, 3], time_last=None) for i, test in enumerate(to_test): v = df[features[2 * i].get_name()].values.tolist() assert v == test[1] v = df[features[2 * i + 1].get_name()].values.tolist() assert v == test[2] test = to_test[-1][-1] v = df[features[-1].get_name()].values.tolist() assert (np.isnan(v[0])) assert v[1:] == test[1:]
def __div__(self, other_feature_or_val): """Divide by other_feature_or_val See also: :meth:`PrimitiveBase.divide` """ from featuretools.primitives import Divide return Divide(self, other_feature_or_val)
def __rdiv__(self, other_feature_or_val): from featuretools.primitives import Divide return Divide(other_feature_or_val, self)