-
Notifications
You must be signed in to change notification settings - Fork 285
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
Conversation
…st failures are incorrect
75b3dee
to
de8e390
Compare
de8e390
to
64f195b
Compare
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 |
@@ -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)) |
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.
@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)), |
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.
@djkirkham Here is well ... np.ma.is_masked(data)
-> ma.is_masked(data)
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.