fslaborg / Deedle

Easy to use .NET library for data and time series manipulation and for scientific programming
http://fslab.org/Deedle/
BSD 2-Clause "Simplified" License
924 stars 196 forks source link

Add Series.Diff method that operates on DateTime to return series of TimeSpan #565

Open totalgit74 opened 4 days ago

totalgit74 commented 4 days ago

Currently Series has a diff method that operates on decimal, double, float and int. Could DateTime also be handled?

Series<K, TimeSpan> Diff<K>(this Series<K, DateTime> series, int offset) would be handy when trying to ascertain periodicity of a Frame by extracting the timestamp column and comparing a shift(1). That way you can see if it is constant or varying and, if so, the min and max interval lengths. The calculation can be done externally but is likely more efficient if implemented internally.

An example would be dealing with a time-series of data that could be either 30 minute or 5 minute intervals but you don't know which as you load the data from files. It could even be a mix. In the first two cases the output of your processing keeps the input interval length whereas in the latter case you reject the file/do not process it. The interval length is needed because you need to rebase the series by shifting times by 1 interval length should a flag be set.