-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33f8d2a
commit 2b92f42
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from haferml.transforms import BaseTransform | ||
|