Add expanding moment functions and related tests. by qwhelan · Pull Request #1785 · pandas-dev/pandas (original) (raw)
Implement expanding_
analogues to the rolling_
moment functions available in pandas/stats/moments.py
by calling the rolling_
function with window=len(arg)
and min_periods
defaulting to the minimum number of data points to compute the statistic (1
for most, 4
for kurtosis, etc.). Resolves Issue #849.
The only potentially surprising behavior is that some expanding_
functions differ from their NumPy equivalents in whether they preserve NaN
s. For example, expanding_max(s)
is equivalent to rolling_max(s, len(s), min_periods=1)
, but both produce different output from s.cummax()
, as the latter always returns NaN
for every NaN
in s
. I don't have a strong opinion on which output is correct, aside from thinking rolling_
and expanding_
should agree.