Skip to content

Create LambdaTransform #762

@Mr-Geekman

Description

@Mr-Geekman

🚀 Feature Request

The idea is to create a transform with custom transformation/inverse transformation.

Motivation

It can help users to write less boilerplate code for custom transforms.

Proposal

class LambdaTransform(Transform):

    def __init__(self, in_column, inplace, out_column, transform_func, inverse_transform_func):
        pass

Constructor parameters:

  • in_column: name of column to transform
  • inplace: should transform be applied inplace or create a new column
  • out_column: name of column to create if inplace=False
  • transform_func: function that takes wide dataframe with selected in_column and transforms it so the shape and columns remains the same. It can be
    • some function on dataframe itself
    • calling apply with any user-defined function in lambda
    • type: Callable[[pd.DataFrame], pd.DataFrame]
  • inverse_transform_func: is necessary if inplace=True, signature is the same as signature of transform_func

Reference transforms (multi-segment):

  • LagTransform
  • AddConstTransform
  • LogTransform

After creation of this transform some existing transforms can be rewritten using it. We can inherit them from LambdaTransform and set transform_func, inverse_transform_func to some methods of the class.

  • LagTransform -- add some checks during the init an
  • AddConstTransform
  • LogTransform -- add some checks during the transform

Test cases

  1. Make sure that rewritten transforms pass the tests.
  2. Test that if inplace=True inverse_transform_func is necessary.
  3. Test interface if inplace=True.
  4. Test interface if inplace=False: column name should be generated by out_column if it is present.
  5. Test transform method for some function examples.
  6. Test inverse_transform for some function examples in inplace=True and inplace=False.

Alternatives

No response

Additional context

No response

Checklist

  • I discussed this issue with ETNA Team

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions