handle python 2 compat

This commit is contained in:
Joris Van den Bossche authored and Krisztián Szűcs committed 2019-10-05 12:03:33 +02:00
1 parent 6bfafbe144
commit f4d6b4b645
1 file changed
+13 -4
+13 -4
View File
@@ -116,15 +116,22 @@ inline int64_t PyDateTime_to_ns(PyDateTime_DateTime* pydatetime) {
ARROW_PYTHON_EXPORT
inline int64_t PyDelta_to_s(PyDateTime_Delta* pytimedelta) {
int64_t total_seconds = 0;
total_seconds += PyDateTime_DELTA_GET_SECONDS(pytimedelta);
total_seconds += PyDateTime_DELTA_GET_DAYS(pytimedelta) * 24 * 3600;
// TODO(py2) change to "PyDateTime_DELTA_GET_SECONDS/DAYS(pytimedelta)"
total_seconds +=
PyLong_AsLongLong(PyObject_GetAttrString((PyObject*)pytimedelta, "seconds"));
total_seconds +=
PyLong_AsLongLong(PyObject_GetAttrString((PyObject*)pytimedelta, "days")) * 24 *
3600;
return total_seconds;
}
ARROW_PYTHON_EXPORT
inline int64_t PyDelta_to_ms(PyDateTime_Delta* pytimedelta) {
int64_t total_ms = PyDelta_to_s(pytimedelta) * 1000;
total_ms += PyDateTime_DELTA_GET_MICROSECONDS(pytimedelta) / 1000;
// TODO(py2) change to "PyDateTime_DELTA_GET_MICROSECONDS(pytimedelta) / 1000"
total_ms +=
PyLong_AsLongLong(PyObject_GetAttrString((PyObject*)pytimedelta, "microseconds")) /
1000;
return total_ms;
}
@@ -132,7 +139,9 @@ ARROW_PYTHON_EXPORT
inline int64_t PyDelta_to_us(PyDateTime_Delta* pytimedelta) {
int64_t total_us = 0;
total_us += PyDelta_to_s(pytimedelta) * 1000 * 1000;
total_us += PyDateTime_DELTA_GET_MICROSECONDS(pytimedelta);
// TODO(py2) change to "PyDateTime_DELTA_GET_MICROSECONDS(pytimedelta)"
total_us +=
PyLong_AsLongLong(PyObject_GetAttrString((PyObject*)pytimedelta, "microseconds"));
return total_us;
}