Skip to content

fix(pandas-postprocessing): handle prophet errors and validate minimum data points for forecast#41180

Open
yousoph wants to merge 3 commits into
apache:masterfrom
preset-io:fix-sc-111157-forecast-prophet-error
Open

fix(pandas-postprocessing): handle prophet errors and validate minimum data points for forecast#41180
yousoph wants to merge 3 commits into
apache:masterfrom
preset-io:fix-sc-111157-forecast-prophet-error

Conversation

@yousoph

@yousoph yousoph commented Jun 18, 2026

Copy link
Copy Markdown
Member

SUMMARY

Two related bugs in the prophet/forecast post-processing pipeline caused any forecast chart to surface an unhandled 500 error when data conditions were unfavourable — most visibly when a high-granularity time grain (e.g. Day) was used with a dataset that had only a single data point in the selected range.

Fix 1 — minimum data-point guard (prophet.py):
Prophet hard-requires ≥ 2 data points to fit a model. The old code had no pre-flight check; Prophet raised a bare ValueError that propagated as an unhandled 500. A clear InvalidPostProcessingError("Forecast requires at least 2 data points") is now raised before any prophet call.

Fix 2 — wrap fit/predict in try/except (prophet.py):
Even when enough data exists, Prophet can raise for other reasons (bad data, convergence failures, etc.). The model.fit(), model.make_future_dataframe(), and model.predict() calls are now wrapped in a try/except Exception that re-raises as InvalidPostProcessingError with the original message, giving the user a readable error instead of a 500.

Fix 3 — update deprecated pandas frequency aliases (utils.py):
PROPHET_TIME_GRAIN_MAP used aliases that are deprecated in pandas 2.2+ ("S", "H", "M", "Q", "A"):

  • "S""s", "H""h" (safe on all supported pandas versions)
  • "M" / "Q" / "A""ME" / "QE" / "YE" when pandas ≥ 2.2, old aliases otherwise (the new names raise ValueError on the currently pinned pandas 2.1.4)

BEFORE/AFTER

Before: Enabling forecast with sparse daily data → unhandled ValueError from Prophet → HTTP 500, generic error shown in the chart.

After: InvalidPostProcessingError("Forecast requires at least 2 data points") → HTTP 422 with a user-readable message.

TESTING INSTRUCTIONS

pytest tests/unit_tests/pandas_postprocessing/test_prophet.py -v

New tests:

  • test_prophet_insufficient_data — verifies the < 2 data points guard raises correctly
  • test_prophet_fit_error — verifies prophet fitting errors surface as InvalidPostProcessingError

All 11 prophet tests pass.

ADDITIONAL INFORMATION

  • Fixes customer-reported issue: forecast broken on "Vehicle Sales" dataset at "Day" granularity (internal: SC-111157 / PPR-1319)
  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration
  • Introduces new feature or API
  • Removes existing feature or API

🤖 Generated with Claude Code

…r prophet forecast

- Add try/except around model.fit() and model.predict() in
  _prophet_fit_and_predict, re-raising prophet errors as
  InvalidPostProcessingError with a user-readable message
- Add minimum 2 data points validation in prophet() before fitting,
  which is prophet's hard requirement; sparse daily data (e.g. Vehicle
  Sales dataset at Day granularity) could have only 1 row and trigger
  an unhandled 500 error
- Update deprecated pandas frequency aliases: 'S'→'s', 'H'→'h', and
  add a runtime version check so 'M'/'Q'/'A' map to 'ME'/'QE'/'YE'
  on pandas>=2.2 (the new aliases are invalid on pinned pandas 2.1.4)
- Add tests for insufficient data and prophet fitting errors

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bito-code-review

bito-code-review Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #16a87b

Actionable Suggestions - 0
Review Details
  • Files reviewed - 3 · Commit Range: 3eacaea..3eacaea
    • superset/utils/pandas_postprocessing/prophet.py
    • superset/utils/pandas_postprocessing/utils.py
    • tests/unit_tests/pandas_postprocessing/test_prophet.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

)


def test_prophet_insufficient_data():

Copy link
Copy Markdown
Contributor

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 -> None is a real violation.

Fix in Cursor Fix in VSCode Claude

(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:** 190:190
**Comment:**
	*Custom Rule: Add an explicit return type annotation to this new test function (for example `-> None`) to satisfy the rule requiring fully typed new Python functions.

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
👍 | 👎

Copy link
Copy Markdown
Member Author

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 -> None annotations or docstrings. Adding them only to the two new functions would be inconsistent with the established pattern here.

)


def test_prophet_fit_error():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Fix in Cursor Fix in VSCode Claude

(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
👍 | 👎

Copy link
Copy Markdown
Member Author

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 use docstrings, and adding one only to the new functions would be inconsistent. Test name is self-describing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Customized review instruction saved!

Instruction:

Do not require docstrings for new test functions when the surrounding test file uses self-describing test names and existing tests in that file omit docstrings; keep the style consistent within the file.

Applied to:

  • tests/unit_tests/pandas_postprocessing/**

💡 To manage or update this instruction, visit: CodeAnt AI Settings

@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 20.00000% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.30%. Comparing base (883b7a2) to head (57f98b7).
⚠️ Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
superset/utils/pandas_postprocessing/prophet.py 11.11% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #41180      +/-   ##
==========================================
+ Coverage   63.73%   64.30%   +0.57%     
==========================================
  Files        2651     2651              
  Lines      144737   144753      +16     
  Branches    33402    33403       +1     
==========================================
+ Hits        92242    93079     +837     
+ Misses      50827    50004     -823     
- Partials     1668     1670       +2     
Flag Coverage Δ
hive 39.32% <20.00%> (+<0.01%) ⬆️
mysql 58.06% <20.00%> (-0.01%) ⬇️
postgres 58.12% <20.00%> (-0.01%) ⬇️
presto 40.91% <20.00%> (+<0.01%) ⬆️
python 59.57% <20.00%> (+1.22%) ⬆️
sqlite 57.78% <20.00%> (-0.01%) ⬇️
unit 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

yousoph and others added 2 commits June 18, 2026 08:49
Add noqa: BLE001 to broad exception catch (required since Prophet can
raise a mix of ValueError/RuntimeError), and collapse single-argument
raise to one line per ruff-format.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…in tests

- Add noqa: C901 to prophet() — the new data-point guard legitimately adds
  one branch, pushing cyclomatic complexity to 11; suppressing is correct here
- Wrap long pytest.raises() call in test_prophet_fit_error to stay under 88 chars

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bito-code-review

bito-code-review Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #863d21

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 3eacaea..57f98b7
    • superset/utils/pandas_postprocessing/prophet.py
    • tests/unit_tests/pandas_postprocessing/test_prophet.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant