tsod icon indicating copy to clipboard operation
tsod copied to clipboard

wrong gradient with abs(periods)>1

Open otzi5300 opened this issue 1 month ago • 0 comments

We should add some documentation to this function but i think it is currently not calculating the gradients correctly if periods > 1. Testing of "monotonically increasing" could also be done in _validation() function? Possible fix below for dt:

def _gradient(
        self, data: pd.Series | pd.DataFrame, periods: int = 1
    ) -> pd.Series | pd.DataFrame:
        #OLD dt = data.index.to_series().diff().dt.total_seconds()
        dt = data.index.to_series().diff(periods=periods).dt.total_seconds() <<< NEW LINE

        if dt.min() < 1e-15:
            raise ValueError("Index must be monotonically increasing")

        gradient = data.diff(periods=periods) / dt


        return gradient

otzi5300 avatar Nov 07 '25 09:11 otzi5300