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 197 forks source link

Deedle FillMissing() function bug? #446

Closed DutchL closed 5 years ago

DutchL commented 5 years ago

I work with Deedle v.1.2.5 on C# and do get strange behavior.

When I replace missing values with FillMissing(double.NaN) function, it works as expected, but FillMissing((x) => double.NaN) code will not replace missing values.

What am I doing wrong?

//unitest
[Test]
public void Missing()
{
    var sb = new SeriesBuilder<int, double>() { { 1, double.NaN }, { 2, 2 } };
    var serie = sb.Series;
    //replaces missing with NaN
    var res = serie.FillMissing(double.NaN);

    //ok
    Assert.AreEqual(double.NaN, res.FirstValue());

    var sb2 = new SeriesBuilder<int, double>() { { 1, double.NaN }, { 2, 2 } };
    var serie2 = sb2.Series;
    //NOT replaces missing with NaN
    var res2 = serie2.FillMissing((x) => double.NaN);

    //crashes
    Assert.AreEqual(double.NaN, res2.FirstValue());
}
zyzhu commented 5 years ago

This is actually a bug in FillMissingWith. It assumes the replacement constant value is not nan. By design, Deedle should always handle nan value as missing value. Otherwise functions such as Stats.sum won't work as expected.

So basically the second case above is the correct behavior.