Skip to content
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: skew, kurtosis return np.nan instead of "propagate" #5817

Closed
josef-pkt opened this issue Feb 7, 2016 · 4 comments · Fixed by #5970
Closed

BUG: skew, kurtosis return np.nan instead of "propagate" #5817

josef-pkt opened this issue Feb 7, 2016 · 4 comments · Fixed by #5970
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.stats
Milestone

Comments

@josef-pkt
Copy link
Member

Initial guess

I thought "propagate" just calculates with nans in the arrays, like np.sum, so we get the correct shape with just some extra nans.

Instead we get a scalar nan back
https://github.com/scipy/scipy/blame/v0.17.0/scipy/stats/stats.py#L1319

possible candidate for
statsmodels/statsmodels#2800

>>> aa = np.arange(5 * 4.).reshape(5,4)
>>> aa[0,1] = np.nan
>>> np.sum(aa, 0)
array([ 40.,  nan,  50.,  55.])
>>> from scipy import stats
>>> stats.kurtosis(aa, axis=0)
array([-1.3,  nan, -1.3, -1.3])
>>> stats.skew(aa, axis=0)
array([  0.,  nan,   0.,   0.])
>>> scipy.__version__
'0.15.1'
@josef-pkt
Copy link
Member Author

The actual problem for the statsmodels case seems to be scalar versus array return

continued example
1-d versus 2d inputs

>>> stats.skew(aa[0], axis=0)
nan
>>> stats.skew(aa[1], axis=0)
0.0

>>> stats.skew(aa[:1], axis=1)
array([ nan])
>>> stats.skew(aa[1:2], axis=1)
array([ 0.])


>>> np.sum(aa[1], axis=0)
22.0
>>> np.sum(aa[1:2], axis=1)
array([ 22.])

>>> np.sum(aa[0], axis=0)
nan
>>> np.sum(aa[:1], axis=1)
array([ nan])

@rgommers rgommers added the defect A clear bug or issue that prevents SciPy from being installed or used as expected label Feb 7, 2016
@rgommers rgommers added this to the 0.18.0 milestone Feb 7, 2016
@rgommers
Copy link
Member

rgommers commented Feb 7, 2016

That's indeed a regression that needs fixing. I thought we had not merged one PR yet with the functions that suffered from this, but apparently we missed one.

@josef-pkt
Copy link
Member Author

This seems to be a pattern that has been added to several reduce functions
73c4f62

I think statsmodels is also using normaltest, skewtest and kurtosistest, but in general we are not supposed to have nans in the calculated data, so there are no broken test cases.

@ev-br
Copy link
Member

ev-br commented Feb 28, 2016

I'll change the milestone to 0.17.1 because this functionality is new in 0.17.0 so it could be good to have it fixed in the 0.17.x series.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.stats
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants