jorisvandenbossche commented on code in PR #14395:
URL: https://github.com/apache/arrow/pull/14395#discussion_r994547601
##########
cpp/src/arrow/compute/kernels/scalar_nested_test.cc:
##########
@@ -116,6 +117,64 @@ TEST(TestScalarNested, ListElementInvalid) {
Raises(StatusCode::Invalid));
}
+void CheckListSlice(std::shared_ptr<Array> input, std::shared_ptr<Array>
expected,
+ SliceOptions& args) {
+ ASSERT_OK_AND_ASSIGN(auto result, CallFunction("list_slice", {input},
&args));
+ ASSERT_EQ(result, expected);
+}
+
+TEST(TestScalarNested, ListSlice) {
+ const auto value_types = {float32(), int32()};
+ for (auto value_type : value_types) {
+ auto inputs = {ArrayFromJSON(list(value_type), "[[1, 2, 3], [4, 5], [6]]"),
+ ArrayFromJSON(fixed_size_list(value_type, 3),
+ "[[1, 2, 3], [4, 5, null], [6, null,
null]]")};
+ for (auto input : inputs) {
+ SliceOptions args(0, 2);
+ auto expected =
+ ArrayFromJSON(fixed_size_list(value_type, 2), "[[1, 2], [4, 5], [6,
null]]");
+ CheckListSlice(input, expected, args);
+
+ args.start = 1;
+ expected = ArrayFromJSON(fixed_size_list(value_type, 1), "[[2], [5],
[null]]");
+ CheckListSlice(input, expected, args);
+
+ args.start = 2;
+ args.stop = 4;
Review Comment:
Ah, sorry, I interpreted the equal in `start >= stop` the wrong way around
(it's the check when to error, not when to allow it).
I think it is fine to error for now. In general, slicing (at least with
Python semantics) allows this. But eg also negative values to start counting
from the end can be useful, and that's also something that doesn't yet work
right now I assume. Let's maybe first try to get the basics right.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]