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: ma.testutils.assert_equal on nans throws AssertionError #6661 #6871
Conversation
@@ -121,7 +121,11 @@ def assert_equal(actual, desired, err_msg=''): | |||
raise AssertionError("%s not in %s" % (k, actual)) | |||
assert_equal(actual[k], desired[k], 'key=%r\n%s' % (k, err_msg)) | |||
return | |||
# Case #2: lists ..... | |||
# Case #2: nan | |||
if isinstance(actual, float) and isinstance(desired, float) and \ |
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.
Use (...)
instead of line continuation here.
Oh, this is a horrible, horrible function. Let me think about it... |
Ok, either way that should be a minor change to make. The reason I elected to go for the line continuation was matching the style used in line 137. And yeah, this function is... interesting. Would it be worth adding unit tests for |
Note xor with two booleans is Yes, a test would be highly desirable, required even ;) |
Here is equivalent
Note that unicode strings are not handled (python 3) and I'm not clear on why the special casing unless there is (was) a problem with fill value. Should be able to use an empty string for masked fill values I think, but currently maskled string arrays use "N/A". We should consider changing that. |
Ok, thanks! Should I use that as a refactored base to make my changes on top of? |
It needs some filling out with error messages and such, it is a stripped down version. I think it should solve your problem as is, delegating it to the unmasked version. Writing some tests first would be good. The string problem needs an enhancement. I think we should be using an empty string in those cases. |
I think the strings can be handled like so.
|
Ah alright, perfect! Thanks for the help, I'll try my hand at implementing the described changes! |
Should I push my commits directly to this branch, or would the refactoring indicate that I should do this as a separate PR? |
Just push to your branch. When everything is ready, you can squash your commits together and rewrite the first commit message to match format in http://docs.scipy.org/doc/numpy-1.10.1/dev/gitwash/development_workflow.html, followed by a force push |
Previously, np.ma.testutils.assert_equal failed for two nans. The new functionality more closely mirrors np.testing.assert_equal, and is logically more correct. Refactored code to be more legible and concise. Added tests for np.ma.testutils.assert_equal. Had to modify np.testing.assert_equal to keep np.ma.testutils.assert_equal working properly.
@charris Could you re-review this? I think I've gotten it into a pretty good state. |
@charris Should I recreate this PR or will it still be reviewed? I know it's far enough down in the listed PRs now that it has the potential to be skipped over easily. |
@@ -347,6 +347,8 @@ def assert_equal(actual,desired,err_msg='',verbose=True): | |||
try: | |||
# isscalar test to check cases such as [np.nan] != np.nan | |||
if isscalar(desired) != isscalar(actual): | |||
if desired == actual: |
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.
Why is this needed?
I'll need to take a closer look, I note that you did things differently than suggested, so I need to restudy the problem. |
@@ -91,6 +91,21 @@ def _assert_equal_on_sequences(actual, desired, err_msg=''): | |||
return | |||
|
|||
|
|||
def _assert_equal_both_non_masked(actual, desired, err_msg=''): |
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 don't think this should be a separate function, it makes the code harder to follow and is only used once.
Close and reopen to see if tests of unsupported Python versions go away. Otherwise may need a rebase on master |
@mcdaniel67 Needs to be finished. |
☔ The latest upstream changes (presumably #7099) made this pull request unmergeable. Please resolve the merge conflicts. |
Fixes #6661 and makes
np.ma.testutils.assert_equal
's functionality more closely matchnp.testing.assert_equal
Previous Functionality:
Modified Functionality: