@@ -5,22 +5,20 @@ 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
9
8
from cpython cimport (
10
9
PyTypeObject,
11
10
PyFloat_Check,
12
11
PyLong_Check,
13
12
PyObject_RichCompareBool,
14
13
PyObject_RichCompare,
15
14
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
17
16
)
18
17
19
18
# Cython < 0.17 doesn't have this in cpython
20
19
cdef extern from " Python.h" :
21
20
cdef PyTypeObject * Py_TYPE(object )
22
21
int PySlice_Check(object )
23
- object PyUnicode_FromFormat(const char * , ...)
24
22
25
23
cdef extern from " datetime_helper.h" :
26
24
double total_seconds(object )
@@ -1452,43 +1450,20 @@ def format_array_from_datetime(ndarray[int64_t] values, object tz=None, object f
1452
1450
elif basic_format:
1453
1451
1454
1452
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
+
1455
1460
if show_ns:
1456
1461
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)
1465
1463
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
1475
1465
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 )
1492
1467
1493
1468
result[i] = res
1494
1469
0 commit comments