From 1f0bde13afee97ba705a7af385e40809df7a59b1 Mon Sep 17 00:00:00 2001 From: Sudip Sinha Date: Wed, 9 Sep 2026 17:27:37 +0100 Subject: [PATCH] fix: squeeze regressor scores before scalar assignment for numpy 2.x compat In numpy 2.x, PyTorch model output for regressors has shape (n, 1) rather than (n,), so model_scores[i] is an array of shape (1,) not a scalar. Assigning a sequence to a scalar element of a numpy array raises ValueError in numpy 2.x. np.squeeze collapses the size-1 dimension to a 0-d array; float() converts it to a Python scalar before the assignment. This is a no-op for backends that already return a scalar (sklearn). Fixes 14 failing regression tests across dice_random, dice_KD, and dice_genetic with PyTorch backend. Signed-off-by: Sudip Sinha Signed-off-by: Sudip Sinha rh-pre-commit.version: 2.3.2 rh-pre-commit.check-secrets: ENABLED --- dice_ml/explainer_interfaces/explainer_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dice_ml/explainer_interfaces/explainer_base.py b/dice_ml/explainer_interfaces/explainer_base.py index 59894f1f..756c7675 100644 --- a/dice_ml/explainer_interfaces/explainer_base.py +++ b/dice_ml/explainer_interfaces/explainer_base.py @@ -810,7 +810,7 @@ def get_model_output_from_scores(self, model_scores): else: # 1-D input model_output[i] = np.round(model_scores[i]) elif self.model.model_type == ModelTypes.Regressor: - model_output[i] = model_scores[i] + model_output[i] = float(np.squeeze(model_scores[i])) return model_output def check_permitted_range(self, permitted_range):