JeffreySarnoff / RollingFunctions.jl

Roll a window over data; apply a function over the window.
MIT License
114 stars 6 forks source link

Different API with `rolling` function #14

Closed scls19fr closed 5 years ago

scls19fr commented 5 years ago

Hello,

I wonder if

mean(rolling(data, windowsize))

or with piping operator

rolling(data, windowsize) |> mean

couldn't be an interesting API

What is your opinion?

Kind regards

JeffreySarnoff commented 5 years ago

What would be involved?

scls19fr commented 5 years ago

it could reduce the number of exported functions and provide an API quite similar to Python Pandas and have a kind of object oriented API (by using multiple dispatch)

See https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.rolling.html

An other feature that could be provide could be to also have expanding functions.

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.expanding.html#pandas.DataFrame.expanding

For example we have cumsum and cumprod in Base but not neither cummax nor cummin https://github.com/JuliaLang/julia/issues/1649

So a similar approach could be done with expanding functions See https://github.com/JuliaLang/julia/issues/1649#issuecomment-504539648

JeffreySarnoff commented 5 years ago

your mean(rolling(data, windowsize)) is my rolling(mean, data, windowsize) rollmean(data, windowsize) is just a convenience for rolling(mean, data, windowsize)

It wouldn't really reduce the number of exported functions .. I could simply not export the rollmean etc and force the user to use rolling(mean, data, windowsize) .. also, more importantly, I would have to overload mean and all the others which may cause interoperability issues with other packages down the line (or today).

FYI the general approach was (no disrespect to Pandas) inspired by functions and libs I had used with R.

Adding cummax cummin etc seems like a good idea.

scls19fr commented 5 years ago

cummin and cummax have been deprecated in favor of accumulate

https://github.com/JuliaLang/julia/blob/480703b9d770f82202b8a6daf0b3414fc7e9fad9/HISTORY.md

https://github.com/JuliaLang/julia/pull/18931

JeffreySarnoff commented 5 years ago

ok -- thank you for the note