iris icon indicating copy to clipboard operation
iris copied to clipboard

Merging cube with a masked scalar coordinate fails

Open lbdreyer opened this issue 2 years ago • 2 comments

🐛 Bug Report

It looks like the merge code can't handle a cube that contains a masked scalar coordinate.

This originally came from a user who is trying to load a netcdf file that contains an aux coordinate which is scalar. The loading process falls down in the merge step as iris tries to take a has of the masked constant which fails:

  File "<path_to_install>/iris/lib/iris/cube.py", line 535, in merge
    merged_cubes.extend(proto_cube.merge(unique=unique))
  File "<path_to_install>/iris/lib/iris/_merge.py", line 1254, in merge
    indexes = build_indexes(positions)
  File "<path_to_install>/iris/lib/iris/_merge.py", line 598, in build_indexes
    if value in name_index_by_scalar:
  File "<path_to_install>/iris/lib/iris/coords.py", line 1352, in __hash__
    return hash(self.point)
TypeError: unhashable type: 'MaskedConstant'

But loading the netcdf file with iris.load_raw (i.e. skipping the merge step) works.

How To Reproduce

from iris.cube import Cube, CubeList
from iris.coords import AuxCoord
import numpy.ma as ma

cube_a = Cube([1])
cube_a.add_aux_coord(AuxCoord(ma.masked, 'height'))
cube_b = Cube([2])
cube_b.add_aux_coord(AuxCoord(ma.masked, 'height'))

cubes = CubeList([cube_a, cube_b])
cubes.merge()

Expected behaviour

Iris should be able to successfully load a file that contains a masked scalar coordinate and merge two cubes that contain masked scalar coords.

lbdreyer avatar Feb 15 '23 14:02 lbdreyer