Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/iris/tests/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ def test_constraints(self):
sub_list = self.slices.extract(constraint)
self.assertEqual(len(sub_list), 70 * 6)

def test_coord_availability(self):
constraint = iris.Constraint(model_level_number=lambda x: True)
result = self.slices.extract(constraint)
self.assertTrue(result)

constraint = iris.Constraint(latitude=lambda x: False)
result = self.slices.extract(constraint)
self.assertFalse(result)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@rcomer This is a negative test i.e., the latitude coordinate is not in any of the self.slices CubeList, so the result is empty

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Huh. Now I'm confused. Because the pattern is lambda x: False, I assumed it was the other way around. I.e. I thought the constraint was asking for cubes that don't have it, but they all do. Looking at the actual stock.realistic_4d cube, they clearly won't.

< Had a play >

The result is the same whether you say lambda x: True or lambda x: False? 🤯

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Hmm, no. I think lambda x: False always gives an empty list.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

In [30]: slices.extract(iris.Constraint(grid_latitude=lambda x: False))
Out[30]: []


def test_mismatched_type(self):
constraint = iris.Constraint(model_level_number="aardvark")
sub_list = self.slices.extract(constraint)
Expand Down