PERF: vectorize PeriodIndex.from_fields#65921
Open
jbrockmendel wants to merge 2 commits into
Open
Conversation
Add period_ordinals_from_fields Cython function that converts arrays of year/month/day/hour/minute/second fields to period ordinals in a single C-level loop, replacing the Python-space list-append loop in _range_from_fields, and vectorize the quarter-to-calendar-month conversion with numpy ops. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
e71f340 to
9647626
Compare
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Split out of GH-65195 (which also vectorized
to_datetime(DataFrame)); this PR is just thePeriodIndex.from_fieldshalf, with the more involvedto_datetimeassembly path to follow in a separate PR.Adds a
period_ordinals_from_fieldsCython function that converts arrays of date/time fields to period ordinals in a single C-level loop, replacing the Python-space list-append loop in_range_from_fields, and vectorizes the quarter-to-calendar-month conversion with numpy ops. Fields that would overflow theint32npy_datetimestructslots raiseOverflowError, matchingperiod_ordinalonmain.PeriodIndex.from_fields(2k monthly)PeriodIndex.from_fields(100k monthly)Test plan
pandas/tests/indexes/period/andpandas/tests/arrays/period/passpandas/tests/scalar/period/andpandas/tests/tslibs/passQ-DEC, all-6-field hourly periods, empty arrays, and field values outsideint32range raising🤖 Generated with Claude Code