SteffenMoritz/imputeTS

na.locf seems to be editing the original object

bokov opened this issue · 3 comments

bokov commented
bar <-  foo<- cumsum(rnorm(100));
bar[sample(1:100,20)]   <-  NA;
baz <-  bar;
na.locf(bar);
identical(bar, baz);
sum(is.na(bar));
sum(is.na(baz));

Expected result: bar and baz are identical and have same number of NAs. Actual result: the opposite of that in both cases. I've never seen a bug like that, I don't think I could even do that on purpose without at least a substitute statement someplace. Took forever to figure out why my variables we getting permanently changed.

Thx a lot for the report! 👍

Yes, this is or better was quite a strange error.
The issue itself is already fixed in the current version.

I don't think I could even do that on purpose

I also wasn't aware that this could happen....that's how the error came on CRAN 🤕
(actually the problem was in the C++ Code of the function)

You have had some bad luck, the problematic version of the package was online just a few days before being replaced by the bugfixed version.
(if you update the package version the issue should be fixed)

For the current version I get this output to your code:

identical(bar, baz);
[1] TRUE
sum(is.na(bar));
[1] 20
sum(is.na(baz));
[1] 20

Which should be correct.

I'll close this issue, since it seems to be fixed.
(if I misunderstood something or issue is still there, please open a new issue)

Thx again for reporting! :-)

bokov commented

Yes, the bug no longer occurs. Thank you for the fix, and sorry for delay in acknowledging.