Skip to content

fix: do not modify the holidays dataframe passed to Prophet - #2757

Merged
tcuongd merged 1 commit into
facebook:mainfrom
Thanatos9404:fix-holidays-mutation
Oct 21, 2026
Merged

tcuongd merged 1 commit into
facebook:mainfrom
Thanatos9404:fix-holidays-mutation

Conversation

@Thanatos9404

Copy link
Copy Markdown
Contributor

Fixes #2754

Root cause

Prophet.__init__ stores the holidays argument as self.holidays, and validate_inputs then converts the dates with self.holidays['ds'] = pd.to_datetime(self.holidays['ds']). self.holidays is the caller's own dataframe, so constructing a model changes it:

holidays = pd.DataFrame({'holiday': ['xmas'], 'ds': ['2024-12-25']})
Prophet(holidays=holidays)
print(holidays['ds'].dtype)  # datetime64 instead of the original strings

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_copy during cross validation share it with the original model.

Fix

Copy the dataframe in validate_inputs right after the type and column check, before ds is converted. The conversion now only affects the model's copy. The check still runs first, so invalid input raises the same ValueError as 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 and lower_window, upper_window and prior_scale columns, checks that the dataframe is unchanged after constructing a Prophet, and checks that the model's ds column is still converted to datetime.

  • Before the fix: fails in assert_frame_equal with Attribute "dtype" are different for column ds (datetime64[us] vs str on pandas 3, datetime64[ns] vs object on pandas 1.5).
  • After the fix: passes.
  • 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 TestProphetHolidays tests also with Python 3.10.20 and pandas 1.5.3.

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.
@meta-cla meta-cla Bot added the CLA Signed label Oct 14, 2026
@tcuongd
tcuongd merged commit 45dff69 into facebook:main Oct 21, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prophet.__init__ mutates the user’s holidays DataFrame (ds column converted in place)

2 participants