featuretools.primitives.make_trans_primitive(function, input_types, return_type, name=None, description=None, cls_attributes=None, uses_calc_time=False, commutative=False, number_output_features=1)[source]

Returns a new transform primitive class

  • function (function) – Function that takes in a series and applies some transformation to it.

  • input_types (list[ColumnSchema]) – ColumnSchema of the inputs.

  • return_type (ColumnSchema) – ColumnSchema of returned feature.

  • name (str) – Name of the primitive. If no name is provided, the name of function will be used.

  • description (str) – Description of primitive.

  • cls_attributes (dict[str -> anytype]) – Custom attributes to be added to class. Key is attribute name, value is the attribute value.

  • uses_calc_time (bool) – If True, the cutoff time the feature is being calculated at will be passed to the function as the keyword argument ‘time’.

  • commutative (bool) – If True, will only make one feature per unique set of base features.

  • number_output_features (int) – The number of output features (columns in the matrix) associated with this feature.


In [1]: from featuretools.primitives import make_trans_primitive

In [2]: from woodwork.column_schema import ColumnSchema

In [3]: from woodwork.logical_types import Boolean

In [4]: def pd_is_in(array, list_of_outputs=None):
   ...:     if list_of_outputs is None:
   ...:         list_of_outputs = []
   ...:     return pd.Series(array).isin(list_of_outputs)

In [5]: def isin_generate_name(self):
   ...:     return u"%s.isin(%s)" % (self.base_features[0].get_name(),
   ...:                              str(self.kwargs['list_of_outputs']))

In [6]: IsIn = make_trans_primitive(
   ...:     function=pd_is_in,
   ...:     input_types=[ColumnSchema()],
   ...:     return_type=ColumnSchema(logical_type=Boolean),
   ...:     name="is_in",
   ...:     description="For each value of the base feature, checks "
   ...:     "whether it is in a list that provided.",
   ...:     cls_attributes={"generate_name": isin_generate_name})