diff --git a/lib/iris/analysis/__init__.py b/lib/iris/analysis/__init__.py index 0b1d94fbc5..b48fab6baa 100644 --- a/lib/iris/analysis/__init__.py +++ b/lib/iris/analysis/__init__.py @@ -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: diff --git a/lib/iris/tests/results/analysis/coord_comparison/cube1_cube5.txt b/lib/iris/tests/results/analysis/coord_comparison/cube1_cube5.txt new file mode 100644 index 0000000000..d15d4c74d7 --- /dev/null +++ b/lib/iris/tests/results/analysis/coord_comparison/cube1_cube5.txt @@ -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 [] diff --git a/lib/iris/tests/results/analysis/coord_comparison/cube2_cube5.txt b/lib/iris/tests/results/analysis/coord_comparison/cube2_cube5.txt new file mode 100644 index 0000000000..b1d7e797ac --- /dev/null +++ b/lib/iris/tests/results/analysis/coord_comparison/cube2_cube5.txt @@ -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']] diff --git a/lib/iris/tests/results/analysis/coord_comparison/cube3_cube5.txt b/lib/iris/tests/results/analysis/coord_comparison/cube3_cube5.txt new file mode 100644 index 0000000000..7859ef2d2c --- /dev/null +++ b/lib/iris/tests/results/analysis/coord_comparison/cube3_cube5.txt @@ -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 [] diff --git a/lib/iris/tests/results/analysis/coord_comparison/cube4_cube5.txt b/lib/iris/tests/results/analysis/coord_comparison/cube4_cube5.txt new file mode 100644 index 0000000000..25fd739bea --- /dev/null +++ b/lib/iris/tests/results/analysis/coord_comparison/cube4_cube5.txt @@ -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']] diff --git a/lib/iris/tests/test_analysis.py b/lib/iris/tests/test_analysis.py index 8ad41e5270..dc8ff1985a 100644 --- a/lib/iris/tests/test_analysis.py +++ b/lib/iris/tests/test_analysis.py @@ -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'))