make_future_dataframe returns 1970 dates when `ds` is an integer column
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
Research direction
Run the minimal repro and compare m.history['ds'] after fit() with the frame returned by make_future_dataframe(); the history is parsed correctly while the future frame is not. Trace make_future_dataframe and the integer-ds conversion used during fitting, then make the future dates continue from 2024-03-01. Done when the repro prints 2024-03-01 through 2024-03-03 and the integer-year case with freq="YS" continues from 2020.
Written by the indexing model from the issue text.
Description
what happens
when the ds column holds integers (for example 20240101 from a csv of YYYYMMDD dates, or plain integer years like 2019), fit() reads them as dates and trains on the right dates. make_future_dataframe() on the same model does not: it returns timestamps in 1970, and predict() on that frame then forecasts for 1970. no error or warning is raised.
expected
make_future_dataframe() should continue from the last date the model was fitted on, the same as it does when ds holds strings or datetimes.
minimal repro
import logging
import pandas as pd
import prophet
from prophet import Prophet
logging.getLogger("cmdstanpy").setLevel(logging.ERROR)
logging.getLogger("prophet").setLevel(logging.ERROR)
print("prophet", prophet.__version__, "pandas", pd.__version__)
# daily data whose dates are stored as YYYYMMDD integers, which is what
# pd.read_csv gives for a column like 20240101,20240102,...
dates = pd.date_range("2024-01-01", periods=60, freq="D")
df = pd.DataFrame({
"ds": dates.strftime("%Y%m%d").astype("int64"),
"y": [float(i % 7) for i in range(60)],
})
print("ds dtype:", df["ds"].dtype, "first:", df["ds"].iloc[0], "last:", df["ds"].iloc[-1])
m = Prophet().fit(df)
print("history ds range:", m.history["ds"].min(), "->", m.history["ds"].max())
future = m.make_future_dataframe(periods=3, include_history=False)
print("make_future_dataframe(periods=3, include_history=False):")
print(future)
forecast = m.predict(future)
print("forecast dates:", forecast["ds"].dt.strftime("%Y-%m-%d").tolist())
output:
prophet 1.5.0 pandas 3.1.1
ds dtype: int64 first: 20240101 last: 20240229
history ds range: 2024-01-01 00:00:00 -> 2024-02-29 00:00:00
make_future_dataframe(periods=3, include_history=False):
ds
0 1970-01-02 00:00:00.020240229
1 1970-01-03 00:00:00.020240229
2 1970-01-04 00:00:00.020240229
forecast dates: ['1970-01-02', '1970-01-03', '1970-01-04']
the history is right (2024-01-01 to 2024-02-29), but the future frame starts on 1970-01-02 instead of 2024-03-01.
the same happens with integer years: ds = [2000, 2001, ..., 2019] fits on 2000-01-01 to 2019-01-01, and make_future_dataframe(periods=2, freq="YS", include_history=False) returns 1971-01-01 00:00:00.000002019 and 1972-01-01 00:00:00.000002019.
impact
the usual forecasting flow (fit, make_future_dataframe, predict) runs to the end without any error and gives a forecast for the wrong dates. integer ds values are handled on purpose when fitting and predicting (they are converted to strings before parsing, added for #675), so this looks like one place where the dates kept for make_future_dataframe are parsed differently from the dates used for fitting.
versions
- prophet 1.5.0 from pypi, and
mainat 5cf15c0 - pandas 3.1.1, numpy 2.5.5, cmdstanpy 1.3.2
- python 3.12, macos arm64
- Dominant language
- Python
- Stars
- 20.5k
- Forks
- 4.6k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from facebook/prophet
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Linux x86-64 wheel: overlapping ELF load pages in prophet_model.bin on Linux 4.18 kernelsPossibly taken @nicolasdalsass claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
-
model_to_json drops the fitted regressor predictor; deserialized model can't predictPossibly taken @caiotheodoro claimed this 10 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
plot_components fails for logistic models with minmax scaling and no floorPossibly taken @RaphaelFakhri claimed this 38 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
All issues in facebook/prophet
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
available bug good first issue tooling
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Nixitov/Riptide-Native#816 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
SpikeInterface/spikeinterface#5008 ·
Maintainers usually reply within 2 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
teng-lin/notebooklm-py#2593 ·
Maintainers usually reply within 1 day
-
claimed-by:collie role:small-fix status:running
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Beovulfo/herd-sdlc#325 · 1 comment ·
Maintainers usually reply within 1 day