Periods / shifts argument for the diff function

The diff function doesn’t have a periods / shifts argument, similar to the equivalent pandas function. But looking at the julia source code, it seems it would be easy to add it without breaking any existing code.

So before I go create an issue and a PR, is there any reason this is not already implemented (beyond that no one has gotten around to doing it)? Is there a better way to achieve the same functionality?

why? feature-bloated pandas don’t even have it, why should we? (pandas is feature-bloated because anything user have to DIY put together is significantly slower)

No comments on pandas being feature bloated, but what do you mean by “pandas don’t even have it”? I have literally linked to their documentation showing that they do have that argument and functionality.

Because it’s useful for things like time series analysis. Single step and other period differencing is often useful before doing autocorrelation analysis. Single step difference is what diff does, larger periods are not supported at the moment.

diff doesn’t have shift

It does have the periods arg. But periods may not be an intuitive name for the argument when not working with time series data, which is why I have included the shifts as an alternative name for the arg. shifts feels much more neutral (shifts=5 read as array shifted by 5 along index).

Also I’m not sure what you’re trying to argue? None of it is really an argument against adding this to the julia function.

what should go into a package should not be in Base

and sorry, I misunderstood this:

thought you’re saying Pandas also doesn’t have it but we should add.

Use ShiftedArrays.jl.

using ShiftedArrays
mydiff(x,n=1) = x - lag(x,n)

Note that this returns an object with the same length as x, which is not exactly what diff does.

That does look like almost exactly what I want. Thank you.