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

Function InferArrowType

r/src/type_infer.cpp:187–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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