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

Function InferArrowType

r/src/type_infer.cpp:191–230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189}
190
191std::shared_ptr<arrow::DataType> InferArrowType(SEXP x) {
192 if (arrow::r::altrep::is_unmaterialized_arrow_altrep(x)) {
193 return arrow::r::altrep::vec_to_arrow_altrep_bypass(x)->type();
194 }
195
196 // If we handle the conversion in C++ we do so here; otherwise we call
197 // the type() S3 generic to infer the type of the object. For data.frame,
198 // this code is sufficiently recursive such that it correctly calls into
199 // R to infer column types where can_convert_native() is false.
200 if (can_convert_native(x) || Rf_inherits(x, "data.frame")) {
201 switch (TYPEOF(x)) {
202 case ENVSXP:
203 return InferArrowTypeFromVector<ENVSXP>(x);
204 case LGLSXP:
205 return InferArrowTypeFromVector<LGLSXP>(x);
206 case INTSXP:
207 return InferArrowTypeFromVector<INTSXP>(x);
208 case REALSXP:
209 return InferArrowTypeFromVector<REALSXP>(x);
210 case RAWSXP:
211 return uint8();
212 case STRSXP:
213 return InferArrowTypeFromVector<STRSXP>(x);
214 case VECSXP:
215 return InferArrowTypeFromVector<VECSXP>(x);
216 case NILSXP:
217 return null();
218 default:
219 cpp11::stop("Cannot infer type from vector");
220 }
221 } else {
222 cpp11::sexp type_result = cpp11::package("arrow")["infer_type"](
223 x, cpp11::named_arg("from_array_infer_type") = true);
224 if (!Rf_inherits(type_result, "DataType")) {
225 cpp11::stop("type() did not return an object of type DataType");
226 }
227
228 return cpp11::as_cpp<std::shared_ptr<arrow::DataType>>(type_result);
229 }
230}
231
232} // namespace r
233} // namespace arrow

Callers 6

vec_to_ArrayFunction · 0.70
InferSchemaFromDotsFunction · 0.70
Array__infer_typeFunction · 0.70
ChunkedArray__from_listFunction · 0.70

Calls 5

can_convert_nativeFunction · 0.85
stopFunction · 0.85
typeMethod · 0.45

Tested by

no test coverage detected