Skip to content

Create LambdaTransform #762

Closed
1 task done
Mr-Geekman opened this issue Jun 20, 2022 · 0 comments · Fixed by #772
Closed
1 task done

Create LambdaTransform #762

Mr-Geekman opened this issue Jun 20, 2022 · 0 comments · Fixed by #772
Assignees
Labels
enhancement New feature or request

Comments

@Mr-Geekman
Copy link
Contributor

Mr-Geekman commented Jun 20, 2022

🚀 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
@Mr-Geekman Mr-Geekman added the enhancement New feature or request label Jun 20, 2022
@Mr-Geekman Mr-Geekman changed the title Create MathTransform Create LambdaTransform Jun 21, 2022
@scanhex12 scanhex12 self-assigned this Jun 22, 2022
@scanhex12 scanhex12 mentioned this issue Jun 22, 2022
9 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants