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

Method Read

python/pyarrow/src/arrow/python/io.cc:218–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

216}
217
218Result<int64_t> PyReadableFile::Read(int64_t nbytes, void* out) {
219 return SafeCallIntoPython([=]() -> Result<int64_t> {
220 OwnedRef bytes;
221 RETURN_NOT_OK(file_->Read(nbytes, bytes.ref()));
222 PyObject* bytes_obj = bytes.obj();
223 ARROW_DCHECK(bytes_obj != NULL);
224
225 Py_buffer py_buf;
226 if (!PyObject_GetBuffer(bytes_obj, &py_buf, PyBUF_ANY_CONTIGUOUS)) {
227 const uint8_t* data = reinterpret_cast<const uint8_t*>(py_buf.buf);
228 std::memcpy(out, data, py_buf.len);
229 int64_t len = py_buf.len;
230 PyBuffer_Release(&py_buf);
231 return len;
232 } else {
233 return Status::TypeError(
234 "Python file read() should have returned a bytes object or an object "
235 "supporting the buffer protocol, got '",
236 Py_TYPE(bytes_obj)->tp_name, "' (did you open the file in binary mode?)");
237 }
238 });
239}
240
241Result<std::shared_ptr<Buffer>> PyReadableFile::Read(int64_t nbytes) {
242 return SafeCallIntoPython([=]() -> Result<std::shared_ptr<Buffer>> {

Callers

nothing calls this directly

Calls 4

SafeCallIntoPythonFunction · 0.85
HasReadBufferMethod · 0.80
TypeErrorFunction · 0.50
ReadBufferMethod · 0.45

Tested by

no test coverage detected