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: fix ma.median for empty ndarrays #8705

Merged
merged 1 commit into from
Feb 27, 2017

Conversation

juliantaylor
Copy link
Contributor

return nan as it did in 1.11 and same as normal median.
closes gh-8703

@juliantaylor juliantaylor added this to the 1.12.1 release milestone Feb 27, 2017
@juliantaylor
Copy link
Contributor Author

juliantaylor commented Feb 27, 2017

returning a masked nan would make more sense to me, but should we change the behaviour instead of keeping the old?

@juliantaylor juliantaylor added the 09 - Backport-Candidate PRs tagged should be backported label Feb 27, 2017
@mhvk
Copy link
Contributor

mhvk commented Feb 27, 2017

Agreed that a masked nan might be more logical, but since np.ma.mean also just returns nan, it is probably best to keep the behaviour as is.

@eric-wieser
Copy link
Member

eric-wieser commented Feb 27, 2017

Not a huge fan of this special-casing of index building

Can we just do something like:

indexer = [slice(None)] * asorted.ndim
if asorted.shape[axis] == 0:
    indexer[axis] = []
elif asorted.shape[axis] % 2 == 1:
    indexer[axis] = [h]
else:
    indexer[axis] = [h-1, h]

# ....

return np.ma.mean(asorted[indexer], axis=axis)

Edit: no, that doesn't work since the counts are different on each dimension

@eric-wieser
Copy link
Member

eric-wieser commented Feb 27, 2017

I think I meant:

indexer = np.ix_(*(np.arange(x) for x in asorted.shape))
if asorted.shape[axis] == 0:
    indexer[axis] = # empty of the right shape
elif:
    indexer[axis] = np.stack([h-1, h], axis=axis)

return nan as it did in 1.11 and same as normal median.
closes numpygh-8703
@eric-wieser
Copy link
Member

What does this return for a fully-masked matrix? nan or masked?

@juliantaylor
Copy link
Contributor Author

hm right you can index with mixed slices and indices, might be nicer

it returns unmasked nan array of the input shape % the reduced axis

@eric-wieser
Copy link
Member

eric-wieser commented Feb 27, 2017

hm right you can index with mixed slices and indices, might be nicer

Doesn't work when indexing both h and h-1 and the same time. But I'd replace the empty slice with a empty array, for consistency. So remove all the slices, rather than all the arrays

@juliantaylor
Copy link
Contributor Author

not really nicer due to the way the mean works at the end, which is ugly but I don't really want to change it for a bugfix

@eric-wieser
Copy link
Member

Fair enough, I might do some maintenance on this another time

@eric-wieser
Copy link
Member

@juliantaylor: re index-building, #8708

@charris charris removed this from the 1.12.1 release milestone Mar 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

masked median of empty dimension fails
4 participants