Repository navigation
Do time arithmetic on numpy arrays instead of pandas Index objects - #159
Merged
Merged
Conversation
Extract the datetime fields (year, month, day, dayofyear, julian date, fractional hour) as numpy arrays once, at the top of each algorithm. Arithmetic on pandas Index objects allocates a new Index per operation, which dominated runtime for small inputs; SG2 also indexed pandas Series by a per-timestamp row array to look up its delta-T coefficients. Outputs are bit-identical (165 output arrays over 20k random timestamps, 4 sites, all algorithms). Speed-up vs main: 2-6x for a single timestamp, 1.0-1.8x for a year at 1-minute resolution (SG2 1.8x). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013LERsHQC5eP3qvgBsbbory
Member
|
Even if AI, I think it would be worth to review and merge if appropriate? |
Contributor
Author
|
Wanted to add a bit more improvements, but yeah, why not merge time arithmetic first. |
kandersolar
approved these changes
Oct 13, 2026
kandersolar
left a comment
Member
There was a problem hiding this comment.
This seems fine to me, and an optimization/consistency improvement I was going to do soon anyway. I observe speed ratios (ratio of new to old) in the range 1.1x to 1.3x, except for SG2 which is more like 1.5x and USNO which is more like 8x (!)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extract the datetime fields (year, month, day, dayofyear, julian date, fractional hour) as numpy arrays once, at the top of each algorithm. Arithmetic on pandas Index objects allocates a new Index per operation, which dominated runtime for small inputs; SG2 also indexed pandas Series by a per-timestamp row array to look up its delta-T coefficients.
Outputs are bit-identical (165 output arrays over 20k random timestamps, 4 sites, all algorithms). Speed-up vs main: 2-6x for a single timestamp, 1.0-1.8x for a year at 1-minute resolution (SG2 1.8x).