Skip to content

Very specific error with extract #2969

@djkirkham

Description

@djkirkham

Extracting using a constraint on a scalar coordinate with bounds, where the value of the constraint is a non-integer outside the bounds causes an error:

import iris
from iris.cube import Cube
from iris.coords import DimCoord
x = DimCoord([1], bounds=[0,2], long_name='x')
cube = Cube(1, aux_coords_and_dims=[(x,())])
con = iris.Constraint(x=2.5)
cube.extract(con)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../iris/cube.py", line 2044, in extract
    return constraint.extract(self)
  File ".../iris/_constraints.py", line 151, in extract
    resultant_CIM = self._CIM_extract(cube)
  File ".../iris/_constraints.py", line 175, in _CIM_extract
    resultant_CIM = resultant_CIM & coord_constraint.extract(cube)
  File ".../iris/_constraints.py", line 273, in extract
    i = coord.nearest_neighbour_index(self._coord_thing)
  File ".../iris/coords.py", line 1189, in nearest_neighbour_index
    result_index = np.where(inside_cells)[0][0]
IndexError: index out of bounds

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions