jorisvandenbossche commented on code in PR #41757:
URL: https://github.com/apache/arrow/pull/41757#discussion_r1620377248
##########
cpp/src/arrow/array/array_nested.cc:
##########
@@ -836,24 +845,31 @@ Result<std::shared_ptr<Array>>
MapArray::FromArraysInternal(
using OffsetArrayType = typename TypeTraits<OffsetArrowType>::ArrayType;
const auto& typed_offsets = checked_cast<const OffsetArrayType&>(*offsets);
- auto buffers = BufferVector({nullptr, typed_offsets.values()});
+
+ if (null_bitmap != nullptr) {
+ auto buffers = BufferVector({std::move(null_bitmap),
typed_offsets.values()});
+ return std::make_shared<MapArray>(type, offsets->length() - 1,
std::move(buffers),
+ keys, items,
/*null_count=*/null_bitmap->size(),
+ offsets->offset());
+ }
+
+ auto buffers = BufferVector({null_bitmap, typed_offsets.values()});
return std::make_shared<MapArray>(type, offsets->length() - 1,
std::move(buffers), keys,
items, /*null_count=*/0,
offsets->offset());
Review Comment:
Small nit: I think it will be easier to read the code later if you only
define the buffers (and null_count) in an if / else, and the reuse the same
`return std::make_shared<MapArray>(..)` (then you don't need to wonder what is
exactly the difference between both)
##########
python/pyarrow/tests/test_array.py:
##########
@@ -1079,6 +1079,33 @@ def test_map_from_arrays():
pa.int64()
))
+ # pass in null bitmap
+ result = pa.MapArray.from_arrays([0, 2, 2, 6], keys, items, pa.map_(
+ keys.type,
+ items.type),
+ mask=pa.array([False, True, False], type=pa.bool_())
+ )
+ assert result.equals(expected)
Review Comment:
Can you test this both with and without a type passed? (since that are two
separate code paths where the mask is passed in cython)
--
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]