Skip to content

Commit

Permalink
Merge pull request #2772 from djkirkham/coord_comparison_id_check
Browse files Browse the repository at this point in the history
Fix coord_comparison when coords are the same object
  • Loading branch information
pelson authored Oct 27, 2017
2 parents 7831684 + 1f17472 commit 9cc610b
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/iris/analysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def coord_comparison(*cubes):
for other_coord in all_coords[other_cube_i]:
# for optimisation, check that the name is equivalent
# *before* checking all of the metadata is equivalent
eq = (id(other_coord) not in processed_coords and
eq = (other_coord is coord or
other_coord.name() == coord.name() and
other_coord._as_defn() == coord._as_defn())
if eq:
Expand Down
14 changes: 14 additions & 0 deletions lib/iris/tests/results/analysis/coord_comparison/cube1_cube5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
dimensioned [['latitude', 'latitude'], ['longitude', 'longitude']]
equal [['latitude', 'latitude'], ['longitude', 'longitude']]
equal_data_dimension [['latitude', 'latitude'], ['longitude', 'longitude']]
grouped_coords [['f', 'None'], ['latitude', 'latitude'], ['longitude', 'longitude'], ['z', 'None']]
ignorable [['f', 'None'], ['z', 'None']]
no_data_dimension [['f', 'None'], ['z', 'None']]
non_equal_data_dimension [['f', 'None'], ['z', 'None']]
non_equal_shape [['f', 'None'], ['z', 'None']]
not_equal [['f', 'None'], ['z', 'None']]
resamplable []
scalar [['f', 'None'], ['z', 'None']]
transposable []
ungroupable [['f', 'None'], ['z', 'None']]
ungroupable_and_dimensioned []
14 changes: 14 additions & 0 deletions lib/iris/tests/results/analysis/coord_comparison/cube2_cube5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
dimensioned [['latitude', 'latitude'], ['longitude', 'longitude'], ['z', 'None']]
equal [['latitude', 'latitude']]
equal_data_dimension [['latitude', 'latitude'], ['longitude', 'longitude']]
grouped_coords [['latitude', 'latitude'], ['longitude', 'longitude'], ['z', 'None']]
ignorable []
no_data_dimension []
non_equal_data_dimension [['z', 'None']]
non_equal_shape [['z', 'None']]
not_equal [['longitude', 'longitude'], ['z', 'None']]
resamplable [['longitude', 'longitude']]
scalar []
transposable []
ungroupable [['z', 'None']]
ungroupable_and_dimensioned [['z', 'None']]
14 changes: 14 additions & 0 deletions lib/iris/tests/results/analysis/coord_comparison/cube3_cube5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
dimensioned [['latitude', 'latitude'], ['longitude', 'longitude']]
equal [['latitude', 'latitude'], ['longitude', 'longitude']]
equal_data_dimension []
grouped_coords [['f', 'None'], ['latitude', 'latitude'], ['longitude', 'longitude'], ['z', 'None']]
ignorable [['f', 'None'], ['z', 'None']]
no_data_dimension [['f', 'None'], ['z', 'None']]
non_equal_data_dimension [['f', 'None'], ['latitude', 'latitude'], ['longitude', 'longitude'], ['z', 'None']]
non_equal_shape [['f', 'None'], ['z', 'None']]
not_equal [['f', 'None'], ['z', 'None']]
resamplable []
scalar [['f', 'None'], ['z', 'None']]
transposable [['latitude', 'latitude'], ['longitude', 'longitude']]
ungroupable [['f', 'None'], ['z', 'None']]
ungroupable_and_dimensioned []
14 changes: 14 additions & 0 deletions lib/iris/tests/results/analysis/coord_comparison/cube4_cube5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
dimensioned [['latitude', 'latitude'], ['longitude', 'longitude'], ['z', 'None']]
equal [['latitude', 'latitude']]
equal_data_dimension []
grouped_coords [['latitude', 'latitude'], ['longitude', 'longitude'], ['z', 'None']]
ignorable []
no_data_dimension []
non_equal_data_dimension [['latitude', 'latitude'], ['longitude', 'longitude'], ['z', 'None']]
non_equal_shape [['z', 'None']]
not_equal [['longitude', 'longitude'], ['z', 'None']]
resamplable []
scalar []
transposable [['latitude', 'latitude']]
ungroupable [['z', 'None']]
ungroupable_and_dimensioned [['z', 'None']]
11 changes: 11 additions & 0 deletions lib/iris/tests/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,26 @@ def test_coord_comparison(self):
cube4.add_dim_coord(lon, 1)
cube4.add_dim_coord(lat, 0)

# Test when coords are the same object
lon = cube1.coord('longitude')
lat = cube1.coord('latitude')
cube5 = iris.cube.Cube(np.zeros((41, 41)))
cube5.add_dim_coord(lon, 0)
cube5.add_dim_coord(lat, 1)

coord_comparison = iris.analysis.coord_comparison

self.assertComparisonDict(coord_comparison(cube1, cube1), ('analysis', 'coord_comparison', 'cube1_cube1.txt'))
self.assertComparisonDict(coord_comparison(cube1, cube2), ('analysis', 'coord_comparison', 'cube1_cube2.txt'))
self.assertComparisonDict(coord_comparison(cube1, cube3), ('analysis', 'coord_comparison', 'cube1_cube3.txt'))
self.assertComparisonDict(coord_comparison(cube1, cube4), ('analysis', 'coord_comparison', 'cube1_cube4.txt'))
self.assertComparisonDict(coord_comparison(cube1, cube5), ('analysis', 'coord_comparison', 'cube1_cube5.txt'))
self.assertComparisonDict(coord_comparison(cube2, cube3), ('analysis', 'coord_comparison', 'cube2_cube3.txt'))
self.assertComparisonDict(coord_comparison(cube2, cube4), ('analysis', 'coord_comparison', 'cube2_cube4.txt'))
self.assertComparisonDict(coord_comparison(cube2, cube5), ('analysis', 'coord_comparison', 'cube2_cube5.txt'))
self.assertComparisonDict(coord_comparison(cube3, cube4), ('analysis', 'coord_comparison', 'cube3_cube4.txt'))
self.assertComparisonDict(coord_comparison(cube3, cube5), ('analysis', 'coord_comparison', 'cube3_cube5.txt'))
self.assertComparisonDict(coord_comparison(cube4, cube5), ('analysis', 'coord_comparison', 'cube4_cube5.txt'))

self.assertComparisonDict(coord_comparison(cube1, cube1, cube1), ('analysis', 'coord_comparison', 'cube1_cube1_cube1.txt'))
self.assertComparisonDict(coord_comparison(cube1, cube2, cube1), ('analysis', 'coord_comparison', 'cube1_cube2_cube1.txt'))
Expand Down

0 comments on commit 9cc610b

Please sign in to comment.