You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[C++/Python] Kernel for SetItem(IntegerArray, values) ("replace_with_indices") #25505
We should have a kernel that allows overriding the values of an array using an integer array as the indexer and a scalar or array of equal length as the values.
Can we assume that 'to_replace' is a non-null Int64Array?
That might be the easiest for now. Or otherwise we can say nulls in to_replace give nulls in the output. The question is then how to interpret arr2, though (should it be of the same length as to_replace, or as the non-null values of to_replace ?)
And should we enforce 'to_replace' being sorted (IMO this would be more efficient)?
Hmm, not sure. Also for Take we generally don't require sortedness of the indices, I think?
What is the arity of this kernel? Unary or binary?
Niranda Perera / @nirandaperera:
I'm currently working on the 'if-else' function ARROW-10640. And AFAIK it is the only ternary function that is there ATM. This will be another one.
Joris Van den Bossche / @jorisvandenbossche:
Yes, I think that covers all cases. I am personally not fully sure that the third case of a scalar for the indices is necessarily important to cover for an initial implementation (for example also the "take" kernel only supports an actual array for the indices)
Niranda Perera / @nirandaperera:
I'd like to start looking at this Jira again. @jorisvandenbossche Has there been any developments for the last couple of months (affecting this requirement) or can I still go ahead?
The related ARROW-9430 has been done by now, and there we went with a name replace_with_mask for the kernel to set values with a mask. So maybe for this kernel we can then use replace_with_indices to follow the same naming scheme?
Todd Farmer / @toddfarmer:
This issue was last updated over 90 days ago, which may be an indication it is no longer being actively worked. To better reflect the current state, the issue is being unassigned. Please feel free to re-take assignment of the issue if it is being actively worked, or if you plan to start that work soon.
changed the title [-][C++/Python] Kernel for SetItem(IntegerArray, values)[/-][+][C++/Python] Kernel for SetItem(IntegerArray, values) ("replace_with_indices")[/+]on Mar 21, 2023
Hi! I'd like to work on this. I'm still fairly new to Arrow but I'll put in the effort to see this through. My understanding, correct me if I'm wrong: I'd model it on the existing replace_with_mask, so it'd be a ternary kernel replace_with_indices(values, indices, replacements) that returns an array the same length as values, where replacements is either an array (length = len(indices)) or a scalar.
And a few semantics I'd want to confirm: should I assume indices can be unsorted, contain duplicates (last write wins), be null (skipping the index and replacement pair), and out of bounds (skip or error?)?
Activity
asfimport commentedon May 17, 2021
Niranda Perera / @nirandaperera:
Identical issue
asfimport commentedon May 18, 2021
Joris Van den Bossche / @jorisvandenbossche:
@nirandaperera you linked ARROW-9430 as duplicate. Both are of course closely related, but there is a difference: using integer indices vs a boolean mask to select the values you want to set
asfimport commentedon May 18, 2021
Niranda Perera / @nirandaperera:
Thank you @jorisvandenbossche. That was clearly my mistake :(
asfimport commentedon May 18, 2021
Niranda Perera / @nirandaperera:
I'd like to take this one. @jorisvandenbossche @xhochy @pitrou I'd like to get your feedback on the following.
Just to be clear, an example of this would be,
What is a good name for the kernel? I'm not sure about replace_by_index because Arrays are immutable. Any suggestions?
Can we assume that 'to_replace' is a non-null Int64Array?
And should we enforce 'to_replace' being sorted (IMO this would be more efficient)?
What is the arity of this kernel? Unary or binary?
asfimport commentedon May 18, 2021
Joris Van den Bossche / @jorisvandenbossche:
I think one difference in your example is that I expect the
arr2to be of the same length asto_replaceThat might be the easiest for now. Or otherwise we can say nulls in
to_replacegive nulls in the output. The question is then how to interpretarr2, though (should it be of the same length asto_replace, or as the non-null values ofto_replace?)Hmm, not sure. Also for
Takewe generally don't require sortedness of the indices, I think?Ternary?
asfimport commentedon May 26, 2021
Antoine Pitrou / @pitrou:
Indeed, we don't require sortedness of the indices for
Take. Also, I'm not convinced it would be more efficient (why?).asfimport commentedon May 26, 2021
Antoine Pitrou / @pitrou:
The example doesn't quite look right to me. I would expect:
@xhochy What do you think?
asfimport commentedon May 26, 2021
Niranda Perera / @nirandaperera:
@pitrou my idea was something like this.
Its like an if-else mask, but the mask's set bits are encoded in an array ARROW-10640
asfimport commentedon May 26, 2021
Antoine Pitrou / @pitrou:
If this is meant to emulate Numpy's advanced indexing, then I don't think this is the right semantics.
asfimport commentedon May 26, 2021
Niranda Perera / @nirandaperera:
I see.. Can you give an example?
asfimport commentedon May 26, 2021
Antoine Pitrou / @pitrou:
asfimport commentedon May 26, 2021
Antoine Pitrou / @pitrou:
@xhochy What is the intended use case?
asfimport commentedon May 26, 2021
Niranda Perera / @nirandaperera:
Got it. Think that makes sense. So, this will ultimately be another ternary kernel, isnt it?
asfimport commentedon May 26, 2021
Antoine Pitrou / @pitrou:
What do you mean by "another ternary kernel"?
asfimport commentedon May 26, 2021
Niranda Perera / @nirandaperera:
I'm currently working on the 'if-else' function ARROW-10640. And AFAIK it is the only ternary function that is there ATM. This will be another one.
4 remaining items
asfimport commentedon Jun 1, 2021
Joris Van den Bossche / @jorisvandenbossche:
Yes, I think that covers all cases. I am personally not fully sure that the third case of a scalar for the indices is necessarily important to cover for an initial implementation (for example also the "take" kernel only supports an actual array for the
indices)asfimport commentedon Jun 1, 2021
Niranda Perera / @nirandaperera:
@jorisvandenbossche Got it!
asfimport commentedon Nov 16, 2021
Niranda Perera / @nirandaperera:
I'd like to start looking at this Jira again. @jorisvandenbossche Has there been any developments for the last couple of months (affecting this requirement) or can I still go ahead?
asfimport commentedon Nov 17, 2021
Joris Van den Bossche / @jorisvandenbossche:
I am not aware of any work that happened in the meantime. So taking a look at this issue would be very welcome!
The related ARROW-9430 has been done by now, and there we went with a name
replace_with_maskfor the kernel to set values with a mask. So maybe for this kernel we can then usereplace_with_indicesto follow the same naming scheme?asfimport commentedon Jul 12, 2022
Todd Farmer / @toddfarmer:
This issue was last updated over 90 days ago, which may be an indication it is no longer being actively worked. To better reflect the current state, the issue is being unassigned. Please feel free to re-take assignment of the issue if it is being actively worked, or if you plan to start that work soon.
[-][C++/Python] Kernel for SetItem(IntegerArray, values)[/-][+][C++/Python] Kernel for SetItem(IntegerArray, values) ("replace_with_indices")[/+]thisisnic commentedon Jun 20, 2025
This issue hasn't had activity in a long time. If it's still being worked on, please leave a comment. Otherwise, it will be closed on 23rd June.
Labelled
Status: Stale-Warningfor tracking.Kanishk-Dendukuri commentedon Jul 31, 2026
Hi! I'd like to work on this. I'm still fairly new to Arrow but I'll put in the effort to see this through. My understanding, correct me if I'm wrong: I'd model it on the existing replace_with_mask, so it'd be a ternary kernel replace_with_indices(values, indices, replacements) that returns an array the same length as values, where replacements is either an array (length = len(indices)) or a scalar.
And a few semantics I'd want to confirm: should I assume indices can be unsorted, contain duplicates (last write wins), be null (skipping the index and replacement pair), and out of bounds (skip or error?)?
apacheGH-25505: [C++][Python] Add replace_with_indices compute kernel