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

Breaking change for Min/Max stats function between v2.1.0 and 2.1.1 #537

Closed Seddryck closed 2 years ago

Seddryck commented 2 years ago

Before version 2.1.1, it was possible to use the Stats.Min and Stats.Max functions for the series containing elements of type DateTime. When releasing version 2.1.1, a breaking change has been introduced and the following exception is thrown when trying to calculate Min/Max for a series of DateTime:

Message: 
    System.InvalidCastException : Invalid cast from 'DateTime' to 'Double'.
  Stack Trace: 
    IConvertible.ToDouble(IFormatProvider provider)
    Convert.ToDouble(Object value)
    Max@35.Invoke(V arg00) line 35
    map@75.DoMoveNext(b& curr) line 78
    IEnumerator.MoveNext() line 64
    SeriesStatsExtensions.Max[K,V](Series`2 series) line 35
    MaxTest.Execute_DateTime_CorrectValue() 

Same behavior with version >=2.1.1

Steps to reproduce (c#)

var list = new List<object>() { new DateTime(2010,1,1), new DateTime(2016,1,1), new DateTime(2019, 1, 1) };
Assert.That(list.ToOrdinalSeries().Max(), Is.EqualTo(new DateTime(2019, 1, 1)));

The result of this test is successful with 2.1.0 and throws the previously mentioned exception with 2.1.1

zyzhu commented 2 years ago

It was a breaking change to make Stats.min and Stats.max to have similar outputs as other Stats functions. See #419. The old min and max functions were renamed to tryMin and tryMax.

This works in F#.

[DateTime(2010,1,1); DateTime(2016,1,1); DateTime(2019, 1, 1)]
|> Series.ofValues
|> Stats.tryMax

But I just realized that tryMin and tryMax is not exposed as extensions to be easily used in C#. I've just added TryMin and TryMax here https://github.com/fslaborg/Deedle/commit/09cf696c4578f9443aea3792c21089d38672f732 and released 2.4.3. Check it out.

Seddryck commented 2 years ago

Thx for the quick fix, working like a charm.