Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Very specific error with extract #2969

Closed
djkirkham opened this issue Mar 8, 2018 · 1 comment · Fixed by #4245
Closed

Very specific error with extract #2969

djkirkham opened this issue Mar 8, 2018 · 1 comment · Fixed by #4245

Comments

@djkirkham
Copy link
Contributor

djkirkham commented Mar 8, 2018

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
@djkirkham
Copy link
Contributor Author

It turns out it doesn't matter if the coordinate is scalar. The error occurs if the dtype of the constraint is float but the dtype of the bounds is int. There's code which extends the bounds to always include the point, so that the where will always return something, but if the dtypes are different this code can fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants