From 8c03884f10f977ba12dd3ca0bce968d0107c0341 Mon Sep 17 00:00:00 2001 From: Rahil Doshi <rahil.doshi@fau.de> Date: Wed, 5 Mar 2025 01:19:23 +0100 Subject: [PATCH] Improve input validation with detailed error messages --- src/pymatlib/core/interpolators.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pymatlib/core/interpolators.py b/src/pymatlib/core/interpolators.py index 9967a47..e83415d 100644 --- a/src/pymatlib/core/interpolators.py +++ b/src/pymatlib/core/interpolators.py @@ -431,10 +431,13 @@ def prepare_interpolation_arrays(T_array: np.ndarray, E_array: np.ndarray) -> di # Basic validation if len(T_array) != len(E_array): - raise ValueError("Temperature and energy density arrays must have the same length") + raise ValueError(f"Energy density array (length {len(E_array)}) and temperature array (length {len(T_array)}) must have the same length!") - if len(T_array) < 2: - raise ValueError("Arrays must contain at least 2 elements") + if not E_array.size or not T_array.size: + raise ValueError("Energy density and temperature arrays must not be empty!") + + if len(E_array) < 2: + raise ValueError(f"Arrays must contain at least 2 elements, got {len(E_array)}!") # Check if arrays are monotonic T_increasing = np.all(np.diff(T_array) > 0) -- GitLab