mirror of
https://github.com/apache/arrow.git
synced 2026-10-29 17:15:39 +08:00
handle python 2 compat
This commit is contained in:
1 parent
6bfafbe144
commit
f4d6b4b645
1 file changed
+13
-4
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user