-
Notifications
You must be signed in to change notification settings - Fork 83
Create LambdaTransform
#762
Copy link
Copy link
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
🚀 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 transforminplace
: should transform be applied inplace or create a new columnout_column
: name of column to create ifinplace=False
transform_func
: function that takes wide dataframe with selectedin_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 ifinplace=True
, signature is the same as signature oftransform_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 anAddConstTransform
LogTransform
-- add some checks during the transform
Test cases
- Make sure that rewritten transforms pass the tests.
- Test that if
inplace=True
inverse_transform_func
is necessary. - Test interface if
inplace=True
. - Test interface if
inplace=False
: column name should be generated byout_column
if it is present. - Test
transform
method for some function examples. - Test
inverse_transform
for some function examples ininplace=True
andinplace=False
.
Alternatives
No response
Additional context
No response
Checklist
- I discussed this issue with ETNA Team
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Type
Projects
Status
Done