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

Merging cube with a masked scalar coordinate fails #5160

Open
lbdreyer opened this issue Feb 15, 2023 · 2 comments
Open

Merging cube with a masked scalar coordinate fails #5160

lbdreyer opened this issue Feb 15, 2023 · 2 comments
Labels
Stale A stale issue/pull-request Type: Bug

Comments

@lbdreyer
Copy link
Member

🐛 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.

@rcomer
Copy link
Member

rcomer commented Feb 15, 2023

Possible duplicate of #3584.

Copy link
Contributor

In order to maintain a backlog of relevant issues, we automatically label them as stale after 500 days of inactivity.

If this issue is still important to you, then please comment on this issue and the stale label will be removed.

Otherwise this issue will be automatically closed in 28 days time.

@github-actions github-actions bot added the Stale A stale issue/pull-request label Jun 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale A stale issue/pull-request Type: Bug
Projects
Status: No status
Development

No branches or pull requests

2 participants