Skip to content

Commit d916351

Browse files
jbrockmendeljreback
authored andcommitted
remove datetime.pxd (#18654)
1 parent 0f6c846 commit d916351

File tree

7 files changed

+51
-72
lines changed

7 files changed

+51
-72
lines changed

pandas/_libs/hashing.pyx

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def hash_object_array(ndarray[object] arr, object key, object encoding='utf8'):
4242
bytes data, k
4343
uint8_t *kb
4444
uint64_t *lens
45-
char **vecs, *cdata
45+
char **vecs
46+
char *cdata
4647
object val
4748

4849
k = <bytes>key.encode(encoding)

pandas/_libs/src/datetime.pxd

-64
This file was deleted.

pandas/_libs/tslib.pyx

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ from cpython.datetime cimport (PyDateTime_Check, PyDate_Check,
2323
timedelta, datetime, date)
2424
# import datetime C API
2525
PyDateTime_IMPORT
26-
# this is our datetime.pxd
27-
from datetime cimport _string_to_dts
2826

2927

3028
from tslibs.np_datetime cimport (check_dts_bounds,
3129
pandas_datetimestruct,
30+
_string_to_dts,
3231
dt64_to_dtstruct, dtstruct_to_dt64,
3332
pydatetime_to_dt64, pydate_to_dt64,
3433
get_datetime64_value,

pandas/_libs/tslibs/conversion.pyx

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ PyDateTime_IMPORT
2020

2121
from np_datetime cimport (check_dts_bounds,
2222
pandas_datetimestruct,
23+
pandas_datetime_to_datetimestruct, _string_to_dts,
2324
PANDAS_DATETIMEUNIT, PANDAS_FR_ns,
2425
npy_datetime,
2526
dt64_to_dtstruct, dtstruct_to_dt64,
2627
get_datetime64_unit, get_datetime64_value,
2728
pydatetime_to_dt64)
2829

29-
from datetime cimport pandas_datetime_to_datetimestruct, _string_to_dts
30-
3130
from util cimport (is_string_object,
3231
is_datetime64_object,
3332
is_integer_object, is_float_object)

pandas/_libs/tslibs/np_datetime.pxd

+7
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ cdef extern from "../src/datetime/np_datetime.h":
5050
PANDAS_FR_fs
5151
PANDAS_FR_as
5252

53+
void pandas_datetime_to_datetimestruct(npy_datetime val,
54+
PANDAS_DATETIMEUNIT fr,
55+
pandas_datetimestruct *result) nogil
56+
5357
int days_per_month_table[2][12]
5458
int dayofweek(int y, int m, int d) nogil
5559
int is_leapyear(int64_t year) nogil
@@ -71,3 +75,6 @@ cdef int64_t pydate_to_dt64(date val, pandas_datetimestruct *dts)
7175
cdef npy_datetime get_datetime64_value(object obj) nogil
7276
cdef npy_timedelta get_timedelta64_value(object obj) nogil
7377
cdef PANDAS_DATETIMEUNIT get_datetime64_unit(object obj) nogil
78+
79+
cdef int _string_to_dts(object val, pandas_datetimestruct* dts,
80+
int* out_local, int* out_tzoffset) except? -1

pandas/_libs/tslibs/np_datetime.pyx

+39-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# -*- coding: utf-8 -*-
22
# cython: profile=False
33

4-
from cpython cimport Py_EQ, Py_NE, Py_GE, Py_GT, Py_LT, Py_LE
4+
from cpython cimport (Py_EQ, Py_NE, Py_GE, Py_GT, Py_LT, Py_LE,
5+
PyUnicode_Check, PyUnicode_AsASCIIString)
56

67
from cpython.datetime cimport (datetime, date,
78
PyDateTime_IMPORT,
@@ -33,6 +34,11 @@ cdef extern from "../src/datetime/np_datetime.h":
3334

3435
pandas_datetimestruct _NS_MIN_DTS, _NS_MAX_DTS
3536

37+
cdef extern from "../src/datetime/np_datetime_strings.h":
38+
int parse_iso_8601_datetime(char *str, int len,
39+
pandas_datetimestruct *out,
40+
int *out_local, int *out_tzoffset)
41+
3642
# ----------------------------------------------------------------------
3743
# numpy object inspection
3844

@@ -161,3 +167,35 @@ cdef inline int64_t pydate_to_dt64(date val,
161167
dts.hour = dts.min = dts.sec = dts.us = 0
162168
dts.ps = dts.as = 0
163169
return dtstruct_to_dt64(dts)
170+
171+
172+
cdef inline int _string_to_dts(object val, pandas_datetimestruct* dts,
173+
int* out_local, int* out_tzoffset) except? -1:
174+
cdef:
175+
int result
176+
char *tmp
177+
178+
if PyUnicode_Check(val):
179+
val = PyUnicode_AsASCIIString(val)
180+
181+
tmp = val
182+
result = _cstring_to_dts(tmp, len(val), dts, out_local, out_tzoffset)
183+
184+
if result == -1:
185+
raise ValueError('Unable to parse %s' % str(val))
186+
return result
187+
188+
189+
cdef inline int _cstring_to_dts(char *val, int length,
190+
pandas_datetimestruct* dts,
191+
int* out_local, int* out_tzoffset) except? -1:
192+
# Note: without this "extra layer" between _string_to_dts
193+
# and parse_iso_8601_datetime, calling _string_to_dts raises
194+
# `SystemError: <class 'str'> returned a result with an error set`
195+
# in Python3
196+
cdef:
197+
int result
198+
199+
result = parse_iso_8601_datetime(val, length,
200+
dts, out_local, out_tzoffset)
201+
return result

setup.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,7 @@ def pxd(name):
453453
'pandas/_libs/src/datetime/np_datetime_strings.h']
454454
np_datetime_sources = ['pandas/_libs/src/datetime/np_datetime.c',
455455
'pandas/_libs/src/datetime/np_datetime_strings.c']
456-
tseries_depends = np_datetime_headers + ['pandas/_libs/src/datetime.pxd',
457-
'pandas/_libs/tslibs/np_datetime.pxd']
456+
tseries_depends = np_datetime_headers + ['pandas/_libs/tslibs/np_datetime.pxd']
458457

459458
# some linux distros require it
460459
libraries = ['m'] if not is_platform_windows() else []

0 commit comments

Comments
 (0)