-
Notifications
You must be signed in to change notification settings - Fork 296
Fix equality #3536
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
Fix equality #3536
Changes from all commits
227264c
4e68261
dd6ae54
7533d82
ea49cc5
1fa7290
7af627c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,13 @@ | |
from iris.analysis import MEAN | ||
from iris.aux_factory import HybridHeightFactory | ||
from iris.cube import Cube | ||
from iris.coords import AuxCoord, DimCoord, CellMeasure, AncillaryVariable | ||
from iris.coords import ( | ||
AuxCoord, | ||
DimCoord, | ||
CellMeasure, | ||
AncillaryVariable, | ||
CellMethod, | ||
) | ||
from iris.exceptions import ( | ||
CoordinateNotFoundError, | ||
CellMeasureNotFoundError, | ||
|
@@ -1913,13 +1919,13 @@ def test_remove_aux_coord(self): | |
def test_remove_cell_measure(self): | ||
self.cube.remove_cell_measure(self.cube.cell_measure("area")) | ||
self.assertEqual( | ||
self.cube._cell_measures_and_dims, [[self.b_cell_measure, (0, 1)]] | ||
self.cube._cell_measures_and_dims, [(self.b_cell_measure, (0, 1))] | ||
) | ||
|
||
def test_remove_cell_measure_by_name(self): | ||
self.cube.remove_cell_measure("area") | ||
self.assertEqual( | ||
self.cube._cell_measures_and_dims, [[self.b_cell_measure, (0, 1)]] | ||
self.cube._cell_measures_and_dims, [(self.b_cell_measure, (0, 1))] | ||
) | ||
|
||
def test_fail_remove_cell_measure_by_name(self): | ||
|
@@ -2206,5 +2212,99 @@ def test_data_bool_not_eq(self): | |
self.assertFalse(cube1 == cube2) | ||
|
||
|
||
class Test__eq__meta(tests.IrisTest): | ||
def test_ancillary_fail(self): | ||
cube1 = Cube([0, 1]) | ||
cube2 = Cube([0, 1]) | ||
avr = AncillaryVariable([2, 3], long_name="foo") | ||
cube2.add_ancillary_variable(avr, 0) | ||
self.assertFalse(cube1 == cube2) | ||
|
||
def test_ancillary_reorder(self): | ||
cube1 = Cube([0, 1]) | ||
cube2 = Cube([0, 1]) | ||
avr1 = AncillaryVariable([2, 3], long_name="foo") | ||
avr2 = AncillaryVariable([4, 5], long_name="bar") | ||
# Add the same ancillary variables to cube1 and cube2 in | ||
# opposite orders. | ||
cube1.add_ancillary_variable(avr1, 0) | ||
cube1.add_ancillary_variable(avr2, 0) | ||
cube2.add_ancillary_variable(avr2, 0) | ||
cube2.add_ancillary_variable(avr1, 0) | ||
self.assertTrue(cube1 == cube2) | ||
|
||
def test_ancillary_diff_data(self): | ||
cube1 = Cube([0, 1]) | ||
cube2 = Cube([0, 1]) | ||
avr1 = AncillaryVariable([2, 3], long_name="foo") | ||
avr2 = AncillaryVariable([4, 5], long_name="foo") | ||
cube1.add_ancillary_variable(avr1, 0) | ||
cube2.add_ancillary_variable(avr2, 0) | ||
self.assertFalse(cube1 == cube2) | ||
|
||
def test_cell_measure_fail(self): | ||
cube1 = Cube([0, 1]) | ||
cube2 = Cube([0, 1]) | ||
cms = CellMeasure([2, 3], measure="area", long_name="foo") | ||
cube2.add_cell_measure(cms, 0) | ||
self.assertFalse(cube1 == cube2) | ||
|
||
def test_cell_measure_reorder(self): | ||
cube1 = Cube([0, 1]) | ||
cube2 = Cube([0, 1]) | ||
cms1 = CellMeasure([2, 3], measure="area", long_name="foo") | ||
cms2 = CellMeasure([4, 5], measure="area", long_name="bar") | ||
# Add the same cell measure to cube1 and cube2 in | ||
# opposite orders. | ||
cube1.add_cell_measure(cms1, 0) | ||
cube1.add_cell_measure(cms2, 0) | ||
cube2.add_cell_measure(cms2, 0) | ||
cube2.add_cell_measure(cms1, 0) | ||
self.assertTrue(cube1 == cube2) | ||
|
||
def test_cell_measure_diff_data(self): | ||
cube1 = Cube([0, 1]) | ||
cube2 = Cube([0, 1]) | ||
cms1 = CellMeasure([2, 3], measure="area", long_name="foo") | ||
cms2 = CellMeasure([4, 5], measure="area", long_name="foo") | ||
cube1.add_cell_measure(cms1, 0) | ||
cube2.add_cell_measure(cms2, 0) | ||
self.assertFalse(cube1 == cube2) | ||
|
||
def test_cell_method_fail(self): | ||
cube1 = Cube([0, 1]) | ||
cube2 = Cube([0, 1]) | ||
cmth = CellMethod("mean", "time", "6hr") | ||
cube2.add_cell_method(cmth) | ||
self.assertFalse(cube1 == cube2) | ||
|
||
# Unlike cell measures, cell methods are order sensitive. | ||
def test_cell_method_reorder_fail(self): | ||
cube1 = Cube([0, 1]) | ||
cube2 = Cube([0, 1]) | ||
cmth1 = CellMethod("mean", "time", "6hr") | ||
cmth2 = CellMethod("mean", "time", "12hr") | ||
# Add the same cell method to cube1 and cube2 in | ||
# opposite orders. | ||
cube1.add_cell_method(cmth1) | ||
cube1.add_cell_method(cmth2) | ||
cube2.add_cell_method(cmth2) | ||
cube2.add_cell_method(cmth1) | ||
self.assertFalse(cube1 == cube2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we have a successful comparison with cell-methods here, or is that covered somewhere else ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is capturing the behaviour mentioned in the comments on #3530. Adding cell_methods in different orders should cause equality to fail. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Misunderstanding I think ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, yeah, that sounds appropriate. |
||
|
||
def test_cell_method_correct_order(self): | ||
cube1 = Cube([0, 1]) | ||
cube2 = Cube([0, 1]) | ||
cmth1 = CellMethod("mean", "time", "6hr") | ||
cmth2 = CellMethod("mean", "time", "12hr") | ||
# Add the same cell method to cube1 and cube2 in | ||
# the same order. | ||
cube1.add_cell_method(cmth1) | ||
cube1.add_cell_method(cmth2) | ||
cube2.add_cell_method(cmth1) | ||
cube2.add_cell_method(cmth2) | ||
self.assertTrue(cube1 == cube2) | ||
|
||
|
||
if __name__ == "__main__": | ||
tests.main() |
Uh oh!
There was an error while loading. Please reload this page.