-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Replaced PANDAS_DATETIMEUNIT with NPY_DATETIMEUNIT #21863
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
Conversation
pandas/_libs/tslibs/conversion.pxd
Outdated
@@ -33,3 +32,21 @@ cdef maybe_datetimelike_to_i8(object val) | |||
cdef int64_t tz_convert_utc_to_tzlocal(int64_t utc_val, tzinfo tz) | |||
|
|||
cpdef datetime localize_pydatetime(datetime dt, object tz) | |||
|
|||
cdef extern from "numpy/ndarraytypes.h": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if there is a better way to do this declaration. Right now I copy/pasted in the three files where it is need but is there a shared place to put that for shared access across the modules?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it is in np_datetime.pxd, it can be cimport
ed from there.
pandas/_libs/tslibs/conversion.pxd
Outdated
@@ -33,3 +32,21 @@ cdef maybe_datetimelike_to_i8(object val) | |||
cdef int64_t tz_convert_utc_to_tzlocal(int64_t utc_val, tzinfo tz) | |||
|
|||
cpdef datetime localize_pydatetime(datetime dt, object tz) | |||
|
|||
cdef extern from "numpy/ndarraytypes.h": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is done in np_datetime.pxd, I'd just cimport from there rather than copying this.
Aside from that note on repeated imports, this looks like a step in the right direction. The other super-easy change-over is |
pandas/_libs/tslibs/conversion.pxd
Outdated
@@ -7,7 +7,6 @@ from numpy cimport int64_t, int32_t | |||
|
|||
from np_datetime cimport pandas_datetimestruct | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file isn't linted, but if it were, I think it would want two lines before the cdef class
Codecov Report
@@ Coverage Diff @@
## master #21863 +/- ##
=======================================
Coverage 91.92% 91.92%
=======================================
Files 160 160
Lines 49906 49906
=======================================
Hits 45875 45875
Misses 4031 4031
Continue to review full report at Codecov.
|
I still can’t find a way to access functions in numpy’s _datetime.h. Not even sure what is possible in C-land. @chris-b1 are you the right person to ask about this? |
@jbrockmendel not sure what you are looking for out of that but it doesn't appear that header is included in numpy's Line 128 in 5d0daa0
Though that most likely violates a lot of best practices |
Though looking at it I don't believe |
The hope was that it is somehow passed through via an |
Yeah, even if it were possible I don't think we should be depending on private API of numpy - presumably why some bits (e.g. datetime string parsing) were vendored in the first place. |
cc @charris do you recall if these existed in numpy < 1.6 ? |
AFAICT goes at least back to 1.4 |
AFAICT the code was vendored b/c at the time pandas supported older numpy versions that did not yet have It would also be super-convenient to be able to use the numpy versions in src/ujson/python/obj2JSON.c, as that would let us de-couple the remaing src/datetime code. |
thanks @WillAyd and @jbrockmendel for the comments. Agree that the vendored code, just wanted the rationale documented here :> |
progress towards #21852
git diff upstream/master -u -- "*.py" | flake8 --diff
Working on my C-fu as well. There may be a better way to do this (ex: even adding NPY_DATETIMEUNIT to Cython/includes) but figured I'd offer this up for review
@jbrockmendel