Skip to content

Commit 08ae571

Browse files
committed
remove total_seconds compat from json
1 parent 473a7f3 commit 08ae571

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

pandas/_libs/src/ujson/python/objToJSON.c

+7-10
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ static Py_ssize_t get_attr_length(PyObject *obj, char *attr) {
329329
return ret;
330330
}
331331

332-
npy_int64 get_long_attr(PyObject *o, const char *attr) {
332+
static npy_int64 get_long_attr(PyObject *o, const char *attr) {
333333
npy_int64 long_val;
334334
PyObject *value = PyObject_GetAttrString(o, attr);
335335
long_val = (PyLong_Check(value) ?
@@ -338,15 +338,12 @@ npy_int64 get_long_attr(PyObject *o, const char *attr) {
338338
return long_val;
339339
}
340340

341-
npy_float64 total_seconds(PyObject *td) {
342-
// Python 2.6 compat
343-
// TODO(anyone): remove this legacy workaround with a more
344-
// direct td.total_seconds()
345-
npy_int64 microseconds = get_long_attr(td, "microseconds");
346-
npy_int64 seconds = get_long_attr(td, "seconds");
347-
npy_int64 days = get_long_attr(td, "days");
348-
npy_int64 days_in_seconds = days * 24LL * 3600LL;
349-
return (microseconds + (seconds + days_in_seconds) * 1000000.0) / 1000000.0;
341+
static npy_float64 total_seconds(PyObject *td) {
342+
npy_float64 double_val;
343+
PyObject *value = PyObject_CallMethod(td, "total_seconds", NULL);
344+
double_val = PyFloat_AS_DOUBLE(value);
345+
Py_DECREF(value);
346+
return double_val;
350347
}
351348

352349
static PyObject *get_item(PyObject *obj, Py_ssize_t i) {

0 commit comments

Comments
 (0)