Add error messages for minimum required non-NA Values
Closed this issue · 3 comments
Would be nice, if the package directly gives a error message, when the chosen method is not able to work properly because the time series is too short.
na.interpolation: "need at least two non-NA values to interpolate"
na.kalman: around 3 values + possible infinite loop
na.mean: 1 non NA value
na.locf: 1 non NA value
na.ma: unclear / possible errors for very small inputs (time series of length smaller parameter k)
My remark fits to this issue:
Due to a mistake in my own code I passed a time series only with NaNs to the na.kalman method. It calls na.locf which contains these lines:
#Replace NAs through locf/nocb from the other direction
else if (na.remaining == "rev") {
if (option == "locf") {
data <- na.locf(data, option = "nocb")
}
else if (option == "nocb") {
data <- na.locf(data, option = "locf")
}
}
I think, this leads to endless calls of na.locf. My error message is:
na.locf(data, option = "nocb") : node stack overflow
Using imputation with an "empty" time series is nonsense, of course. But, as you mentioned in your post, having error message would be nice :)
Thanks a lot for your error report.
This specific error was not on my radar yet.
Adding better error messages + improving behavior for these edge cases is definitely on the ToDo list for one of the next updates.
Error Messages now present for a lot of wrong inputs.