MCPcopy Create free account
hub / github.com/apache/arrow / VisitBinary

Method VisitBinary

python/pyarrow/src/arrow/python/numpy_to_arrow.cc:577–606  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

575
576template <typename T>
577Status NumPyConverter::VisitBinary(T* builder) {
578 auto data = reinterpret_cast<const uint8_t*>(PyArray_DATA(arr_));
579
580 auto AppendNotNull = [builder, this](const uint8_t* data) {
581 // This is annoying. NumPy allows strings to have nul-terminators, so
582 // we must check for them here
583 const size_t item_size =
584 strnlen(reinterpret_cast<const char*>(data), static_cast<size_t>(itemsize_));
585 return builder->Append(data, static_cast<int32_t>(item_size));
586 };
587
588 if (mask_ != nullptr) {
589 Ndarray1DIndexer<uint8_t> mask_values(mask_);
590 for (int64_t i = 0; i < length_; ++i) {
591 if (mask_values[i]) {
592 RETURN_NOT_OK(builder->AppendNull());
593 } else {
594 RETURN_NOT_OK(AppendNotNull(data));
595 }
596 data += stride_;
597 }
598 } else {
599 for (int64_t i = 0; i < length_; ++i) {
600 RETURN_NOT_OK(AppendNotNull(data));
601 data += stride_;
602 }
603 }
604
605 return Status::OK();
606}
607
608Status NumPyConverter::Visit(const BinaryType& type) {
609 ::arrow::internal::ChunkedBinaryBuilder builder(kBinaryChunksize, pool_);

Callers

nothing calls this directly

Calls 3

OKFunction · 0.50
AppendMethod · 0.45
AppendNullMethod · 0.45

Tested by

no test coverage detected