-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
support axis=None for nanmedian ( issue #7352 ) #7440
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
Conversation
I have added a fix (hopefully) for the rounding errors |
@@ -118,11 +120,39 @@ def check_results(self, targ, res, axis): | |||
res = getattr(res, 'values', res) | |||
if axis != 0 and hasattr(targ, 'shape') and targ.ndim: | |||
res = np.split(res, [targ.shape[0]], axis=0)[0] | |||
tm.assert_almost_equal(targ, res) | |||
try: |
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.
you can just pass check_less_precise=True
if its a complex number (or explicty astype before the comparison)
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 tried that, it doesn't fix the problem. It still raises an AssertionError even if they only differ in their 16th digit.
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.
>>> a=np.array([1+.1111111111111111*1j])
>>> b=np.array([1+.1111111111111112*1j])
>>> tm.assert_almost_equal(a, b, check_less_precise=True)
AssertionError: (1+0.1111111111111111j) != (1+0.1111111111111112j)
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.
compare the real and imag pars separately and then it works correctly. side issue is to patch tm.assert_almost_equal
to deal with complex numbers by this method
In [1]: a=np.array([1+.1111111111111111*1j])
In [2]: b=np.array([1+.1111111111111112*1j])
In [4]: tm.assert_almost_equal(a.real, b.real)
Out[4]: True
In [5]: tm.assert_almost_equal(a.imag, b.imag)
Out[5]: True
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.
Done.
support axis=None for nanmedian ( issue #7352 )
thanks! |
@toddrjen a bunch of tests failing on windows. I debugged one of them below. If you can debug this would be great.
|
The problem seems to be that the values are getting converted to a python long instead of a numpy scalar. The workaround is easy, I can either include it in a separate patch or as part of the next one. But could you also try the following code and see what you get? a=np.zeros(11).astype('bool')
b=a.shape[0] - a.sum(0)
type(b) I have tried this on linux, winpython3 x64, and pythonxy and in all of them I get |
At least looking at the last error, for nanskew, it doesn't appear that I have touched any of the code in that code path, so this doesn't seem to be a new bug. |
All of the errors are related to the changes for
|
There were no changes to _get_counts. Looking at the blame, it hasn't been touched since 2011. |
it wasn't broken before I merged your first PR. |
The first version of |
ok, its a problem now. pls have a look. |
This fixes #7352, where
nanmedian
does not work whenaxis==None
.