-
Notifications
You must be signed in to change notification settings - Fork 17.7k
fix(pandas-postprocessing): handle prophet errors and validate minimum data points for forecast #41180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix(pandas-postprocessing): handle prophet errors and validate minimum data points for forecast #41180
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| # under the License. | ||
| from datetime import datetime | ||
| from importlib.util import find_spec | ||
| from unittest.mock import patch | ||
|
|
||
| import pandas as pd | ||
| import pytest | ||
|
|
@@ -186,6 +187,43 @@ def test_prophet_incorrect_time_grain(): | |
| ) | ||
|
|
||
|
|
||
| def test_prophet_insufficient_data(): | ||
| single_row_df = pd.DataFrame( | ||
| { | ||
| DTTM_ALIAS: [datetime(2022, 1, 1)], | ||
| "sales": [100.0], | ||
| } | ||
| ) | ||
| with pytest.raises(InvalidPostProcessingError, match="at least 2 data points"): | ||
| prophet( | ||
| df=single_row_df, | ||
| time_grain="P1D", | ||
| periods=3, | ||
| confidence_interval=0.9, | ||
| ) | ||
|
|
||
|
|
||
| def test_prophet_fit_error(): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Add a concise docstring under this new function definition to describe the expected error-handling behavior. [custom_rule] Severity Level: Minor Why it matters? 🤔This is a newly added Python function and it has no docstring. That violates the rule requiring new functions and classes to include docstrings. (Use Cmd/Ctrl + Click for best experience) Prompt for AI Agent 🤖This is a comment left during a code review.
**Path:** tests/unit_tests/pandas_postprocessing/test_prophet.py
**Line:** 206:206
**Comment:**
*Custom Rule: Add a concise docstring under this new function definition to describe the expected error-handling behavior.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Declining — no existing test functions in this file use docstrings, and adding one only to the new functions would be inconsistent. Test name is self-describing.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ Customized review instruction saved! Instruction:
Applied to:
💡 To manage or update this instruction, visit: CodeAnt AI Settings |
||
| if find_spec("prophet") is None: | ||
| pytest.skip("prophet not installed") | ||
|
|
||
| with patch( | ||
| "superset.utils.pandas_postprocessing.prophet._prophet_fit_and_predict" | ||
| ) as mock_fit: | ||
| mock_fit.side_effect = InvalidPostProcessingError( | ||
| "Unable to generate forecast: Dataframe has fewer than 2 non-NaN rows." | ||
| ) | ||
| with pytest.raises( | ||
| InvalidPostProcessingError, match="Unable to generate forecast" | ||
| ): | ||
| prophet( | ||
| df=prophet_df, | ||
| time_grain="P1D", | ||
| periods=3, | ||
| confidence_interval=0.9, | ||
| ) | ||
|
|
||
|
|
||
| def test_prophet_uncertainty_lower_bound_can_be_negative_for_negative_series(): | ||
| """ | ||
| Regression for #21734: when the input series contains negative values, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Add an explicit return type annotation to this new test function (for example
-> None) to satisfy the rule requiring fully typed new Python functions. [custom_rule]Severity Level: Minor⚠️
Why it matters? 🤔
This is a newly added Python function and it has no return type annotation. The custom rule requires new Python code to be fully typed, so omitting
-> Noneis a real violation.(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declining — no existing test functions in this file (or in the broader test suite) use
-> Noneannotations or docstrings. Adding them only to the two new functions would be inconsistent with the established pattern here.