Skip to content

Conversation

@bjlittle
Copy link

@bjlittle bjlittle commented Dec 7, 2020

@rcomer Apologies for dragging my heels on this one... spinning too many plates as usual.

I guess something along the following lines should be sufficient to give a nod to this particular pattern of constrains usage.

Let me know what you think :-)

@rcomer
Copy link
Owner

rcomer commented Dec 7, 2020

Thanks @bjlittle, looks good! Is is also worth having the negative result using a spurious coord name? So like iris.Constraint(wibble=lambda x: True) should give an empty cubelist. Or is that overkill? I don't know anything about the inner workings of constraints...

I can easily add it myself after after merge if you are 👍

Comment on lines 76 to 78
constraint = iris.Constraint(latitude=lambda x: False)
result = self.slices.extract(constraint)
self.assertFalse(result)
Copy link
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
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
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
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]: []

@rcomer rcomer merged commit 5cbe12d into rcomer:gallery-seasonal-ensemble Dec 7, 2020
@rcomer
Copy link
Owner

rcomer commented Dec 7, 2020

Thanks @bjlittle 😁

@bjlittle bjlittle deleted the gallery-constraint-test branch February 15, 2021 13:32
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