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

Method GetType

python/pyarrow/src/arrow/python/inference.cc:522–620  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

520 }
521
522 Status GetType(std::shared_ptr<DataType>* out) {
523 // TODO(wesm): handling forming unions
524 if (make_unions_) {
525 return Status::NotImplemented("Creating union types not yet supported");
526 }
527
528 RETURN_NOT_OK(Validate());
529
530 if (arrow_scalar_count_ > 0 && arrow_scalar_count_ + none_count_ != total_count_) {
531 return Status::Invalid(
532 "pyarrow scalars cannot be mixed "
533 "with other Python scalar values currently");
534 }
535
536 if (numpy_dtype_count_ > 0) {
537 // All NumPy scalars and Nones/nulls
538 if (numpy_dtype_count_ + none_count_ == total_count_) {
539 return NumPyDtypeToArrow(numpy_unifier_.current_dtype()).Value(out);
540 }
541
542 // The "bad path": data contains a mix of NumPy scalars and
543 // other kinds of scalars. Note this can happen innocuously
544 // because numpy.nan is not a NumPy scalar (it's a built-in
545 // PyFloat)
546
547 // TODO(ARROW-5564): Merge together type unification so this
548 // hack is not necessary
549 switch (numpy_unifier_.current_type_num()) {
550 case NPY_BOOL:
551 bool_count_ += numpy_dtype_count_;
552 break;
553 case NPY_INT8:
554 case NPY_INT16:
555 case NPY_INT32:
556 case NPY_INT64:
557 case NPY_UINT8:
558 case NPY_UINT16:
559 case NPY_UINT32:
560 case NPY_UINT64:
561 int_count_ += numpy_dtype_count_;
562 break;
563 case NPY_FLOAT32:
564 case NPY_FLOAT64:
565 float_count_ += numpy_dtype_count_;
566 break;
567 case NPY_DATETIME:
568 return Status::Invalid(
569 "numpy.datetime64 scalars cannot be mixed "
570 "with other Python scalar values currently");
571 }
572 }
573
574 if (list_count_) {
575 std::shared_ptr<DataType> value_type;
576 RETURN_NOT_OK(list_inferrer_->GetType(&value_type));
577 *out = list(value_type);
578 } else if (struct_count_) {
579 RETURN_NOT_OK(GetStructType(out));

Callers 2

GetStructTypeMethod · 0.45
InferArrowTypeFunction · 0.45

Calls 15

ValidateFunction · 0.85
NumPyDtypeToArrowFunction · 0.85
listFunction · 0.85
month_day_nano_intervalFunction · 0.85
current_dtypeMethod · 0.80
current_type_numMethod · 0.80
NotImplementedFunction · 0.50
InvalidFunction · 0.50
ARROW_ASSIGN_OR_RAISEFunction · 0.50
MakeFunction · 0.50
time64Function · 0.50
timestampFunction · 0.50

Tested by

no test coverage detected