Skip to content

Commit

Permalink
Merge pull request #520 from Aarhus-Psychiatry-Research/docs/511/add_…
Browse files Browse the repository at this point in the history
…docstrings_to_aggregators

docs(#511): add docstrings to aggregators
  • Loading branch information
HLasse authored Feb 27, 2024
2 parents de3973f + d378662 commit c16728e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docs/tutorials/04_from_legacy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@
],
"source": [
"from timeseriesflattener import PredictorSpec as Version2PredictorSpec\n",
"\n",
"# IMPORT CHANGED BELOW #\n",
"# from timeseriesflattener.v1.feature_specs.single_specs import PredictorSpec as Version1PredictorSpec\n",
"# from timeseriesflattener.v1.feature_specs.single_specs import PredictorSpec as Version1PredictorSpec # noqa: ERA001\n",
"from timeseriesflattener.feature_specs.from_legacy import PredictorGroupSpec\n",
"\n",
"# IMPORT CHANGED ABOVE #\n",
"\n",
"new_specs = PredictorGroupSpec(\n",
Expand Down
18 changes: 18 additions & 0 deletions src/timeseriesflattener/aggregators.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,35 @@ def new_col_name(self, previous_col_name: str) -> str:


class MinAggregator(Aggregator):
"""Returns the minimum value in the look window."""

name: str = "min"

def __call__(self, column_name: str) -> pl.Expr:
return pl.col(column_name).min().alias(self.new_col_name(column_name))


class MaxAggregator(Aggregator):
"""Returns the maximum value in the look window."""

name: str = "max"

def __call__(self, column_name: str) -> pl.Expr:
return pl.col(column_name).max().alias(self.new_col_name(column_name))


class MeanAggregator(Aggregator):
"""Returns the mean value in the look window."""

name: str = "mean"

def __call__(self, column_name: str) -> pl.Expr:
return pl.col(column_name).mean().alias(self.new_col_name(column_name))


class CountAggregator(Aggregator):
"""Returns the count of non-null values in the look window."""

name: str = "count"

def __call__(self, column_name: str) -> pl.Expr:
Expand All @@ -48,6 +56,8 @@ def __call__(self, column_name: str) -> pl.Expr:

@dataclass(frozen=True)
class EarliestAggregator(Aggregator):
"""Returns the earliest value in the look window."""

timestamp_col_name: str
name: str = "earliest"

Expand All @@ -62,6 +72,8 @@ def __call__(self, column_name: str) -> pl.Expr:

@dataclass(frozen=True)
class LatestAggregator(Aggregator):
"""Returns the latest value in the look window"""

timestamp_col_name: str
name: str = "latest"

Expand All @@ -75,13 +87,17 @@ def __call__(self, column_name: str) -> pl.Expr:


class SumAggregator(Aggregator):
"""Returns the sum of all values in the look window."""

name: str = "sum"

def __call__(self, column_name: str) -> pl.Expr:
return pl.col(column_name).sum().alias(self.new_col_name(column_name))


class VarianceAggregator(Aggregator):
"""Returns the variance of the values in the look window"""

name: str = "var"

def __call__(self, column_name: str) -> pl.Expr:
Expand All @@ -106,6 +122,8 @@ def __call__(self, column_name: str) -> pl.Expr:

@dataclass(frozen=True)
class SlopeAggregator(Aggregator):
"""Returns the slope (i.e. the correlation between the timestamp and the value) in the look window."""

timestamp_col_name: str
name: str = "slope"

Expand Down

0 comments on commit c16728e

Please sign in to comment.