`binary_replace_slice` should not work with `string` types
- Dominant language
- C++
- Stars
- 17.1k
- Forks
- 4.3k
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 88
Description
`binary_replace_slice` can give in invalid output when used with string types. Given that there is `utf8_replace_slice`, I think `binary_replace_slice` should not support string types.
If a user actually wants to play with bytes for string type, they should explicitly cast to binary type and use `binary_replace_slice`.
```java
>>> pc.binary_replace_slice(["hé"], 1, 2, "x")
[
"hx�"
]
>>> pc.binary_replace_slice(["hé"], 1, 2, "x").validate(full=True)
Traceback (most recent call last):
...
ArrowInvalid: Invalid UTF8 sequence at string index 0
```
Ref:
cc: @pitrou
**Reporter**: [Kshiteej K](https://issues.apache.org/jira/browse/ARROW-18319) / @kshitij12345
**Note**: *This issue was originally created as [ARROW-18319](https://issues.apache.org/jira/browse/ARROW-18319). Please see the [migration documentation](https://github.com/apache/arrow/issues/14542) for further details.*
Contributor guide
Research direction
Start by reproducing the Python examples for binary_replace_slice and utf8_replace_slice, including validate(full=True), and trace how string inputs are handled. Done means binary_replace_slice no longer accepts string types that can produce invalid UTF-8, while callers can explicitly cast to binary and use the operation successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100