Repository navigation
fix: keep the offset's resolution with an array n and in time_ranges - #308
Merged
Merged
Conversation
Closes #304 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
The focused implementation is consistent with scalar behavior and is comprehensively tested.
0 open findings
What changed in this PR
Fixes datetime offset precision loss and overflow handling in pandas-backed operations.
Changes:
- Preserves finer datetime resolutions for array offsets.
- Reworks datetime range generation to use
offset_times. - Adds coverage for precision, overflow, timezone, Arrow, and empty inputs.
| File | Description |
|---|---|
utilsforecast/processing.py |
Corrects offset resolution, overflow validation, and range generation. |
tests/test_processing.py |
Tests the corrected behavior and edge cases. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Saul (nasaul)
approved these changes
Oct 13, 2026
Saul (nasaul)
left a comment
Contributor
There was a problem hiding this comment.
LGTM. Array n now matches scalar n for numpy and tz-aware times, and time_ranges no longer repeats timestamps with sub-unit freqs.
A few pyarrow issues that already exist on main (not introduced here), could go in a follow-up:
- pyarrow + sub-unit non-Tick offset raises:
out.astype(times.dtype)casts back to the input's arrow unit. Casting to anArrowDtypewithout's unit would fix it.t = pd.Series(pd.to_datetime(["2020-01-31 10:00:00"])).astype("timestamp[s][pyarrow]") offset_times(t, pd.DateOffset(milliseconds=500), np.array([1])) # ArrowInvalid: Casting from timestamp[ms] to timestamp[s] would lose data
date32[pyarrow]with a Tick freq givesAttributeError: 'pyarrow.lib.DataType' object has no attribute 'unit'from_dt_unit. Scalarnfails too, so it's only the error message.time_rangeswith pyarrow timestamp starts raisesArrowTypeError: No temporal attributes found on objectfor any freq (exceptperiods=0). Probably the most relevant one, since pyarrow-backed pandas is getting more common.
José Morales (jmoralez)
added a commit
that referenced
this pull request
Oct 13, 2026
Drops keep_resolution and the arrow handling in time_ranges, which now come from offset_times after #308. Co-Authored-By: Claude Opus 5.5 <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.
Closes #304.
offset_timeswith an arraynandtime_rangeslost the resolution of offsets finer than the times' unit: an arrayncast the result back to the input unit, andtime_rangestruncated the values, which repeats timestamps (e.g.datetime64[s]starts with"500ms"gave[t, t, t+1s]).Changes
offset_timeswith an arraynnow returns the same unit as a scalarn:Tickoffsets no longer cast back to the input unit, which also removes a pandasFutureWarningabout concatenating empty entries.Tickoffsets use the finer of the times' and the offset's resolution, as pandas does (e.g.Milli(1000)on[s]times gives[ms]).time_rangeswith datetimes builds each period withoffset_times(starts, freq, i)and reorders the result per series, so it agrees withoffset_timesby construction:periods=0returns an empty Series with the starts' dtype instead of raising.Dwent from ~4.1s to ~15ms).offset_timeswith an arraynand aTickoffset raisesOutOfBoundsTimedeltawhenn * freqoverflows, andOverflowErrorwhen an unsignedndoesn't fit in int64, instead of silently wrapping around. This matches a scalarn.🤖 Generated with Claude Code