Skip to content

Commit

Permalink
add transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
emptymalei committed Oct 28, 2023
1 parent 33f8d2a commit 2b92f42
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
File renamed without changes.
52 changes: 52 additions & 0 deletions haferml/transforms/dataframe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from __future__ import annotations
from abc import ABC, abstractmethod
import pandas as pd
from typing import List, Union


class TransformBase(ABC):
"""
TransformBase transforms a dataframe.
This is a transformation inspired by the
package gluonts.
"""

@abstractmethod
def __call__(self, dataframe: pd.DataFrame) -> pd.DataFrame:
"""
"""
raise NotImplementedError("This method is not implemented yet.")

def __add__(self, other: TransformBase) -> ConcatTransform:
"""
"""
return ConcatTransform([self, other])


class ConcatTransform(TransformBase):
"""Concatenated transforms.
The returned transforms inherited from the
:param transforms: List of transforms to be concatenated
"""

def __init__(self, transforms: List[TransformBase]):
self.transforms = []
for transform in transforms:
self._update(transform)

def _update(self, transform: Union[ConcatTransform, TransformBase]):
if isinstance(transform, ConcatTransform):
self.transforms.extend(transform)
elif isinstance(transform, TransformBase):
self.transforms.append(transform)
else:
raise TypeError("Expected type TransformBase or ConcatTransform")

def __call__(self, dataframe: pd.DataFrame) -> pd.DataFrame:
for t in self.transforms:
dataframe = t(dataframe)

return dataframe
File renamed without changes.
2 changes: 2 additions & 0 deletions tests/transforms/test_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from haferml.transforms import BaseTransform

0 comments on commit 2b92f42

Please sign in to comment.