@@ -5,22 +5,20 @@ from numpy cimport (int8_t, int32_t, int64_t, import_array, ndarray,
55 NPY_INT64, NPY_DATETIME, NPY_TIMEDELTA)
66import numpy as np
77
8- from cpython.ref cimport PyObject
98from cpython cimport (
109 PyTypeObject,
1110 PyFloat_Check,
1211 PyLong_Check,
1312 PyObject_RichCompareBool,
1413 PyObject_RichCompare,
1514 PyString_Check,
16- Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE,
15+ Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE
1716)
1817
1918# Cython < 0.17 doesn't have this in cpython
2019cdef extern from " Python.h" :
2120 cdef PyTypeObject * Py_TYPE(object )
2221 int PySlice_Check(object )
23- object PyUnicode_FromFormat(const char * , ...)
2422
2523cdef extern from " datetime_helper.h" :
2624 double total_seconds(object )
@@ -1452,43 +1450,20 @@ def format_array_from_datetime(ndarray[int64_t] values, object tz=None, object f
14521450 elif basic_format:
14531451
14541452 pandas_datetime_to_datetimestruct(val, PANDAS_FR_ns, & dts)
1453+ res = ' %d -%.2d -%.2d %.2d :%.2d :%.2d ' % (dts.year,
1454+ dts.month,
1455+ dts.day,
1456+ dts.hour,
1457+ dts.min,
1458+ dts.sec)
1459+
14551460 if show_ns:
14561461 ns = dts.ps / 1000
1457- res = PyUnicode_FromFormat(' %d -%02d -%02d %02d :%02d :%02d .%09d ' ,
1458- dts.year,
1459- dts.month,
1460- dts.day,
1461- dts.hour,
1462- dts.min,
1463- dts.sec,
1464- ns + 1000 * dts.us)
1462+ res += ' .%.9d ' % (ns + 1000 * dts.us)
14651463 elif show_us:
1466- res = PyUnicode_FromFormat(' %d -%02d -%02d %02d :%02d :%02d .%06d ' ,
1467- dts.year,
1468- dts.month,
1469- dts.day,
1470- dts.hour,
1471- dts.min,
1472- dts.sec,
1473- dts.us)
1474-
1464+ res += ' .%.6d ' % dts.us
14751465 elif show_ms:
1476- res = PyUnicode_FromFormat(' %d -%02d -%02d %02d :%02d :%02d .%03d ' ,
1477- dts.year,
1478- dts.month,
1479- dts.day,
1480- dts.hour,
1481- dts.min,
1482- dts.sec,
1483- dts.us/ 1000 )
1484- else :
1485- res = PyUnicode_FromFormat(' %d -%02d -%02d %02d :%02d :%02d ' ,
1486- dts.year,
1487- dts.month,
1488- dts.day,
1489- dts.hour,
1490- dts.min,
1491- dts.sec)
1466+ res += ' .%.3d ' % (dts.us/ 1000 )
14921467
14931468 result[i] = res
14941469
0 commit comments