FIX: scipy.stats.mstats.kurtosis() throwing ValueError #391

Closed
wants to merge 2 commits into
from

Projects

None yet

3 participants

@trueprice
Contributor

Fixed a bug in scipy.stats.mstats.kurtosis() that caused a ValueError to be
thrown when bias=False. In the same context, fixed a TypeError that was being
thrown for one-dimensional input where all elements are masked.

Appropriate tests have been added to the testing suite for the function.

Relates to ticket: http://projects.scipy.org/scipy/ticket/1798

@josef-pkt josef-pkt commented on the diff Dec 24, 2012
scipy/stats/mstats_basic.py
m2 = moment(a,2,axis)
m4 = moment(a,4,axis)
vals = ma.where(m2 == 0, 0, m4/ m2**2.0)
if not bias:
- can_correct = (n > 3) & (m2 > 0)
+ n = a.count(axis)
+ can_correct = (n > 3) & (m2 is not ma.masked and m2 > 0)
josef-pkt
josef-pkt Dec 24, 2012 Member

why is m2 is not ma.masked necessary?
It's a bool not a boolean array.

Member

Looks good to me.

(We get a masked value back if there are no valid values. I didn't read this correctly initially.)

Owner

@trueprice you explicitly set your email address to an empty string, which trips up git am (and probably other git commands). If you don't want your real email address displayed, you can put in a fake one in - you can also link that to your Github account like so: https://help.github.com/articles/keeping-your-email-address-private

Could you please add an email address to the above commit? You then have to force-push it to the branch you made the PR from (git push origin master -f).

@trueprice trueprice Fixed a bug in scipy.stats.mstats.kurtosis() that caused a ValueError…
… to be

thrown when bias=False. In the same context, fixed a TypeError that was being
thrown for one-dimensional input where all elements are masked.

Appropriate tests have been added to the testing suite for the function.

Fixed a bug in scipy.stats.mstats.kurtosis() that caused a ValueError to be
thrown when bias=False. In the same context, fixed a TypeError that was being
thrown for one-dimensional input where all elements are masked.

Appropriate tests have been added to the testing suite for the function.

Relates to ticket: http://projects.scipy.org/scipy/ticket/1798
0f859ee
Contributor

Ok, fixed! For the record, when I tried using user@server.fake as my email, github showed my commit as a different user...

Owner

Thanks, that works now. Fix and tests look good.

I added a test, silenced a warning that was printed and changed a few things in the tests: https://github.com/rgommers/scipy/tree/pull-391-mstats
Could you have a quick look at that to see if that makes sense?

@trueprice trueprice Added RuntimeWarning suppression in scipy.stats.kurtosis for one-dime…
…nsional

input having a second moment equal to zero (i.e. m2==0).
bf788cf
Contributor

Great! The changes make sense to me. I'll point out that the warning you silenced also occurs in the unmasked kurtosis function, e.g.:

scipy.stats.kurtosis([0,0,0,0,0])
/usr/lib64/python2.6/site-packages/scipy/stats/stats.py:1078: RuntimeWarning: invalid value encountered in double_scalars
vals = np.where(zero, 0, m4/ m2**2.0)
-3.0

So, I added the same silencing to scipy.stats.kurtosis.

Owner

Merged in b69fe18. Thanks @trueprice.

@rgommers rgommers closed this Dec 26, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment