From 04809033433737a1c31689c78358dfc9611597fd Mon Sep 17 00:00:00 2001
From: Manon Blanco <blanco@teklia.com>
Date: Wed, 11 Oct 2023 12:43:55 +0000
Subject: [PATCH] Round mean values calculated during data analysis

---
 dan/datasets/analyze/statistics.py | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/dan/datasets/analyze/statistics.py b/dan/datasets/analyze/statistics.py
index efdc0ef6..d6a716ed 100644
--- a/dan/datasets/analyze/statistics.py
+++ b/dan/datasets/analyze/statistics.py
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 import logging
 from collections import Counter, defaultdict
+from functools import partial
 from pathlib import Path
 from typing import Dict, List, Optional
 
@@ -32,23 +33,32 @@ def create_table(
     operations = []
 
     if count:
-        operations.append(("Count", len))
+        operations.append(("Count", len, None))
 
     operations.extend(
         [
-            ("Min", np.min),
-            ("Max", np.max),
-            ("Mean", np.mean),
-            ("Median", np.median),
+            ("Min", np.min, None),
+            ("Max", np.max, None),
+            ("Mean", np.mean, 2),
+            ("Median", np.median, 2),
         ]
     )
     if total:
-        operations.append(("Total", np.sum))
+        operations.append(("Total", np.sum, None))
 
     statistics.add_rows(
         [
-            [col_name, *list(map(operator, data.values()))]
-            for col_name, operator in operations
+            [
+                col_name,
+                *list(
+                    map(
+                        # Round values if needed
+                        partial(round, ndigits=digits),
+                        map(operator, data.values()),
+                    )
+                ),
+            ]
+            for col_name, operator, digits in operations
         ]
     )
 
-- 
GitLab