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

Method Convert

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

Source from the content-addressed store, hash-verified

325};
326
327Status NumPyConverter::Convert() {
328 if (PyArray_NDIM(arr_) != 1) {
329 return Status::Invalid("only handle 1-dimensional arrays");
330 }
331
332 if (dtype_->type_num == NPY_OBJECT) {
333 // If an object array, convert it like a normal Python sequence
334 PyConversionOptions py_options;
335 py_options.type = type_;
336 py_options.from_pandas = from_pandas_;
337 ARROW_ASSIGN_OR_RAISE(
338 auto chunked_array,
339 ConvertPySequence(reinterpret_cast<PyObject*>(arr_),
340 reinterpret_cast<PyObject*>(mask_), py_options, pool_));
341 out_arrays_ = chunked_array->chunks();
342 return Status::OK();
343 }
344
345 if (type_ == nullptr) {
346 return Status::Invalid("Must pass data type for non-object arrays");
347 }
348
349 if (dtype_->type_num == NPY_VSTRING && !is_string_or_string_view(type_->id())) {
350 return Status::TypeError("Expected an Arrow string type for NumPy StringDType, got ",
351 type_->ToString());
352 }
353
354 // Visit the type to perform conversion
355 return VisitTypeInline(*type_, this);
356}
357
358namespace {
359

Callers 2

VisitMethod · 0.45
NdarrayToArrowFunction · 0.45

Calls 8

is_string_or_string_viewFunction · 0.85
VisitTypeInlineFunction · 0.85
InvalidFunction · 0.50
OKFunction · 0.50
TypeErrorFunction · 0.50
chunksMethod · 0.45
idMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected