-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
CLN/PERF: simplify tslib.get_time_micros #18389
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
|
Since its just one function, how about just a timeit result 0.21.0
PR:
|
Codecov Report
@@ Coverage Diff @@
## master #18389 +/- ##
==========================================
- Coverage 91.35% 91.34% -0.02%
==========================================
Files 163 163
Lines 49695 49695
==========================================
- Hits 45401 45392 -9
- Misses 4294 4303 +9
Continue to review full report at Codecov.
|
pandas/_libs/tslib.pyx
Outdated
micros[i] = 1000000LL * (dts.hour * 60 * 60 + | ||
60 * dts.min + dts.sec) + dts.us | ||
|
||
micros = np.mod(dtindex, 86400000000000, dtype=np.int64) // 1000LL |
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.
pretty sure we have a constant somewhere rather than hard-coding 86400.....
also shouldn't this routine be in conversion?
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.
conversion would be reasonable. fields might be a better fit. I'm actually leaning towards "this doesn't need to be a function" since its a one-linear and only used once.
The constant you're thinking of is defined in conversion.
needs an update according to comments |
No thoughts on the "just put this one-liner in the one place its used" idea? |
cdef: | ||
ndarray[int64_t] micros | ||
|
||
micros = np.mod(dtindex, 86400000000000, dtype=np.int64) // 1000LL |
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.
don't we have this constant defined already somewhere?
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, it’s defined in conversion. But it’s all the same to the compiler right? If it was something that was liable to change and needed to be kept in sync (eg nat_strings) it would make sense to cimport it. But for a constant like this it isn’t worth the hassle; it’d be like defining DAYSPERWEEK=7 and importing that all over the place.
yeah, but rather actually have these defined in a single place (rather than scattered about), so in same vein could move |
I'm with you on the non-scattering. Anyway, moved this to fields a few minutes ago. |
ok, let's add to list to remove need for this |
tslib.get_time_micros
implementation is way more complicated than it needs to be. Instead of callingdt64_to_dtstruct
in a loop, this changes the function to one call tonp.mod
.AFAIK the
np.mod
call is to the python function, not sure if numpy exposes a cython version of mod. Then again, the function is only used once inindexes.datetimes
and isn't all that perf sensitive. It might not need to be in cython in the first place.Re-wrote inaccurate docstring.