From dfed8c3be0612a199c1a554422ea818f2fa50586 Mon Sep 17 00:00:00 2001 From: "s.kyon" <251157463+skyon0522-ai@users.noreply.github.com> Date: Fri, 9 Oct 2026 00:26:40 +0900 Subject: [PATCH] GH-45880: [C++][Python] Return TypeError for map parent indices --- cpp/src/arrow/compute/kernels/vector_nested.cc | 2 ++ cpp/src/arrow/compute/kernels/vector_nested_test.cc | 12 ++++++++++++ python/pyarrow/tests/test_array.py | 11 +++++++++++ 3 files changed, 25 insertions(+) diff --git a/cpp/src/arrow/compute/kernels/vector_nested.cc b/cpp/src/arrow/compute/kernels/vector_nested.cc index d515e60fbee2..e0d881c2a5a8 100644 --- a/cpp/src/arrow/compute/kernels/vector_nested.cc +++ b/cpp/src/arrow/compute/kernels/vector_nested.cc @@ -167,6 +167,8 @@ struct ListParentIndicesArray { type.ToString()); } + Status Visit(const MapType& type) { return Visit(static_cast(type)); } + static Result> Exec(KernelContext* ctx, const std::shared_ptr& input, int64_t base_output_offset = 0) { diff --git a/cpp/src/arrow/compute/kernels/vector_nested_test.cc b/cpp/src/arrow/compute/kernels/vector_nested_test.cc index 07f9c44db52a..afafe1469859 100644 --- a/cpp/src/arrow/compute/kernels/vector_nested_test.cc +++ b/cpp/src/arrow/compute/kernels/vector_nested_test.cc @@ -271,6 +271,18 @@ TEST(TestVectorNested, ListParentIndices) { } } +TEST(TestVectorNested, ListParentIndicesMap) { + auto input = + ArrayFromJSON(map(utf8(), uint16()), R"([[["a", 1], ["b", 2]], [["c", 3]]])"); + auto chunked = + std::make_shared(ArrayVector{input->Slice(0, 1), input->Slice(1)}); + for (const auto& datum : {Datum(input), Datum(chunked)}) { + EXPECT_RAISES_WITH_MESSAGE_THAT(TypeError, + ::testing::HasSubstr("expects list input, got map"), + CallFunction("list_parent_indices", {datum})); + } +} + TEST(TestVectorNested, ListParentIndicesChunkedArray) { const auto types = { list(int16()), diff --git a/python/pyarrow/tests/test_array.py b/python/pyarrow/tests/test_array.py index 74ff837e16e8..0e6e16a40f92 100644 --- a/python/pyarrow/tests/test_array.py +++ b/python/pyarrow/tests/test_array.py @@ -3369,6 +3369,17 @@ def test_list_value_parent_indices(list_type): assert arr.value_parent_indices().equals(expected) +def test_map_value_parent_indices(): + arr = pa.array([{'a': 1, 'b': 2}, {'c': 3}], + type=pa.map_(pa.utf8(), pa.uint16())) + + message = "expects list input, got map" + with pytest.raises(pa.ArrowTypeError, match=message): + arr.value_parent_indices() + with pytest.raises(pa.ArrowTypeError, match=message): + pc.list_parent_indices(arr) + + @pytest.mark.parametrize(('offset_type', 'list_type'), [(pa.int32(), pa.list_(pa.int32())), (pa.int32(), pa.list_(pa.int32(), list_size=2)),