Expanding

Expanding window operations
import pandas as pd

np.random.seed(0)
array = np.random.rand(100)
series = pd.Series(array)

source

expanding_mean

 expanding_mean (input_array:numpy.ndarray)
np.testing.assert_allclose(expanding_mean(array), series.expanding().mean().values)

source

expanding_std

 expanding_std (input_array:numpy.ndarray)
np.testing.assert_allclose(expanding_std(array), series.expanding().std().values)

source

expanding_max

 expanding_max (x:numpy.ndarray)
np.testing.assert_allclose(expanding_max(array), series.expanding().max())

source

expanding_min

 expanding_min (x:numpy.ndarray)
np.testing.assert_allclose(expanding_min(array), series.expanding().min())

Seasonal

seasons = np.arange(array.size) % 7
grouped_series = series.groupby(seasons)

source

seasonal_expanding_mean

 seasonal_expanding_mean (x:numpy.ndarray, season_length:int)
np.testing.assert_allclose(
    seasonal_expanding_mean(array, 7),
    grouped_series.transform(lambda y: y.expanding().mean())
)

source

seasonal_expanding_std

 seasonal_expanding_std (x:numpy.ndarray, season_length:int)
np.testing.assert_allclose(
    seasonal_expanding_std(array, 7),
    grouped_series.transform(lambda y: y.expanding().std())
)

source

seasonal_expanding_min

 seasonal_expanding_min (x:numpy.ndarray, season_length:int)
np.testing.assert_allclose(
    seasonal_expanding_min(array, 7),
    grouped_series.transform(lambda y: y.expanding().min())
)

source

seasonal_expanding_max

 seasonal_expanding_max (x:numpy.ndarray, season_length:int)
np.testing.assert_allclose(
    seasonal_expanding_min(array, 7),
    grouped_series.transform(lambda y: y.expanding().min())
)