Skip to content

Commit

Permalink
CLN: remove total_seconds compat from json (pandas-dev#17341)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-b1 authored and jowens committed Sep 20, 2017
1 parent b1b3325 commit 76cc924
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions pandas/_libs/src/ujson/python/objToJSON.c
Expand Up @@ -329,7 +329,7 @@ static Py_ssize_t get_attr_length(PyObject *obj, char *attr) {
return ret;
}

npy_int64 get_long_attr(PyObject *o, const char *attr) {
static npy_int64 get_long_attr(PyObject *o, const char *attr) {
npy_int64 long_val;
PyObject *value = PyObject_GetAttrString(o, attr);
long_val = (PyLong_Check(value) ?
Expand All @@ -338,15 +338,12 @@ npy_int64 get_long_attr(PyObject *o, const char *attr) {
return long_val;
}

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

static PyObject *get_item(PyObject *obj, Py_ssize_t i) {
Expand Down

0 comments on commit 76cc924

Please sign in to comment.