API: Partially revert unique with return_inverse #26914
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a good argument that it is not possible to reconstruct the original array with
axis=None
without first reshaping and changing the result shape helped with it.However, it was always possible to do it for other axis values by using
np.take
rather thannp.take_along_axis
. Changing it for all axis values is unnecessary to achieve reconstruction becausenp.take(arr, inverse, axis=axis)
already performed the job except foraxis=None
.Thus, this keeps the change for axis=None, but reverts gh-25553 for numerical axis.
I tried to go through some of the linked PRs, I extremely rough estimate is that at least 2/3 of the time, this would have save a code change. There are a few others that just need flattened (scipy because of a later call, sklearn/cuml because they use a view trick assuming the result is 1-D when it is not). So in many (I am sure not all), of the cases where this doesn't avoid a regression, it is very clean to reshape explicitly.
@charris I am not sure about release notes for 2.0.1, I don't think we incorporate the fragments, but this one might be worth stressing slightly more. I thought I'd add a
note
to the old release notes (even if we may not rebuild them for a while).