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: stats: wrong shape from median_absolute_deviation for arrays with size 0 and an axis. #11720

Closed
WarrenWeckesser opened this issue Mar 24, 2020 · 2 comments · Fixed by #11735
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.stats
Milestone

Comments

@WarrenWeckesser
Copy link
Member

WarrenWeckesser commented Mar 24, 2020

Currently, median_absolute_deviation returns the scalar nan if the size of the input array is 0, even if an axis argument is given. This is not correct. The function must respect the reduction-like behavior for the shape of the arrays. For example, if x has shape (m, n, p) and axis=1, the shape of the result must be (m, p), even if any of m, n, or p are 0.

For example,

In [21]: z = np.ones((3, 0))                                                                                            

Here, just like n.sum(z, axis=0), the result should be an array with shape (0,), but in the master branch, we incorrectly get the scalar nan:

In [22]: median_absolute_deviation(z, axis=0)  # from the master branch, not correct!
Out[22]: nan

With axis=1, the result should be an array with shape (3,). The values in the array should be the same as the value produced by median_absolute_deviation([]), which is nan, so the actual result should be array([nan, nan, nan]). But in the master branch, the behavior is again incorrect--instead of getting the array with shape (3,), we get the scalar nan:

In [23]: median_absolute_deviation(z, axis=1)  # from the master branch, not correct!
Out[23]: nan

The above code was function with the current master branch:

In [28]: import scipy

In [29]: scipy.__version__
Out[29]: '1.5.0.dev0+69f44c0'
@WarrenWeckesser WarrenWeckesser added defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.stats labels Mar 24, 2020
@rgommers rgommers added this to the 1.5.0 milestone Mar 28, 2020
@WarrenWeckesser
Copy link
Member Author

gh-11735 wasn't a complete fix, so I'm reopening the issue.

@WarrenWeckesser
Copy link
Member Author

This was fixed in #11431. median_absolute_deviation is now deprecated, but it does give the correct results for arrays with size 0.

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
3 participants