Skip to content

Commit e728f94

Browse files
jbrockmendeljreback
authored andcommitted
Remove unused from datetime.pxd, check for fastpath in ensure_datetime64ns (#18453)
1 parent 6660638 commit e728f94

File tree

3 files changed

+10
-29
lines changed

3 files changed

+10
-29
lines changed

pandas/_libs/src/datetime.pxd

-14
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ from cpython cimport PyUnicode_Check, PyUnicode_AsASCIIString
55

66

77
cdef extern from "numpy/ndarrayobject.h":
8-
ctypedef int64_t npy_timedelta
98
ctypedef int64_t npy_datetime
109

1110
ctypedef enum NPY_CASTING:
@@ -15,15 +14,10 @@ cdef extern from "numpy/ndarrayobject.h":
1514
NPY_SAME_KIND_CASTING
1615
NPY_UNSAFE_CASTING
1716

18-
cdef extern from "numpy_helper.h":
19-
npy_datetime get_datetime64_value(object o)
20-
npy_timedelta get_timedelta64_value(object o)
21-
2217
cdef extern from "numpy/npy_common.h":
2318
ctypedef unsigned char npy_bool
2419

2520
cdef extern from "datetime/np_datetime.h":
26-
2721
ctypedef enum PANDAS_DATETIMEUNIT:
2822
PANDAS_FR_Y
2923
PANDAS_FR_M
@@ -44,20 +38,12 @@ cdef extern from "datetime/np_datetime.h":
4438
npy_int64 year
4539
npy_int32 month, day, hour, min, sec, us, ps, as
4640

47-
npy_datetime pandas_datetimestruct_to_datetime(
48-
PANDAS_DATETIMEUNIT fr, pandas_datetimestruct *d) nogil
49-
5041
void pandas_datetime_to_datetimestruct(npy_datetime val,
5142
PANDAS_DATETIMEUNIT fr,
5243
pandas_datetimestruct *result) nogil
53-
int days_per_month_table[2][12]
5444

55-
int dayofweek(int y, int m, int d) nogil
56-
int is_leapyear(int64_t year) nogil
57-
PANDAS_DATETIMEUNIT get_datetime64_unit(object o)
5845

5946
cdef extern from "datetime/np_datetime_strings.h":
60-
6147
int parse_iso_8601_datetime(char *str, int len, PANDAS_DATETIMEUNIT unit,
6248
NPY_CASTING casting,
6349
pandas_datetimestruct *out,

pandas/_libs/src/numpy_helper.h

-8
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ The full license is in the LICENSE file, distributed with this software.
1818

1919
PANDAS_INLINE npy_int64 get_nat(void) { return NPY_MIN_INT64; }
2020

21-
PANDAS_INLINE npy_datetime get_datetime64_value(PyObject* obj) {
22-
return ((PyDatetimeScalarObject*)obj)->obval;
23-
}
24-
25-
PANDAS_INLINE npy_timedelta get_timedelta64_value(PyObject* obj) {
26-
return ((PyTimedeltaScalarObject*)obj)->obval;
27-
}
28-
2921
PANDAS_INLINE int is_integer_object(PyObject* obj) {
3022
return (!PyBool_Check(obj)) && PyArray_IsIntegerScalar(obj);
3123
}

pandas/_libs/tslibs/conversion.pyx

+10-7
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,16 @@ def ensure_datetime64ns(ndarray arr):
104104
return result
105105

106106
unit = get_datetime64_unit(arr.flat[0])
107-
for i in range(n):
108-
if ivalues[i] != NPY_NAT:
109-
pandas_datetime_to_datetimestruct(ivalues[i], unit, &dts)
110-
iresult[i] = dtstruct_to_dt64(&dts)
111-
check_dts_bounds(&dts)
112-
else:
113-
iresult[i] = NPY_NAT
107+
if unit == PANDAS_FR_ns:
108+
result = arr
109+
else:
110+
for i in range(n):
111+
if ivalues[i] != NPY_NAT:
112+
pandas_datetime_to_datetimestruct(ivalues[i], unit, &dts)
113+
iresult[i] = dtstruct_to_dt64(&dts)
114+
check_dts_bounds(&dts)
115+
else:
116+
iresult[i] = NPY_NAT
114117

115118
return result
116119

0 commit comments

Comments
 (0)