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

Method PrepareInputData

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

Source from the content-addressed store, hash-verified

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