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

Method VisitBinary

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

Source from the content-addressed store, hash-verified

566
567template <typename T>
568Status NumPyConverter::VisitBinary(T* builder) {
569 auto data = reinterpret_cast<const uint8_t*>(PyArray_DATA(arr_));
570
571 auto AppendNotNull = [builder, this](const uint8_t* data) {
572 // This is annoying. NumPy allows strings to have nul-terminators, so
573 // we must check for them here
574 const size_t item_size =
575 strnlen(reinterpret_cast<const char*>(data), static_cast<size_t>(itemsize_));
576 return builder->Append(data, static_cast<int32_t>(item_size));
577 };
578
579 if (mask_ != nullptr) {
580 Ndarray1DIndexer<uint8_t> mask_values(mask_);
581 for (int64_t i = 0; i < length_; ++i) {
582 if (mask_values[i]) {
583 RETURN_NOT_OK(builder->AppendNull());
584 } else {
585 RETURN_NOT_OK(AppendNotNull(data));
586 }
587 data += stride_;
588 }
589 } else {
590 for (int64_t i = 0; i < length_; ++i) {
591 RETURN_NOT_OK(AppendNotNull(data));
592 data += stride_;
593 }
594 }
595
596 return Status::OK();
597}
598
599Status NumPyConverter::Visit(const BinaryType& type) {
600 ::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