KeyError: 'k' missing
- Dominant language
- Python
- Stars
- 20.4k
- Forks
- 4.6k
- Avg merge
- 19h 52m
- Merged PRs (30d)
- 1
Description
Hello,
I'm new to prophet and trying to 2 years old code from friend to improve a project.
By doing so, I am meeting an issue on prediction where a key seems to be missing somewhere in prediction process internaly.
I do not really get the meaning of this key and still hasn't found the source of the issue. On a hundred reference to predict, only 3 where correctly done.
Legacy code is known to run on version 1.0.1, while I upgraded to latest version (1.1.5) using poetry.
I searched in existing issue and googled for some time but did not find anything yet. :'(
Any idea of what could be happening ?
Exact error stack is:
```
│ │
│ /home/app/app/adapters/predictions/prophet.py:162 in predict │
│ │
│ 159 │ │ predictForDateDataFrame["ds"] = to_datetime(predictForDateDataFrame["ds"]) │
│ 160 │ │ │
│ 161 │ │ try: │
│ ❱ 162 │ │ │ forecast = self.__model.predict(predictForDateDataFrame) │
│ 163 │ │ │ for col in ["yhat", "yhat_lower", "yhat_upper"]: │
│ 164 │ │ │ │ forecast[col] = forecast[col].clip(lower=0.0) │
│ 165 │ │ │ │ forecast[col] = forecast[col].astype(int) │
│ │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ data = │ │ │ ds y │ │
│ │ 1294 2023-12-27 363 │ │
│ │ 1295 2024-01-01 1316 │ │
│ │ 1296 2024-01-08 2193 │ │
│ │ 1297 2024-01-15 2935 │ │
│ │ 1298 2024-01-22 3879 │ │
│ │ 1299 2024-01-29 5735 │ │
│ │ 1300 2024-02-05 7602 │ │
│ │ 1301 2024-02-12 6586 │ │
│ │ 1302 2024-02-19 5897 │ │
│ │ 1303 2024-02-26 6225 │ │
│ │ 1304 2024-03-04 7379 │ │
│ │ 1305 2024-03-11 10891 │ │
│ │ 1306 2024-03-18 10617 │ │
│ │ 1307 2024-03-25 9326 │ │
│ │ 1308 2024-04-01 6673 │ │
│ │ 1309 2024-04-08 5293 │ │
│ │ 1310 2024-04-15 4715 │ │
│ │ 1311 2024-04-22 4121 │ │
│ │ 1312 2024-04-29 3735 │ │
│ │ 1313 2024-05-06 3265 │ │
│ │ 1314 2024-05-13 1252 │ │
│ │ predictForDateDataFrame = │ │ ds │ │
│ │ 0 2024-05-13 │ │
│ │ 1 2024-05-20 │ │
│ │ 2 2024-05-27 │ │
│ │ 3 2024-06-03 │ │
│ │ 4 2024-06-10 │ │
│ │ .. ... │ │
│ │ 81 2025-12-01 │ │
│ │ 82 2025-12-08 │ │
│ │ 83 2025-12-15 │ │
│ │ 84 2025-12-22 │ │
│ │ 85 2025-12-29 │ │
│ │ │ │
│ │ [86 rows x 1 columns] │ │
│ │ predictForDates = [ │ │
│ │ │ datetime.date(2024, 5, 13), │ │
│ │ │ datetime.date(2024, 5, 20), │ │
│ │ │ datetime.date(2024, 5, 27), │ │
│ │ │ datetime.date(2024, 6, 3), │ │
│ │ │ datetime.date(2024, 6, 10), │ │
│ │ │ datetime.date(2024, 6, 17), │ │
│ │ │ datetime.date(2024, 6, 24), │ │
│ │ │ datetime.date(2024, 7, 1), │ │
│ │ │ datetime.date(2024, 7, 8), │ │
│ │ │ datetime.date(2024, 7, 15), │ │
│ │ │ ... +76 │ │
│ │ ] │ │
│ │ productRef = 17 │ │
│ │ self = │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ │
│ /home/vscode/venv/lib/python3.12/site-packages/prophet/forecaster.py:1272 in predict │
│ │
│ 1269 │ │ │ │ raise ValueError('Dataframe has no rows.') │
│ 1270 │ │ │ df = self.setup_dataframe(df.copy()) │
│ 1271 │ │ │
│ ❱ 1272 │ │ df['trend'] = self.predict_trend(df) │
│ 1273 │ │ seasonal_components = self.predict_seasonal_components(df) │
│ 1274 │ │ if self.uncertainty_samples: │
│ 1275 │ │ │ intervals = self.predict_uncertainty(df, vectorized) │
│ │
│ ╭────────────────────────────── locals ──────────────────────────────╮ │
│ │ df = │ │ ds floor t │ │
│ │ 0 2024-05-13 0.0 1.000000 │ │
│ │ 1 2024-05-20 0.0 1.001550 │ │
│ │ 2 2024-05-27 0.0 1.003100 │ │
│ │ 3 2024-06-03 0.0 1.004650 │ │
│ │ 4 2024-06-10 0.0 1.006200 │ │
│ │ .. ... ... ... │ │
│ │ 81 2025-12-01 0.0 1.125554 │ │
│ │ 82 2025-12-08 0.0 1.127104 │ │
│ │ 83 2025-12-15 0.0 1.128654 │ │
│ │ 84 2025-12-22 0.0 1.130204 │ │
│ │ 85 2025-12-29 0.0 1.131754 │ │
│ │ │ │
│ │ [86 rows x 3 columns] │ │
│ │ self = │ │
│ │ vectorized = True │ │
│ ╰────────────────────────────────────────────────────────────────────╯ │
│ │
│ /home/vscode/venv/lib/python3.12/site-packages/prophet/forecaster.py:1375 in predict_trend │
│ │
│ 1372 │ │ ------- │
│ 1373 │ │ Vector with trend on prediction dates. │
│ 1374 │ │ """ │
│ ❱ 1375 │ │ k = np.nanmean(self.params['k']) │
│ 1376 │ │ m = np.nanmean(self.params['m']) │
│ 1377 │ │ deltas = np.nanmean(self.params['delta'], axis=0) │
│ 1378 │
│ │
│ ╭─────────────────────────── locals ───────────────────────────╮ │
│ │ df = │ │ ds floor t │ │
│ │ 0 2024-05-13 0.0 1.000000 │ │
│ │ 1 2024-05-20 0.0 1.001550 │ │
│ │ 2 2024-05-27 0.0 1.003100 │ │
│ │ 3 2024-06-03 0.0 1.004650 │ │
│ │ 4 2024-06-10 0.0 1.006200 │ │
│ │ .. ... ... ... │ │
│ │ 81 2025-12-01 0.0 1.125554 │ │
│ │ 82 2025-12-08 0.0 1.127104 │ │
│ │ 83 2025-12-15 0.0 1.128654 │ │
│ │ 84 2025-12-22 0.0 1.130204 │ │
│ │ 85 2025-12-29 0.0 1.131754 │ │
│ │ │ │
│ │ [86 rows x 3 columns] │ │
│ │ self = │ │
│ ╰──────────────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
KeyError: 'k'
```
Python version: 3.12 (vscode dev container)
Prophet: 1.1.5
Contributor guide
Assessment
This issue has not been assessed yet.