-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: implement pandas_timedelta_to_timedeltastruct for other resos #46465
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
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.
Nice! Glad to see you venture down the C path. This is a great start.
On first pass seems reasonable - your plan is to ultimately generate these for all precisions right? If so you might want to opt for a macro'ed approach similar to what's in khash.h rather than copy / pasting these.
Here's an example of what that might look like
pandas/pandas/_libs/src/klib/khash.h
Line 708 in 5414a2d
KHASH_MAP_INIT_STR(str, size_t) |
@@ -682,19 +682,23 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td, | |||
npy_int64 sfrac; | |||
npy_int64 ifrac; | |||
int sign; | |||
npy_int64 DAY_NS = 86400000000000LL; | |||
npy_int64 PER_DAY; |
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.
Just as a matter of convention should probably be lowercase. Usually you uppercase macros and constants, so on first read looking at these in the body of the functions a reader may mistakenly think that (DAY_NS was incorrect)
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.
good to know, will update
my thought was to follow the pattern for the dt64 code in the same file, which would probably mean refactoring out some helper functions but not using macros. Is getting comfortable with macros the next step of leveling up my C-fu? |
d7396eb
to
981159f
Compare
The macros would definitely be more advanced, at least as far as I understand. I am by no means an expert and not in a good enough position to teach, but from my personal experience the biggest things I've found to help grasp C are:
https://pandas.pydata.org/pandas-docs/stable/development/debugging_extensions.html might also help |
Thanks. Any objection to merging as-is? We may implement more units later, but this gets all the ones we're definitely doing. |
i guess it would make sense to have a corresponding function to go from tdstruct to td64. was that just not necessary at the time when it was nanos-only? |
None from me. My feedback is just long term consideration but I think it’s great to move forward with what’s there and consolidate later |
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 user facing necessarily right?
nope, just needed to implement non-nano Timedelta |
…andas-dev#46465) * ENH: implement pandas_timedelta_to_timedeltastruct for other resos * idiomatic naming
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.cc @WillAyd IIRC you implemented the original here. The new cases this implements are mostly copy/paste, so it wouldn't surprise me if there is a more elegant alternative. Thoughts?