FSharp.Stats icon indicating copy to clipboard operation
FSharp.Stats copied to clipboard

[Feature Request] Median should give a more helpful error for empty non-float sequences

Open nhirschey opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe. The median of an empty float sequence is nan. The median of an empty integer or decimal sequence causes an error with an unhelpful error message.

The error message for an empty non-float sequence should make it clear it's an FSharp.Stats problem to make it easier to debug.

#r "nuget: FSharp.Stats, 0.5.1-preview.2"

open FSharp.Stats

let ys: float [] = [||]
median ys

> val ys: float array = [||]
> val it: float = nan

let xs: decimal [] = [||]
median xs
> System.DivideByZeroException: Attempted to divide by zero.
   at System.Decimal.DecCalc.VarDecDiv(DecCalc& d1, DecCalc& d2)
   at System.Decimal.op_Division(Decimal d1, Decimal d2)

Describe the solution you'd like An error message such as "FSharp.Stats median is undefined for an empty decimal sequence"

nhirschey avatar Aug 27 '24 18:08 nhirschey