Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
is_agg_primitive = lambda name: issubclass(primitives[name], ft.primitives.AggregationPrimitive)
construct_primitive = lambda name: primitives[name](**parameters.get(name, {}))
def __mul__(self, other):
"""Multiply by other"""
if isinstance(other, FeatureBase):
if self.variable_type == Boolean and other.variable_type == Boolean:
return Feature([self, other], primitive=primitives.MultiplyBoolean)
return self._handle_binary_comparision(other, primitives.MultiplyNumeric, primitives.MultiplyNumericScalar)
def __add__(self, other):
"""Add other"""
return self._handle_binary_comparision(other, primitives.AddNumeric, primitives.AddNumericScalar)
def __div__(self, other):
"""Divide by other"""
return self._handle_binary_comparision(other, primitives.DivideNumeric, primitives.DivideNumericScalar)
def _init_primitive_options(primitive_options, es):
# Flatten all tuple keys, convert value lists into sets, check for
# conflicting keys
flattened_options = {}
for primitive_key, options in primitive_options.items():
if isinstance(options, list):
primitive = primitives.get_aggregation_primitives().get(primitive_key) or \
primitives.get_transform_primitives().get(primitive_key)
assert len(primitive.input_types[0]) == len(options) if \
isinstance(primitive.input_types[0], list) else \
len(primitive.input_types) == len(options), \
"Number of options does not match number of inputs for primitive %s" \
% (primitive_key)
options = [_init_option_dict(primitive_key, option, es) for option in options]
else:
options = [_init_option_dict(primitive_key, options, es)]
if not isinstance(primitive_key, tuple):
primitive_key = (primitive_key,)
for each_primitive in primitive_key:
# if primitive is specified more than once, raise error
if each_primitive in flattened_options:
raise KeyError('Multiple options found for primitive %s' %
(each_primitive))
def __mul__(self, other):
"""Multiply by other"""
if isinstance(other, FeatureBase):
if self.variable_type == Boolean and other.variable_type == Boolean:
return Feature([self, other], primitive=primitives.MultiplyBoolean)
return self._handle_binary_comparision(other, primitives.MultiplyNumeric, primitives.MultiplyNumericScalar)
def get_transform_primitives():
transform_primitives = set([])
for attribute_string in dir(featuretools.primitives):
attribute = getattr(featuretools.primitives, attribute_string)
if isclass(attribute):
if issubclass(attribute,
featuretools.primitives.TransformPrimitive):
if attribute.name:
transform_primitives.add(attribute)
return {prim.name.lower(): prim for prim in transform_primitives}