REF: relocate _freq storage from DTA/TDA arrays to Index (GH#24566)#65322
Merged
mroeschke merged 4 commits intopandas-dev:mainfrom Apr 29, 2026
Merged
REF: relocate _freq storage from DTA/TDA arrays to Index (GH#24566)#65322mroeschke merged 4 commits intopandas-dev:mainfrom
mroeschke merged 4 commits intopandas-dev:mainfrom
Conversation
…566) PeriodArray.to_timestamp now returns a bare DatetimeArray; the freq inference moves to a new PeriodArray._to_timestamp_freq helper that PeriodIndex.to_timestamp consumes. Array-level to_timestamp no longer manages freq, matching the direction of earlier PRs that pulled freq management off DTA/TDA. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
DatetimeArray._generate_range and TimedeltaArray._generate_range now return bare arrays; the three callers (date_range, timedelta_range, DatetimeIndexOpsMixin.shift) stamp freq explicitly. Continues moving freq management off DTA/TDA toward the Index level. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…H#24566) _freq now lives on the Index. DatetimeTimedeltaMixin owns the class attribute, property getter, and validating setter; DatetimeIndexOpsMixin keeps a simpler getter that routes PeriodIndex through self._data.freq (still dtype-derived on the PeriodArray side). All former `self._data._freq = X` / `arr._freq = X` write sites across core/indexes/ now write `self._freq = X` on the wrapping Index. copy(), _view(), Index.__new__ (wrap-DTI/TDI case), and as_unit() explicitly carry _freq forward. pytables, DatetimeIndex.__new__ fastpath, and _pin_freq were updated to match. Pickle compat: DatetimeIndex/TimedeltaIndex __reduce__ now include freq in the dict; _new_DatetimeIndex / _new_TimedeltaIndex migrate legacy array-side _freq payloads up onto the Index on unpickle. Also fixed Grouper._codes_and_uniques to return the full Index (not ._values) for datetime-like BaseGrouper uniques so freq survives the trip through Index._with_infer — was causing pivot_table to drop freq. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…566) When freq was relocated from DatetimeIndexOpsMixin to DatetimeTimedeltaMixin, the docstring wasn't copied to the override. numpydoc validation flagged pandas.DatetimeIndex.freq / TimedeltaIndex.freq as missing a docstring, which the docbuild treats as an error via --warnings-are-errors. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
mroeschke
approved these changes
Apr 29, 2026
Member
|
Thanks @jbrockmendel |
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.
Summary
PeriodArray.to_timestampfreq inference intoPeriodArray._to_timestamp_freq(dta, target_freq, how). Array-levelto_timestampnow returns a bare DTA;PeriodIndex.to_timestampcalls the helper and stamps the result._generate_range.DatetimeArray._generate_rangeandTimedeltaArray._generate_rangenow return bare arrays; the three callers (date_range,timedelta_range,DatetimeIndexOpsMixin.shift) own the freq stamp._freqstorage from DTA/TDA toDatetimeTimedeltaMixin. Getter, validating setter, and class attribute all live on the Index now. Every former `self._data._freq = X` / `arr._freq = X` write site in `pandas/core/indexes/` is rewritten to stamp `self._freq` on the wrapping Index. `copy()`, `_view()`, `Index.new` (wrap-DTI/TDI case), and `as_unit()` explicitly carry `_freq` forward; `pytables`, `DatetimeIndex.new` fastpath, and `_pin_freq` were updated to match.Part of GH#24566. Follows up on #65266 / #65276 / #65285.
Test plan
🤖 Generated with Claude Code