-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
[BUG] Fix bug in trimr when inclusive=False #10549
Conversation
x = ma.arange(10) | ||
result = mstats.trimr(x, limits=(0.15, 0.14), inclusive=(False, False)) | ||
expected = [None, None, 2, 3, 4, 5, 6, 7, 8, None] | ||
assert_equal(result, expected) |
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.
result
is a masked array, apparently the comparison in assert_equal
with the list works. I did not check in the other Tests: is that the standard way to write the test cases for masked arrays?
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.
I follow the format in test_trim
to write the present test.
assert_equal
is stricter than other test utilities such as assert_almost_equal
.
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.
iirc numpy test functions had stuff in them for masked array handling, and will cast inputs to ndarrays if either one is
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.
Actually, not exactly:
>>> x = np.ma.array([1,2,3,4,5], dtype=int, mask=[0,0,0,1,0])
>>> numpy.testing.assert_equal(x, [1,2,3,None,5])
>>> numpy.testing.assert_equal(x, [1,2,3,4,5])
>>> numpy.testing.assert_equal(x, [1,2,3,999,5])
It won't check that the mask is correct, so this test should check the mask separately (which some of the tests above do).
result = mstats.trimr(x, limits=(0.15, 0.14), inclusive=(False, False)) | ||
expected = ma.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], | ||
mask=[1, 1, 0, 0, 0, 0, 0, 0, 0, 1]) | ||
pytest.set_trace() |
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.
Forgot set_trace here
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.
Test looks good now, waiting for @pv to confirm
when
inclusive=False
,mstats.trimr
runs intoTypeError
i.e.,TypeError: slice indices must be integers or None or have an __index__ method
.