v = Series([1, 1, 1, nan, 1, 1, 1, 1, nan, 1], dtype=float)
n = v.isnull()
a = ~n
c = a.astype(float).cumsum()
index = c[n].index
d = Series(np.diff(np.hstack(([0.0], c[n]))), index=index)
v[n] = -d
result = v.cumsum()
Cumsum reset at NaN