-
Notifications
You must be signed in to change notification settings - Fork 300
Improve gracefully filling warning #3171
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 4 commits
4a166cd
52331d2
be08462
7f0e676
9c56b8a
c86b5a7
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 2014 - 2015, Met Office | ||
| # (C) British Crown Copyright 2014 - 2018, Met Office | ||
| # | ||
| # This file is part of Iris. | ||
| # | ||
|
|
@@ -112,6 +112,60 @@ def test_dim_coord_construction(self): | |
| self.engine.cube.add_dim_coord.assert_called_with( | ||
| expected_coord, [0]) | ||
|
|
||
| def test_dim_coord_construction_masked_array(self): | ||
| self._set_cf_coord_var(np.ma.array( | ||
| np.arange(6), | ||
| mask=[True, False, False, False, False, False], | ||
| fill_value=-999, | ||
| )) | ||
|
|
||
| expected_coord = DimCoord( | ||
| np.array([-999, 1, 2, 3, 4, 5]), | ||
| long_name=self.cf_coord_var.long_name, | ||
| var_name=self.cf_coord_var.cf_name, | ||
| units=self.cf_coord_var.units, | ||
| bounds=self.bounds) | ||
|
|
||
| with warnings.catch_warnings(record=True) as w: | ||
| # Asserts must lie within context manager because of deferred | ||
| # loading. | ||
| with self.deferred_load_patch, self.get_cf_bounds_var_patch: | ||
| build_dimension_coordinate(self.engine, self.cf_coord_var) | ||
|
|
||
| # Test that expected coord is built and added to cube. | ||
| self.engine.cube.add_dim_coord.assert_called_with( | ||
| expected_coord, [0]) | ||
|
|
||
| # Assert warning is raised | ||
| assert len(w) == 1 | ||
| assert 'Gracefully filling' in w[0].message.args[0] | ||
|
|
||
| def test_dim_coord_construction_masked_array_mask_does_nothing(self): | ||
| self._set_cf_coord_var(np.ma.array( | ||
| np.arange(6), | ||
| mask=False, | ||
| )) | ||
|
|
||
| expected_coord = DimCoord( | ||
| self.cf_coord_var[:], | ||
| long_name=self.cf_coord_var.long_name, | ||
| var_name=self.cf_coord_var.cf_name, | ||
| units=self.cf_coord_var.units, | ||
| bounds=self.bounds) | ||
|
|
||
| with warnings.catch_warnings(record=True) as w: | ||
| # Asserts must lie within context manager because of deferred | ||
| # loading. | ||
| with self.deferred_load_patch, self.get_cf_bounds_var_patch: | ||
| build_dimension_coordinate(self.engine, self.cf_coord_var) | ||
|
|
||
| # Test that expected coord is built and added to cube. | ||
| self.engine.cube.add_dim_coord.assert_called_with( | ||
| expected_coord, [0]) | ||
|
|
||
| # Assert no warning is raised | ||
| assert len(w) == 0 | ||
|
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. These new tests look great – but would you mind adding testing that covers the cases where the incoming coordinate has masked bounds? Thanks!
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. have a look now, I think this is what you wanted? |
||
|
|
||
| def test_aux_coord_construction(self): | ||
| # Use non monotonically increasing coordinates to force aux coord | ||
| # construction. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.