Skip to content
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

Use np.ma.is_masked() instead of isinstance(MaskedArray) in tests #2477

Merged
merged 3 commits into from
Apr 6, 2017

Conversation

djkirkham
Copy link
Contributor

Due to some changes in Numpy 1.12, some aggregator functions in np.ma return a MaskedArray instance with no mask rather than an ndarray. This causes some of our tests to fail which do an instance check for a MaskedArray.

I've modified the checking code to use np.ma.is_masked(), but this causes other tests to fail where the array being checked has always been a MaskedArray instance with no mask (thus, the reference file claims it is masked when it isn't). Commit dfa75a3 demonstrates this - see the Travis test failures. Note that because some tests contain multiple checks, not all of the checks which would fail are listed in the output.

@djkirkham djkirkham force-pushed the is_masked-check branch 2 times, most recently from 75b3dee to de8e390 Compare April 5, 2017 17:52
@marqh
Copy link
Member

marqh commented Apr 6, 2017

thank you @djkirkham

this is a better test pattern, I think, asking whether the data is masked, rather than checking if it's type is 'maskedarray'

the only changes here are test results which were not masked, but were of masked array type, so this is a testing pattern change only

@marqh marqh merged commit e0b671c into SciTools:master Apr 6, 2017
@@ -421,7 +421,7 @@ def assertDataAlmostEqual(self, data, reference_filename, **kwargs):
stats = json.load(reference_file)
self.assertEqual(stats.get('shape', []), list(data.shape))
self.assertEqual(stats.get('masked', False),
isinstance(data, ma.MaskedArray))
np.ma.is_masked(data))
Copy link
Member

Choose a reason for hiding this comment

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

@djkirkham We have a soft coding standard where we use ma instead of np.ma, see here.

If it's not too much trouble, could you adopt this please, thanks.

('min', np.float_(data.min())),
('max', np.float_(data.max())),
('shape', data.shape),
('masked', np.ma.is_masked(data)),
Copy link
Member

Choose a reason for hiding this comment

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

@djkirkham Here is well ... np.ma.is_masked(data) -> ma.is_masked(data)

@QuLogic QuLogic added this to the v2.0 milestone Apr 10, 2017
@QuLogic QuLogic modified the milestones: v1.13.0, v2.0 May 17, 2017
bjlittle added a commit to bjlittle/iris that referenced this pull request Jun 5, 2017
@djkirkham djkirkham deleted the is_masked-check branch October 26, 2017 13:02
@djkirkham djkirkham restored the is_masked-check branch October 26, 2017 13:02
@djkirkham djkirkham deleted the is_masked-check branch October 26, 2017 13:02
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.

4 participants