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

Lazy series interaction with Sample is broken #310

Open adamklein opened 9 years ago

adamklein commented 9 years ago

A little subtle, giving a full example:

public static async Task<Series<DateTime, double>> LazyData(DateTime d1, DateTime d2) {
    var ts = new SeriesBuilder<DateTime, double>();
    var d0 = d1;
    var v = 0.0;
    while (d0 <= d2) {
        ts.Add(d0, v);
        d0 = d0.AddSeconds(1);
        v += 1;
    }
    return ts.ToSeries();
}

void Main()
{
    var start = new DateTime(2014, 1, 2);
    var end   = new DateTime(2014, 1, 3);   
    var ts = DelayedSeries.Create<DateTime,double>(start, end, 
        async (lo, _, hi, __) => { 
            var x = await LazyData(lo, hi); 
            return x.Observations; 
        });

    var ds = new DateTime(2014, 1, 2);
    var de = ds.AddSeconds(20); // ds.AddDays(1).AddTicks(-1);

    // ok:
    // ts.Between(ds, de).Materialize().Sample(ds, TimeSpan.FromSeconds(5), Direction.Forward).Format().Dump(); 

    // fails: prints out data from 1/2/14 through 1/3/14 at 5 second intervals
    ts.Between(ds, de).Sample(ds, TimeSpan.FromSeconds(5), Direction.Forward).Format().Dump();
}
adamklein commented 9 years ago

(sample is linqpad script, hence Dump() call)

adamklein commented 9 years ago

PS we should basically just run the whole Series test suite on a lazy series :)

tpetricek commented 9 years ago

Oh.. I'll investigate.

Finding some way to run the tests on different kinds of series (lazy, big Deedle) is actually a great idea!