From 49ef7edd2611628b630d47aea1c941e60539d46f Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Fri, 11 Feb 2022 10:30:24 +0100 Subject: [PATCH] Robustifie calculs stats sur types exotiques / 9.1.51 --- app/comp/aux_stats.py | 19 +++++++++++-------- sco_version.py | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/comp/aux_stats.py b/app/comp/aux_stats.py index 3337c2b8..91b1f899 100644 --- a/app/comp/aux_stats.py +++ b/app/comp/aux_stats.py @@ -20,15 +20,18 @@ class StatsMoyenne: """Calcul les statistiques. Les valeurs NAN ou non numériques sont toujours enlevées. Si vals is None, renvoie des zéros (utilisé pour UE bonus) - """ - if vals is None or len(vals) == 0: + """sco_ver + try: + if vals is None or len(vals) == 0 or np.isnan(vals).all(): + self.moy = self.min = self.max = self.size = self.nb_vals = 0 + else: + self.moy = np.nanmean(vals) + self.min = np.nanmin(vals) + self.max = np.nanmax(vals) + self.size = len(vals) + self.nb_vals = self.size - np.count_nonzero(np.isnan(vals)) + except TypeError: # que des NaN dans un array d'objets, ou ce genre de choses exotiques... self.moy = self.min = self.max = self.size = self.nb_vals = 0 - else: - self.moy = np.nanmean(vals) - self.min = np.nanmin(vals) - self.max = np.nanmax(vals) - self.size = len(vals) - self.nb_vals = self.size - np.count_nonzero(np.isnan(vals)) def to_dict(self): "Tous les attributs dans un dict" diff --git a/sco_version.py b/sco_version.py index bda50cef..3f97897e 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.1.50" +SCOVERSION = "9.1.51" SCONAME = "ScoDoc"