From 1b264590377e9a18718114a8a5f2a3f8108eeec8 Mon Sep 17 00:00:00 2001 From: "Justin R. Porter" Date: Mon, 10 Jun 2024 09:43:51 -0400 Subject: [PATCH] Elaborate on error message in ragged array slicing. (#151) --- enspara/ra/ra.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/enspara/ra/ra.py b/enspara/ra/ra.py index 26900113..c29c75f2 100644 --- a/enspara/ra/ra.py +++ b/enspara/ra/ra.py @@ -319,11 +319,14 @@ def _convert_from_2d(iis_ragged, lengths=None, starts=None, error_check=True): [second_dimension for n in first_dimension]) first_dimension, second_dimension = _handle_negative_indices( first_dimension, second_dimension, lengths=lengths, starts=starts) - # Check for index error + # Check if row is too short for indexing if lengths is not None and error_check: if np.any(lengths[first_dimension] <= second_dimension): - raise IndexError - iis_flat = starts[first_dimension]+second_dimension + raise IndexError(("Length of dimension {} ({}) is out of " + "range for index {}") + .format(first_dimension, lengths[first_dimension], + second_dimension)) + iis_flat = starts[first_dimension] + second_dimension return (iis_flat,)