blob: 7b627b66665915bcaedda8ba0344dfe8bd2d6b03 [file] [log] [blame]
import polars as pl
"""
Notes:
1. This file is used for all the [ray|dask|spark]/hello_world examples.
2. It therefore show cases how you can write something once and not only scale it, but port it
to different frameworks with ease!
"""
def avg_3wk_spend(spend: pl.Series) -> pl.Series:
"""Rolling 3 week average spend."""
return spend.rolling_mean(3)
def spend_per_signup(spend: pl.Series, signups: pl.Series) -> pl.Series:
"""The cost per signup in relation to spend."""
return spend / signups
def spend_mean(spend: pl.Series) -> float:
"""Shows function creating a scalar. In this case it computes the mean of the entire column."""
return spend.mean()
def spend_zero_mean(spend: pl.Series, spend_mean: float) -> pl.Series:
"""Shows function that takes a scalar. In this case to zero mean spend."""
return spend - spend_mean
def spend_std_dev(spend: pl.Series) -> float:
"""Function that computes the standard deviation of the spend column."""
return spend.std()
def spend_zero_mean_unit_variance(spend_zero_mean: pl.Series, spend_std_dev: float) -> pl.Series:
"""Function showing one way to make spend have zero mean and unit variance."""
return spend_zero_mean / spend_std_dev