facebook / facebook/prophet

[Feature request][Python] Custom/Specific Exceptions instead of using simply Exception

Open
#2,275 1 comment 0 reactions 0 assignees View on GitHub
enhancement py
Dominant language
Python
Stars
20.4k
Forks
4.6k
Avg merge
19h 52m
Merged PRs (30d)
1

Description

It would be great if there could be specifc excpetions in the code instead of always raising `Exception`.

This could be helpful when doing benchamarking with different paramenters and models.
In my code, I am iterating through models and I would love to catch the ["Prophet object can only be fit once."](https://github.com/facebook/prophet/blob/419ee68ac6b218b7a3f06a9ddaa6bc08041be1d6/python/prophet/forecaster.py#L1107) or the ["Model has not been fit."](https://github.com/facebook/prophet/blob/419ee68ac6b218b7a3f06a9ddaa6bc08041be1d6/python/prophet/forecaster.py#L1205) general exceptions.

Having a `ModelFitError` , for instance, could help to do the following:
```python

for model in models:
try:
future = model.fit(df)
forecast = model.predict(future)
except ModelFitError:
forecast = model.predict(future)

```

Basic example here, but I think it can be beneficial for more complex scenarios where `model`, `future` and `forecast` are part of a class.
Or the error can be passed when re-running the cell on a notebook.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.