diff --git a/h5py/_errors.pyx b/h5py/_errors.pyx index 612052fb2..88d996843 100644 --- a/h5py/_errors.pyx +++ b/h5py/_errors.pyx @@ -80,6 +80,12 @@ _exact_table = { (H5E_FILE, H5E_CANTCONVERT): ValueError, # Invalid file format } +# Further fudge: In some cases, the error numbers we care about are those from +# the bottom (innermost) error in the stack. +_bottom_exact_table = { + (H5E_DATASPACE, H5E_BADRANGE): IndexError, # Out of range selection +} + IF HDF5_VERSION > (1, 12, 0): _exact_table[(H5E_DATASET, H5E_CANTCREATE)] = ValueError # bad param for dataset setup @@ -140,6 +146,8 @@ cdef int set_exception() except -1: if H5Ewalk(H5E_DEFAULT, H5E_WALK_DOWNWARD, walk_cb, &err) < 0: raise RuntimeError("Failed to walk error stack") + eclass = _bottom_exact_table.get((err.err.maj_num, err.err.min_num), eclass) + desc_bottom = err.err.desc if desc_bottom is NULL: raise RuntimeError("Failed to extract bottom-level error description") diff --git a/h5py/tests/test_dataset.py b/h5py/tests/test_dataset.py index df99f527a..fde90914a 100644 --- a/h5py/tests/test_dataset.py +++ b/h5py/tests/test_dataset.py @@ -1753,6 +1753,11 @@ def test_read_points(writable_file): res = ds.points[[(0, 0), (1, 0), (2, 2)]] np.testing.assert_array_equal(res, [0, 6, 14]) + with pytest.raises(IndexError): + ds.points[[(0, 7)]] + + with pytest.raises(IndexError): + ds.points[[(-1, 0)]] def test_write_points(writable_file): ds = writable_file.create_dataset('a', shape=(3, 3)) @@ -1764,6 +1769,12 @@ def test_write_points(writable_file): [0, 0, 3], ]) + with pytest.raises(IndexError): + ds.points[[(0, 4)]] = [4] + + with pytest.raises(IndexError): + ds.points[[(-1, 0)]] = [5] + class TestCommutative(BaseDataset): """