Skip to content

Commit

Permalink
describe returns string as key
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpantyukhin committed Aug 14, 2018
1 parent 3a4a790 commit 4ee9729
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
11 changes: 0 additions & 11 deletions src/Deedle/Common/Common.fs
Expand Up @@ -160,17 +160,6 @@ type 'T tryval = TryValue<'T>
/// [category:Primitive types and values]
type 'T opt = OptionalValue<'T>


/// The type of statistic item.
///
/// [category:Primitive types and values]
type StatisticItem =
| Min
| Max
| Mean
| Std


/// Represents different behaviors of key lookup in series. For unordered series,
/// the only available option is `Lookup.Exact` which finds the exact key - methods
/// fail or return missing value if the key is not available in the index. For ordered
Expand Down
20 changes: 11 additions & 9 deletions src/Deedle/Stats.fs
Expand Up @@ -631,21 +631,23 @@ type Stats =
/// Returns the series of main statistic values of the series.
///
/// [category:Series statistics]
static member describe (series:Series<'K, 'V>) =
static member inline describe (series:Series<'K, 'V>) =
match series with
| :? Series<_, float> as floatSeries ->
[|
(Min, Stats.min floatSeries);
(Max, Stats.max floatSeries);
(Mean, Some(Stats.mean floatSeries));
(Std, Some(Stats.stdDev floatSeries));
("min", Stats.min floatSeries);
("max", Stats.max floatSeries);
("mean", Some(Stats.mean floatSeries));
("std", Some(Stats.stdDev floatSeries));
("unique", Some(float(Stats.uniqueCount floatSeries)));
|] |> Array.toSeq |> Series.ofObservations
| _ ->
[|
(Min, None);
(Max, None);
(Mean, None);
(Std, None);
("min", None);
("max", None);
("mean", None);
("std", None);
("unique", Some(float(Stats.uniqueCount series)));
|] |> Array.toSeq |> Series.ofObservations


Expand Down
9 changes: 5 additions & 4 deletions tests/Deedle.Tests/Stats.fs
Expand Up @@ -89,11 +89,12 @@ let ``describe works`` ()=
let s = Series.ofValues [ 0.0; 1.0; 2.0; 3.0; 4.0 ]
let desc = Stats.describe s

desc.Get(Min) |> should equal (Stats.min s)
desc.Get(Max) |> should equal (Stats.max s)
desc.Get(Mean) |> should equal (Some(Stats.mean s))
desc.Get("min") |> should equal (Stats.min s)
desc.Get("max") |> should equal (Stats.max s)
desc.Get("mean") |> should equal (Some(Stats.mean s))
desc.Get("unique") |> should equal (Some(float(Stats.uniqueCount s)))

(Option.get (desc.Get(Std))) |> should beWithin ((Stats.stdDev s) +/- 1e-9)
(Option.get (desc.Get("std"))) |> should beWithin ((Stats.stdDev s) +/- 1e-9)

[<Test>]
let ``Moving skew works`` () =
Expand Down

0 comments on commit 4ee9729

Please sign in to comment.