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

add keepat! (the opposite of deleteat!) #36229

Merged
merged 6 commits into from
May 27, 2021
Merged

add keepat! (the opposite of deleteat!) #36229

merged 6 commits into from
May 27, 2021

Conversation

rfourquet
Copy link
Member

It feels like I'm missing something, but I asked on slack and this functionality doesn't seem to exist yet in Base.
keepat!(vector, indices) deletes items at all indices of vector except those which are specified in indices.
In other words, after keepat!(a, inds), a is equal to the array which would have been obtained by a[inds].

I'm not sure about the name, it could be maybe getindex!, or the feature could be incorporated in deleteat! with a keyword.

@rfourquet rfourquet added arrays [a, r, r, a, y, s] needs compat annotation Add !!! compat "Julia x.y" to the docstring needs docs Documentation for this change is required needs news A NEWS entry is required for this change needs tests Unit tests are required for this change labels Jun 11, 2020
@StefanKarpinski
Copy link
Member

Maybe better expressed with https://github.com/mbauman/InvertedIndices.jl and deleteat!?

@rfourquet
Copy link
Member Author

Maybe better expressed with https://github.com/mbauman/InvertedIndices.jl and deleteat!?

Maybe! Someone pointed out this package to me and I forgot to mention it here. But it's quite less discoverable than deleteat!, while the operation of "keeping only these indices" doesn't seem to be any less fundamental than "delete all these indices". Although it might be less often needed given that this feature isn't in Base yet and doesn't seem to have been requested before. But given how often the non-mutating equivalent vector[inds] is used, I'm quite surprised by this fact.

@rfourquet rfourquet added the design Design of APIs or of the language itself label Jun 12, 2020
base/array.jl Outdated Show resolved Hide resolved
@vtjnash vtjnash changed the title [WIP/RFC] add keepat! the opposite of deleteat! add keepat! (the opposite of deleteat!) Apr 16, 2021
Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable to me. I think the implementation can be generalized, but otherwise, lgtm conceptually. I'd merge if you finish it :)

@vtjnash vtjnash added the forget me not PRs that one wants to make sure aren't forgotten label Apr 16, 2021
@rfourquet rfourquet removed needs compat annotation Add !!! compat "Julia x.y" to the docstring needs docs Documentation for this change is required needs news A NEWS entry is required for this change needs tests Unit tests are required for this change labels Apr 22, 2021
@oscardssmith oscardssmith merged commit 4cdcdb8 into master May 27, 2021
@oscardssmith oscardssmith deleted the rf/keepat branch May 27, 2021 20:13
@simeonschaub simeonschaub removed the forget me not PRs that one wants to make sure aren't forgotten label May 29, 2021
shirodkara pushed a commit to shirodkara/julia that referenced this pull request Jun 9, 2021
johanmon pushed a commit to johanmon/julia that referenced this pull request Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] design Design of APIs or of the language itself
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants