You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: compute time_idx in steps for non-monthly panel data - #1636
add_time_idx_col (used for ts_forecast_panel when the data has no time_idx column, and in the TFT predict path) is broken for any frequency other than monthly/yearly:
timestamps - timestamps.min() / freq only divides the minimum, so time_idx ends up as the raw nanosecond timestamp. For daily data starting 2024-01-01 the first value is 1704067199999980288 instead of 0.
The values are computed from the unique dates and assigned back to X, so every row whose timestamp repeats (any panel with more than one series) gets NaN, and .astype("int") raises IntCastingNaNError.
Series.view was removed in pandas 3, so there it fails with AttributeError before any of that.
This computes (timestamp - first timestamp) // step for every row instead.
Related issue number
None, found while reading the time series code.
Checks
I've used pre-commit to lint the changes in this PR (note the same in integrated in our CI checks).
add_time_idx_col divided only the minimum timestamp by the step
(operator precedence), so time_idx held raw nanosecond values, and it
assigned the per-unique-date series back to X, which left NaN for any
repeated timestamp in panel data and crashed the int cast. It also
used Series.view, which pandas 3 removed.
The reason will be displayed to describe this comment to others. Learn more.
Overall review of the complete PR: no blocking code issue found; approval withheld pending CI.
The corrected subtraction/division order computes elapsed time steps, and assigning from the original timestamp column preserves repeated panel dates and row-index alignment. Both focused regression tests passed locally. The review-code harness is clean and Copilot's current Balanced review recommends approval with no open issues. The current head still has failing build checks, so the all-CI-passed approval gate is not met. This review does not approve the PR for merge.
The reason will be displayed to describe this comment to others. Learn more.
Overall review at c99d0484e355d7df37ffbfd8fa0060e133ebab21: the ordinary daily/panel correction is useful, but one P2 correctness issue remains in the new step mapping. Complete regular month-end and timezone-aware daily series still receive duplicate indices and artificial gaps; the inline review includes independently executed reproductions.
Validation: python -m pytest test\automl\test_add_time_idx_col.py -q --disable-warnings passed (2 passed). Separate repeated-panel calendar/DST fixtures fail the consecutive-step invariant, and the review-code whole-PR Low harness independently identified the same root cause. Green CI and a positive Copilot recommendation do not resolve this source defect, so approval is withheld. No contributor code was modified.
The reason will be displayed to describe this comment to others. Learn more.
P2 - Count calendar steps rather than fixed elapsed durations. This floor division assumes that every step has the same epoch duration, even when pd.infer_freq identifies a calendar frequency. With six complete month ends from 2021-01-31, freq='ME', the actual indices are [0,0,1,2,4,5]. With six America/New_York local days from 2021-03-12, crossing spring DST, they are [0,1,2,2,3,4]. Each should have relative steps [0,1,2,3,4,5]. I reproduced both with the dates repeated across two panel groups; distinct observations collide within each group even though no timestamps are missing.
TFT consumes these indices for dataset validation, encoder windows, and decoder alignment, so valid regular series can be rejected or use a distorted forecast window. Map recognized calendar-frequency steps to ordinal positions instead of dividing elapsed time by a modal duration, preserving equal indices for shared panel timestamps and row order. Please add exact repeated-panel month-end and spring-DST regressions. This is an incomplete correction of the helper, not a claim that the original main implementation already handled these cases correctly.
The reason will be displayed to describe this comment to others. Learn more.
Fixed in e796511. When pd.infer_freq finds a frequency the index is now the position among the unique timestamps, so month ends and the DST week both give [0..5], with shared panel dates kept equal. Irregular series still fall back to elapsed time over the modal step so gaps are kept. Added the month-end and spring-DST panel tests plus one for the gap case.
DST causes irregular daily data to lose calendar-day spacing
flaml/automl/data.py:266
The irregular fallback still loses calendar-day steps across DST. For New York midnights on March 12, 13, 14, 15, and 17, 2021, infer_freq returns None. The modal interval is 24 hours, so this division produces [0, 1, 2, 2, 4] instead of [0, 1, 2, 3, 5]. Distinct dates then share a time_idx. Preserve calendar-day spacing for irregular daily data without changing elapsed-time indexing for intraday data, and add a regression combining DST with a missing date.
The reason will be displayed to describe this comment to others. Learn more.
Reviewed e796511b5c07e38efe7a190063396202aa98f934 with review-code (Low, gpt-6.1-sol). The complete regular month-end/DST mapping is repaired on modern pandas, but changes are requested for supported-version compatibility.
[P2] Keep the new month-end fixture within the declared pandas range. Both AutoML and test extras permit pandas>=1.1.4, while the new freq="ME" fixture requires pandas 2.2+. I reproduced ValueError: Invalid frequency: ME natively with Python 3.10/pandas 1.5.3. pd.offsets.MonthEnd() produces the same six dates on pandas 1.5.3, 2.3.3 and 3.0.5. This corroborates the existing Copilot finding; no duplicate inline is being added.
The actual focused file reports 5 passed on pandas 3.0.5, but 2 failed, 3 passed on pandas 1.5.3. The second failure is the timezone test: the unchanged pd.infer_freq(Series) call rejects timezone-aware Series on that runtime. Exact prior and current code both show that TypeError, so I am not attributing it to the new ordinal branch. The same dates wrapped in a DatetimeIndex infer D; please ensure the newly added DST regression also runs across the declared pandas range.
Fifteen native calendar/DST/permutation controls verify the modern regular-grid fix and original panel-row/index preservation. Existing irregular modal-gap/DST limitations are recorded separately and are not claimed fixed or introduced by this correction. I have not resolved my older signed calendar/DST thread while supported-version handling remains incomplete, and no other reviewer's thread was touched.
No contributor implementation/test or installed package was changed. Approval remains withheld.
Posted by thinkall-agent-auto-reviewer
This branch has not been deployed
No deployments
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
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.
Why are these changes needed?
add_time_idx_col(used forts_forecast_panelwhen the data has notime_idxcolumn, and in the TFT predict path) is broken for any frequency other than monthly/yearly:timestamps - timestamps.min() / freqonly divides the minimum, sotime_idxends up as the raw nanosecond timestamp. For daily data starting 2024-01-01 the first value is 1704067199999980288 instead of 0.X, so every row whose timestamp repeats (any panel with more than one series) gets NaN, and.astype("int")raisesIntCastingNaNError.Series.viewwas removed in pandas 3, so there it fails withAttributeErrorbefore any of that.This computes
(timestamp - first timestamp) // stepfor every row instead.Related issue number
None, found while reading the time series code.
Checks
test/automl/test_add_time_idx_col.pyfails on main (pandas 2.3 and 3.0) and passes with the change.