-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Move remaining conversion functions to tslibs.conversion #18358
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
Codecov Report
@@ Coverage Diff @@
## master #18358 +/- ##
==========================================
- Coverage 91.38% 91.36% -0.02%
==========================================
Files 164 164
Lines 49790 49791 +1
==========================================
- Hits 45501 45493 -8
- Misses 4289 4298 +9
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #18358 +/- ##
==========================================
- Coverage 91.38% 91.36% -0.02%
==========================================
Files 164 164
Lines 49790 49791 +1
==========================================
- Hits 45501 45493 -8
- Misses 4289 4298 +9
Continue to review full report at Codecov.
|
pandas/_libs/tslibs/conversion.pyx
Outdated
@@ -73,6 +73,86 @@ cdef inline int64_t get_datetime64_nanos(object val) except? -1: | |||
|
|||
return ival | |||
|
|||
|
|||
def cast_to_nanoseconds(ndarray arr): | |||
cdef: |
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.
can you add doc-string
pandas/_libs/tslibs/conversion.pyx
Outdated
|
||
|
||
def datetime_to_datetime64(ndarray[object] values): | ||
cdef: |
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.
same
pandas/_libs/tslibs/conversion.pyx
Outdated
|
||
|
||
cdef inline _to_i8(object val): | ||
cdef: |
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.
doc-string.
can you rename this to something else. maybe datetime_to_i8
pandas/_libs/index.pyx
Outdated
@@ -13,7 +13,7 @@ cimport util | |||
|
|||
import numpy as np | |||
|
|||
from tslib cimport _to_i8 | |||
from tslibs.conversion cimport _maybe_datetimelike_to_i8 |
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.
note to de-private this at some point as well
pandas/_libs/tslibs/conversion.pyx
Outdated
@@ -73,6 +73,123 @@ cdef inline int64_t get_datetime64_nanos(object val) except? -1: | |||
|
|||
return ival | |||
|
|||
|
|||
def cast_to_nanoseconds(ndarray arr): |
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.
let's rename this maybe ensure_datetime64ns
if len(iresult) == 0: | ||
return result | ||
|
||
unit = get_datetime64_unit(arr.flat[0]) |
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.
prob should add some checks around this, IOW this could already be ns (TODO ok)
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.
Yah, this check is done elsewhere, will not be hard to implement.
If it weren't for datetime64[Y]
and datetime64[M]
we could take the pandas_datetime_to_datetimestruct
out of these funcs altogether, avoid converting back and forth.
pandas/_libs/tslibs/conversion.pyx
Outdated
|
||
Returns | ||
------- | ||
result : ndarray witth dtype int64 |
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.
typo
thanks! |
Slightly more efficient implementation of
_to_i8
.Importantly (or at least satisfyingly) gets
pandas_datetime_to_datetimestruct
usage centralized in conversion.