-
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.
feat(#360): ensure correct ordering before concatenating
Fixes #360
- Loading branch information
1 parent
dba3063
commit 3af55e3
Showing
4 changed files
with
82 additions
and
35 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,18 +1,25 @@ | ||
from dataclasses import dataclass | ||
|
||
import polars as pl | ||
from polars.lazyframe.group_by import LazyGroupBy | ||
|
||
from .feature_specs import AggregatedValueFrame, Aggregator, SlicedFrame | ||
from timeseriesflattenerv2.feature_specs import Aggregator | ||
|
||
from .feature_specs import AggregatedValueFrame | ||
|
||
|
||
@dataclass | ||
class MeanAggregator(Aggregator): | ||
name: str = "mean" | ||
def apply(self, grouped_frame: LazyGroupBy, column_name: str) -> AggregatedValueFrame: | ||
value_col_name = f"{column_name}_mean" | ||
df = grouped_frame.agg(pl.col(column_name).mean().alias(value_col_name)) | ||
return AggregatedValueFrame(df=df, value_col_name=value_col_name) | ||
|
||
|
||
def apply(self, sliced_frame: SlicedFrame, column_name: str) -> AggregatedValueFrame: | ||
df = sliced_frame.df.group_by( | ||
sliced_frame.pred_time_uuid_col_name, maintain_order=True | ||
).agg(pl.col(column_name).mean()) | ||
# TODO: Figure out how to standardise the output column names | ||
@dataclass | ||
class MaxAggregator(Aggregator): | ||
def apply(self, grouped_frame: LazyGroupBy, column_name: str) -> AggregatedValueFrame: | ||
value_col_name = f"{column_name}_max" | ||
df = grouped_frame.agg(pl.col(column_name).max().alias(value_col_name)) | ||
|
||
return AggregatedValueFrame(df=df) | ||
return AggregatedValueFrame(df=df, value_col_name=value_col_name) |
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
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
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