Skip to content

remove datetime.pxd #18654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pandas/_libs/hashing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def hash_object_array(ndarray[object] arr, object key, object encoding='utf8'):
bytes data, k
uint8_t *kb
uint64_t *lens
char **vecs, *cdata
char **vecs
char *cdata
object val

k = <bytes>key.encode(encoding)
Expand Down
64 changes: 0 additions & 64 deletions pandas/_libs/src/datetime.pxd

This file was deleted.

3 changes: 1 addition & 2 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ from cpython.datetime cimport (PyDateTime_Check, PyDate_Check,
timedelta, datetime, date)
# import datetime C API
PyDateTime_IMPORT
# this is our datetime.pxd
from datetime cimport _string_to_dts


from tslibs.np_datetime cimport (check_dts_bounds,
pandas_datetimestruct,
_string_to_dts,
dt64_to_dtstruct, dtstruct_to_dt64,
pydatetime_to_dt64, pydate_to_dt64,
get_datetime64_value,
Expand Down
3 changes: 1 addition & 2 deletions pandas/_libs/tslibs/conversion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ PyDateTime_IMPORT

from np_datetime cimport (check_dts_bounds,
pandas_datetimestruct,
pandas_datetime_to_datetimestruct, _string_to_dts,
PANDAS_DATETIMEUNIT, PANDAS_FR_ns,
npy_datetime,
dt64_to_dtstruct, dtstruct_to_dt64,
get_datetime64_unit, get_datetime64_value,
pydatetime_to_dt64)

from datetime cimport pandas_datetime_to_datetimestruct, _string_to_dts

from util cimport (is_string_object,
is_datetime64_object,
is_integer_object, is_float_object)
Expand Down
7 changes: 7 additions & 0 deletions pandas/_libs/tslibs/np_datetime.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ cdef extern from "../src/datetime/np_datetime.h":
PANDAS_FR_fs
PANDAS_FR_as

void pandas_datetime_to_datetimestruct(npy_datetime val,
PANDAS_DATETIMEUNIT fr,
pandas_datetimestruct *result) nogil

int days_per_month_table[2][12]
int dayofweek(int y, int m, int d) nogil
int is_leapyear(int64_t year) nogil
Expand All @@ -71,3 +75,6 @@ cdef int64_t pydate_to_dt64(date val, pandas_datetimestruct *dts)
cdef npy_datetime get_datetime64_value(object obj) nogil
cdef npy_timedelta get_timedelta64_value(object obj) nogil
cdef PANDAS_DATETIMEUNIT get_datetime64_unit(object obj) nogil

cdef int _string_to_dts(object val, pandas_datetimestruct* dts,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can deprivatize at some point

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yah I’m currently running asv on a proposed change to string_to_dts that would make to_datetime and Timestamp behavior more similar (or at least make the dissimilarity more obvious)

int* out_local, int* out_tzoffset) except? -1
40 changes: 39 additions & 1 deletion pandas/_libs/tslibs/np_datetime.pyx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# cython: profile=False

from cpython cimport Py_EQ, Py_NE, Py_GE, Py_GT, Py_LT, Py_LE
from cpython cimport (Py_EQ, Py_NE, Py_GE, Py_GT, Py_LT, Py_LE,
PyUnicode_Check, PyUnicode_AsASCIIString)

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

pandas_datetimestruct _NS_MIN_DTS, _NS_MAX_DTS

cdef extern from "../src/datetime/np_datetime_strings.h":
int parse_iso_8601_datetime(char *str, int len,
pandas_datetimestruct *out,
int *out_local, int *out_tzoffset)

# ----------------------------------------------------------------------
# numpy object inspection

Expand Down Expand Up @@ -161,3 +167,35 @@ cdef inline int64_t pydate_to_dt64(date val,
dts.hour = dts.min = dts.sec = dts.us = 0
dts.ps = dts.as = 0
return dtstruct_to_dt64(dts)


cdef inline int _string_to_dts(object val, pandas_datetimestruct* dts,
int* out_local, int* out_tzoffset) except? -1:
cdef:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when you do change this, pls add doc-string (and same below)

int result
char *tmp

if PyUnicode_Check(val):
val = PyUnicode_AsASCIIString(val)

tmp = val
result = _cstring_to_dts(tmp, len(val), dts, out_local, out_tzoffset)

if result == -1:
raise ValueError('Unable to parse %s' % str(val))
return result


cdef inline int _cstring_to_dts(char *val, int length,
pandas_datetimestruct* dts,
int* out_local, int* out_tzoffset) except? -1:
# Note: without this "extra layer" between _string_to_dts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have to investigate this, it is pretty weird

# and parse_iso_8601_datetime, calling _string_to_dts raises
# `SystemError: <class 'str'> returned a result with an error set`
# in Python3
cdef:
int result

result = parse_iso_8601_datetime(val, length,
dts, out_local, out_tzoffset)
return result
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,7 @@ def pxd(name):
'pandas/_libs/src/datetime/np_datetime_strings.h']
np_datetime_sources = ['pandas/_libs/src/datetime/np_datetime.c',
'pandas/_libs/src/datetime/np_datetime_strings.c']
tseries_depends = np_datetime_headers + ['pandas/_libs/src/datetime.pxd',
'pandas/_libs/tslibs/np_datetime.pxd']
tseries_depends = np_datetime_headers + ['pandas/_libs/tslibs/np_datetime.pxd']

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