-
Notifications
You must be signed in to change notification settings - Fork 316
Changed to auto convert from aux to dim coord #1039
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
Changes from 3 commits
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # (C) British Crown Copyright 2010 - 2013, Met Office | ||
| # (C) British Crown Copyright 2010 - 2014, Met Office | ||
| # | ||
| # This file is part of Iris. | ||
| # | ||
|
|
@@ -81,11 +81,18 @@ def test_no_dim(self): | |
| self.cube.add_dim_coord, | ||
| iris.coords.DimCoord(np.arange(2), "latitude")) | ||
|
|
||
| def test_adding_aux_coord(self): | ||
| coord = iris.coords.AuxCoord(np.arange(2), "latitude") | ||
| def test_adding_nonmonotonic_aux_coord(self): | ||
| coord = iris.coords.AuxCoord([0, 1, 1, 2], "latitude") | ||
|
Member
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. Can you also add a new test that exercises the new functionality. Check that a strictly monotonic AuxCoord can be accepted and also check the warning is raised perhaps. |
||
| with self.assertRaises(ValueError): | ||
| self.cube.add_dim_coord(coord, 0) | ||
|
|
||
| def test_adding_aux_coord(self): | ||
| try: | ||
| coord = iris.coords.AuxCoord(np.arange(2), "latitude") | ||
| self.cube.add_dim_coord(coord, 0) | ||
| except ValueError as e: | ||
|
Member
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 doesn't look right. You don't need the try/except block, if the code you are testing raises an exception then the test will fail anyway. It'd be nice to check that a warning is issued too. I'm not sure what the current best practice for doing this in Iris is (it can be non-trivial). I think @pelson did something like this recently... I may be wrong though.
Contributor
Author
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. That's how I originally had it but I thought that would be bad practise - i.e. an error is different from a fail. If that's considered acceptable in iris testing then I'll change it back.
Member
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. You should also be checking that the coordinate was added correctly, sorry I forgot to say that before, but it is very important! I didn't explain myself very well, sorry for confusion. We shouldn't really be testing for errors like this, we should be testing the result of the code. When the code as you called it is functioning correctly no error will be raised, which means you don't need to allow for that in the test. The test should aim to capture changes in behaviour (i.e. the resulting coordinate) rather than an error, so an error shouldn't result in a test fail. If the code somehow gets broken so that this usage becomes an error then we will still be notified, but the test suite will report an error, rather than a fail, and this is OK.
Contributor
Author
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.
OK - I think I see what you mean. New test coming up.
Member
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.
Awesome, because I don't think I explained it well that time either. I should have said before, you already have an explicit test for the error condition, so for any other tests you should assume this condition is not met and your bases are still covered. |
||
| self.fail(str(e)) | ||
|
|
||
|
|
||
| class TestEquality(tests.IrisTest): | ||
| def test_not_implmemented(self): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What extra information is contained in
str(e)(not necessarily a criticism, I'm at a windows machine so I can't check myself)?If it doesn't add much useful I'd say ditch it and go for a more descriptive static message. On the flip side, if
ealready contains a descriptive message that is good to use as is then we don't even necessarily have to re-raise it...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ValueError: Could not convert coord to DimCoord: The points array must be strictly monotonic.Probably worth keeping, do you think? Could do with being changed from a colon after DimCoord thought
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, then I guess what I want to know is will it ever be anything other than that? If not then you could just write that... If it can be one of any number of things then maybe this is OK.