BUG: Identified bug with numpy 1.7 ufunc operators#1052
Conversation
|
Ready for review |
|
Is there also a numpy PR to fix the underlying issue? |
|
I see it is number 4425 on the numpy github tracker. |
There was a problem hiding this comment.
Renaming add as op obfuscates what's going on. Especially as op has the same name as self.op.
There was a problem hiding this comment.
In fact, there's no real need for the from ... syntax. Just import operator and then later return operator.add would be even more clear.
|
Thanks both. Made the changes requested, ready for review.
Sry @pelson, I can confirm its numpy/numpy#4425 |
|
bump |
|
Just picking this up, more to come...
I'm inclined to agree. |
|
The use of abstract classes deriving from unittest.TestCase can cause problems because unittest (though not nose, I think) will try to run them. Problem is discussed here -- http://stackoverflow.com/questions/4566910/abstract-test-case-using-python-unittest We already have some tests that fix this by using multiple-inheritance |
There was a problem hiding this comment.
Abstract test classes can cause problems when running via unittest -- see separate comment #1052 (comment)
|
Something is wrong here, because when I try to run the tests on the earlier master commit that this branch is based from, I don't get the expected masked data error but I do get a spurious error in a different test (which think I have traced + will explain later...). Bear with me, this is awkwardly complex to demonstrate, but here goes ... First check what test results are in the current branch. NOW revert to the master version preceding your changes, but "patch in" your newly added tests ... Sorry for the mess!! (this would be much easier with tests in a separate repo) NOW run the pasted-in tests again... NOTE IN PARTICULAR ASIDE: The test that did fail is actually the wrong one. |
There was a problem hiding this comment.
The presence of the '_div' in the name is misleading.
|
I'm thoroughly confused now, still not sure why your tests are not working as advertised. with old iris : last result is different -- |
|
NOTE: I was going to suggest that the 4 separate copycat tests seem awkward, but I see we have to do it this way to satisfy the test structure rules. I also wondered whether it can all be done in the lower reaches of the code (ideally in maths._math_op_common), but I think I'm satisifed that doesn't work and we do need to modify each of maths.add/subtract/divide/multiply. Shame ! 😞 |
|
Over to you -- get the tests working properly + we'll see what it looks like then. |
This effects binary operators (add, subtract, division and multiply) onlt.
|
Thanks @pp-mo, back to you. |
There was a problem hiding this comment.
On checking this against the "old" version again, I found this has "introduced" a bug.
I say "introduced" because really the code was already wrong to be using array[~array.mask], as it does not do the expected when the mask is a pure boolean instead of an array.
I think my preferred solution would be to use full mask arrays if not insisting on exact equality (i.e. "strict=False").
I.E. something like this ...
* strict (bool):
If True, perform a complete mask and data array equality check.
If False (default), the masks are compared as full arrays and the
data array comparison includes only the unmasked elements.
"""
if strict:
np.testing.assert_array_equal(a.mask, b.mask)
np.testing.assert_array_equal(a.data, b.data)
else:
a_mask, b_mask = ma.getmaskarray(a), ma.getmaskarray(b)
np.testing.assert_array_equal(a_mask, b_mask)
np.testing.assert_array_equal(a[~a_mask].data, b[~b_mask].data)
I tested this and it seems to deliver the goods, i.e. behaviour like ...
between...
ma.array([1,2], mask=False)andma.array([1,2], mask=[False, False])
...compare result, strict = True/False --> FAIL / OK
Of course, all of this applies equally to "assertMaskedArrayAlmostEqual" (the very next thing)
|
I would like to pull away the bug-fixing of the masked array comparison if possible: |
Thanks @cpelley - highly commendable ! I was wondering whether to suggest this anyway, but I thought it might be asking too much. |
Provides testing framework for iris math operators.
Also provides workaround for bug present in numpy ufunc.
https://groups.google.com/forum/#!topic/scitools-iris/WvGKWUGne00
Numpy issue raised:
numpy/numpy#4425