Skip to content

Conversation

@esc24
Copy link
Member

@esc24 esc24 commented Jan 3, 2014

The following fails on upstream/master:

>>> import iris
>>> cube = iris.load_cube(iris.sample_data_path('space_weather.nc'), 'electron density')
>>> res = cube + cube

producing
ValueError: This operation cannot be performed as there are differing coordinates (longitude) remaining which cannot be ignored.
I tracked this down to the fact the longitude coordinate is fully masked (I know masked coords are not supported in Iris, but that can wait for another day). The problem stems from:

>>> lon = cube.coord('longitude')
>>> lon == lon
masked

This PR fixes the problem by altering iris.util.array_equal so it ignores any mask if present. This matches the behaviour of numpy.array_equal as stated in the existing iris.util.array_equal docstring. You could argue that we should modify the function to handle masked_arrays properly (that is open to various interpretations), but the chosen approach fixes the problem, is simpler, and reflects numpy behaviour.

Note that the change also means that iris.util.array_equal now matches numpy.array_equal in other ways too such as handling other types via np.asarray().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not need to give this a specific name? (Update: No, it appears not).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the reason this function exists at all, I'd be more comfortable if there was a test checking the string equality (with strings of different lengths).

@pelson
Copy link
Member

pelson commented Jan 8, 2014

Other than that, the implementation certainly is much neater. 👍

@esc24
Copy link
Member Author

esc24 commented Jan 9, 2014

I've added some more tests @pelson.

pelson added a commit that referenced this pull request Jan 15, 2014
Fixed iris.util.array_equal to avoid issues with fully masked arrays
@pelson pelson merged commit 2499d2e into SciTools:master Jan 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants