Validate ds range early; clear error for out-of-bounds datetime64[ns] #2690
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
Prophet crashed when
dscontains dates outside pandas datetime64[ns] range. Example: 3969-12-02.Root cause
preprocess()castsdsviapd.to_datetime(...), which forces ns precision and raisesOutOfBoundsDatetimedeep in pandas.Fix
Add
_validate_ds_ns_range(df["ds"])at the start ofpreprocess(). It parses to plaindatewithout pandas and raises a clear ValueError with the supported range (1677-09-21 to 2262-04-11) and the first offending value.Tests
test_in_range_okverifies normal fit with valid dates.test_out_of_range_raisesasserts ValueError and message substringdatetime64[ns].Behavior
No changes for valid inputs. Out-of-range data now gets an immediate, actionable error instead of a pandas traceback.
Fixes #2689.