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

Function ImportPresentIntervalTypes

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

Assigns a tuple to interval_types_tuple containing the nametuple for MonthDayNanoIntervalType and if present dateutil's relativedelta and pandas DateOffset.

Source from the content-addressed store, hash-verified

46// MonthDayNanoIntervalType and if present dateutil's relativedelta and
47// pandas DateOffset.
48Status ImportPresentIntervalTypes(OwnedRefNoGIL* interval_types_tuple) {
49 OwnedRef relative_delta_module;
50 // These are Optional imports so swallow errors.
51 OwnedRef relative_delta_type;
52 // Try to import pandas to get types.
53 internal::InitPandasStaticData();
54 if (internal::ImportModule("dateutil.relativedelta", &relative_delta_module).ok()) {
55 RETURN_NOT_OK(internal::ImportFromModule(relative_delta_module.obj(), "relativedelta",
56 &relative_delta_type));
57 }
58
59 PyObject* date_offset_type = internal::BorrowPandasDataOffsetType();
60 interval_types_tuple->reset(
61 PyTuple_New(1 + (date_offset_type != nullptr ? 1 : 0) +
62 (relative_delta_type.obj() != nullptr ? 1 : 0)));
63 RETURN_IF_PYERROR();
64 int index = 0;
65 PyTuple_SetItem(interval_types_tuple->obj(), index++,
66 internal::NewMonthDayNanoTupleType());
67 RETURN_IF_PYERROR();
68 if (date_offset_type != nullptr) {
69 Py_XINCREF(date_offset_type);
70 PyTuple_SetItem(interval_types_tuple->obj(), index++, date_offset_type);
71 RETURN_IF_PYERROR();
72 }
73 if (relative_delta_type.obj() != nullptr) {
74 PyTuple_SetItem(interval_types_tuple->obj(), index++, relative_delta_type.detach());
75 RETURN_IF_PYERROR();
76 }
77 return Status::OK();
78}
79
80} // namespace
81

Callers 1

TypeInferrerMethod · 0.85

Calls 8

InitPandasStaticDataFunction · 0.85
ImportModuleFunction · 0.85
ImportFromModuleFunction · 0.85
NewMonthDayNanoTupleTypeFunction · 0.85
OKFunction · 0.50
okMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected