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

Method PrepareInputData

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

Source from the content-addressed store, hash-verified

453
454template <typename ArrowType>
455inline Status NumPyConverter::PrepareInputData(std::shared_ptr<Buffer>* data) {
456 if (PyArray_ISBYTESWAPPED(arr_)) {
457 // TODO
458 return Status::NotImplemented("Byte-swapped arrays not supported");
459 }
460
461 if (dtype_->type_num == NPY_BOOL) {
462 int64_t nbytes = bit_util::BytesForBits(length_);
463 ARROW_ASSIGN_OR_RAISE(auto buffer, AllocateBuffer(nbytes, pool_));
464
465 Ndarray1DIndexer<uint8_t> values(arr_);
466 int64_t i = 0;
467 const auto generate = [&values, &i]() -> bool { return values[i++] > 0; };
468 GenerateBitsUnrolled(buffer->mutable_data(), 0, length_, generate);
469
470 *data = std::move(buffer);
471 } else if (is_strided()) {
472 RETURN_NOT_OK(NumPyStridedConverter::Convert(arr_, length_, pool_, data));
473 } else {
474 // Can zero-copy
475 *data = std::make_shared<NumPyBuffer>(reinterpret_cast<PyObject*>(arr_));
476 }
477
478 return Status::OK();
479}
480
481template <typename ArrowType>
482inline Status NumPyConverter::ConvertData(std::shared_ptr<Buffer>* data) {

Callers

nothing calls this directly

Calls 6

BytesForBitsFunction · 0.85
NotImplementedFunction · 0.50
GenerateBitsUnrolledFunction · 0.50
ConvertFunction · 0.50
OKFunction · 0.50
mutable_dataMethod · 0.45

Tested by

no test coverage detected