-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Merge deleteat() into delete!() and deprecate it #20531
Conversation
8d65983
to
a6d4207
Compare
(Damn, I thought I could guess the PR # before opening it, but Steven opened a new one a few seconds before I pushed the button...) |
I'm left wondering what the original reason for having |
Yes, I've used the same test and it works pretty well (see docstring). The PR which introduced |
@tkelman points out that |
To quote myself from over here:
|
In #5118 and #3023, it was argued that Vectors sometimes implement set operations, and therefore should support both |
I don't find this argument convincing either. I don't see what real-world code would accept an argument without paying attention to wether it's an array or a dict, call Regarding the specific case of sets mentioned at #3023, @mlubin said himself that the issue would be fixed by having So, if anything, |
I believe the relevant view on sets is that they are like an associative mapping of each value to itself. |
I don't have a strong opinion on this at the moment. I'll support the consensus. |
FWIW, this is precisely one of the aspects of standard library APIs that I think needs review for 1.0. |
That makes sense, but then |
FWIW, I don't think it'd be all that surprising as a user if Are there performance costs for deleting and shifting though? |
The generic definition of delete!() suits deleteat!() very well, and the signatures do not conflict.
a6d4207
to
6383358
Compare
Even if it's unsurprising in some contexts, there's a data structure where these two generic actions conflict: sparse vectors. The
|
You can have a look at code touched by #20465: for vectors, |
@StefanKarpinski I don't really buy that line of thinking. Sparse vectors differ from dicts in that their keys (indices) must be contiguous. So it's natural that removing an entry in the middle of the index range would shift subsequent entries down by one. Do you really suggest making |
So what's your proposal for the generic meaning of |
Yes, see discussion starting at #20516 (comment) - if
|
I made a proposal in this PR, which could be improved to something like "Delete item(s) at the given key(s) or index(es) in a collection, and return the collection." Then we would specify what "delete item" means for Though I see your point about merging |
IMO, that's just sweeping under the carpet whether it affects other keys or not, which is the crux of the question of whether these two functions can be semantically merged or not. And the sparse vector case is right in the middle of the semantic ambiguity: some people think it makes sense for |
Also comes up in IndexedTables, where people want a |
OK, let's close this then. |
FWIW, I don't love that we have two such similar functions as |
If there is no foreseeable way to merge both functions, we might at least consider renaming |
As @tkelman noted on the other issue, it looks like we need 2 of these three functions: |
Now that I look at it, the only difference between |
Edit: nevermind, i kind of missed Stefans' post. Oh, and it would be nice to have some pointers in the docstrings of |
That would be great, if you wouldn't mind making a PR adding them :) |
The generic definition of delete!() suits deleteat!() very well, and
the signatures do not conflict.
I have kept the internal
_deleteat!
function inbase/array.jl
since it mirrorsjl_array_del_at
fromsrc/array.c
, which itself is part of a consistent C API, withjl_array_grow_at
,jl_array_grow_at_end
,jl_array_grow_at_beg
,jl_array_del_at_beg
andjl_array_del_at_end
.I wasn't sure where to put the generic docstring, suggestions welcome. In particular, it would be great to find a way to have it appear before the more specific ones (which wasn't the case either before moving it out of helpdb).