From 9a57f362dc3d45be564fd1d2ef75932104d50055 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 15 Feb 2022 22:20:17 +0100 Subject: [PATCH] =?UTF-8?q?Divisions=20par=20z=C3=A9ro=20non=20control?= =?UTF-8?q?=C3=A9es=20si=20les=20arrays=20vides=20passent=20en=20object?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/comp/moy_ue.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/comp/moy_ue.py b/app/comp/moy_ue.py index b0a534e5..84a7e2bf 100644 --- a/app/comp/moy_ue.py +++ b/app/comp/moy_ue.py @@ -266,6 +266,8 @@ def compute_ue_moys_apc( ) # Annule les coefs des modules NaN modimpl_coefs_etuds_no_nan = np.where(np.isnan(sem_cube), 0.0, modimpl_coefs_etuds) + if modimpl_coefs_etuds_no_nan.dtype == np.object: # arrive sur des tableaux vides + modimpl_coefs_etuds_no_nan = modimpl_coefs_etuds_no_nan.astype(np.float) # # Version vectorisée # @@ -348,7 +350,8 @@ def compute_ue_moys_classic( modimpl_coefs_etuds_no_nan = np.where( np.isnan(sem_matrix), 0.0, modimpl_coefs_etuds ) - + if modimpl_coefs_etuds_no_nan.dtype == np.object: # arrive sur des tableaux vides + modimpl_coefs_etuds_no_nan = modimpl_coefs_etuds_no_nan.astype(np.float) # --------------------- Calcul des moyennes d'UE ue_modules = np.array( [[m.module.ue == ue for m in formsemestre.modimpls_sorted] for ue in ues] @@ -358,6 +361,8 @@ def compute_ue_moys_classic( ) # nb_ue x nb_etuds x nb_mods : coefs prenant en compte NaN et inscriptions coefs = (modimpl_coefs_etuds_no_nan_stacked * ue_modules).swapaxes(1, 2) + if coefs.dtype == np.object: # arrive sur des tableaux vides + coefs = coefs.astype(np.float) with np.errstate(invalid="ignore"): # ignore les 0/0 (-> NaN) etud_moy_ue = ( np.sum(coefs * sem_matrix_inscrits, axis=2) / np.sum(coefs, axis=2)