@@ -5,20 +5,22 @@ from numpy cimport (int8_t, int32_t, int64_t, import_array, ndarray,
5
5
NPY_INT64, NPY_DATETIME, NPY_TIMEDELTA)
6
6
import numpy as np
7
7
8
+ from cpython.ref cimport PyObject
8
9
from cpython cimport (
9
10
PyTypeObject,
10
11
PyFloat_Check,
11
12
PyLong_Check,
12
13
PyObject_RichCompareBool,
13
14
PyObject_RichCompare,
14
15
PyString_Check,
15
- Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE
16
+ Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE,
16
17
)
17
18
18
19
# Cython < 0.17 doesn't have this in cpython
19
20
cdef extern from " Python.h" :
20
21
cdef PyTypeObject * Py_TYPE(object )
21
22
int PySlice_Check(object )
23
+ object PyUnicode_FromFormat(const char * , ...)
22
24
23
25
cdef extern from " datetime_helper.h" :
24
26
double total_seconds(object )
@@ -1450,20 +1452,43 @@ def format_array_from_datetime(ndarray[int64_t] values, object tz=None, object f
1450
1452
elif basic_format:
1451
1453
1452
1454
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
-
1460
1455
if show_ns:
1461
1456
ns = dts.ps / 1000
1462
- res += ' .%.9d ' % (ns + 1000 * dts.us)
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)
1463
1465
elif show_us:
1464
- res += ' .%.6d ' % dts.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
+
1465
1475
elif show_ms:
1466
- res += ' .%.3d ' % (dts.us/ 1000 )
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)
1467
1492
1468
1493
result[i] = res
1469
1494
0 commit comments