Repository navigation
fix: do not modify the holidays dataframe passed to Prophet - #2757
Merged
Merged
Conversation
validate_inputs converted the ds column of the holidays dataframe in place, and self.holidays was the dataframe passed by the caller, so constructing a Prophet changed the caller's dataframe (string dates became datetime64). Work on a copy instead.
tcuongd
approved these changes
Oct 21, 2026
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.
Fixes #2754
Root cause
Prophet.__init__stores theholidaysargument asself.holidays, andvalidate_inputsthen converts the dates withself.holidays['ds'] = pd.to_datetime(self.holidays['ds']).self.holidaysis the caller's own dataframe, so constructing a model changes it:Because the object is shared, later edits to that dataframe also change the holidays of a model that was already created, and the models built by
diagnostics.prophet_copyduring cross validation share it with the original model.Fix
Copy the dataframe in
validate_inputsright after the type and column check, beforedsis converted. The conversion now only affects the model's copy. The check still runs first, so invalid input raises the sameValueErroras before, and the model's holidays are unchanged.Test
Added
TestProphetHolidays::test_holidays_does_not_modify_input. It passes a holidays dataframe with string dates andlower_window,upper_windowandprior_scalecolumns, checks that the dataframe is unchanged after constructing aProphet, and checks that the model'sdscolumn is still converted to datetime.assert_frame_equalwithAttribute "dtype" are differentfor columnds(datetime64[us]vsstron pandas 3,datetime64[ns]vsobjecton pandas 1.5).cd python && python -m pytest prophet/tests/: 118 passed, 2 skipped on main; 119 passed, 2 skipped on this branch.cd python && pyrefly check: 0 errors (18 suppressed) on both main and this branch.Tested on Windows with Python 3.12.5, pandas 3.0.6, numpy 2.5.4 and cmdstanpy 1.3.0, and the
TestProphetHolidaystests also with Python 3.10.20 and pandas 1.5.3.