Split unique
into separate functions
#275
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.
This PR
resolves gh-212 by splitting
unique
into separate functions with a fixed number of arguments, thus addressing the concerns regardingunique
's polymorphic behavior.splits
unique
in the following functions:unique_all(x, /)
: returns (1) unique values, (2) indices of first occurrence, (3) reverse indices, and (4) counts. This is the equivalent of the previousunique
API withreturn_index
,return_inverse
, andreturn_counts
kwargs asTrue
.unique_inverse(x, /)
: returns (1) unique values and (2) reverse indices. As discussed in the OP for gh-212, this addresses the fairly common use case of settingreturn_inverse
toTrue
in the previous API.unique_values(x, /)
: only returns (1) unique values. This is the most common use of the previous API.chooses to retain
return_index
as a return value inunique_all
as this returned array does have value in being able to construct the array of unique values and because deriving this returned array is somewhat tedious to construct via the objects in this specification otherwise.eliminates polymorphic return behavior by removing kwargs from the respective APIs which affect which and how many arrays are returned.
adds guidance on expected output array shapes.
requires that named tuples be returned.
does not use the function name
unique
in order to avoid breaking backward compatibility in array-specification implementations.