SEPURI-SAI-KRISHNA opened a new pull request, #43205:
URL: https://github.com/apache/superset/pull/43205
<!-- PR TITLE: fix(chart): map the remaining time grains for Prophet
forecasting -->
### SUMMARY
Enabling **Forecast** (Advanced Analytics → Predictive Analytics) fails with
`Unsupported time grain` for five time grains that Superset itself offers in
the Time Grain control.
`PROPHET_TIME_GRAIN_MAP` covered 16 of the 21 `TimeGrain` values. `prophet()`
rejects anything missing from it:
```python
if time_grain not in PROPHET_TIME_GRAIN_MAP:
raise InvalidPostProcessingError(_("Unsupported time grain:
%(time_grain)s", ...))
```
The five gaps, and how reachable each is — every one is exposed by real
engine
specs through their `_time_grain_expressions`:
| TimeGrain | ISO | engine specs offering it |
| --- | --- | --- |
| `FIVE_SECONDS` | `PT5S` | 40 (Postgres, CockroachDB, SQLite, DataFusion,
…) |
| `THIRTY_SECONDS` | `PT30S` | 42 (Postgres, CockroachDB, SQLite,
DataFusion, …) |
| `HALF_HOUR` | `PT0.5H` | 15 (SQLite, Presto, GSheets, Kusto, …) |
| `SIX_HOURS` | `PT6H` | 15 (SQLite, Presto, Druid, GSheets, …) |
| `QUARTER_YEAR` | `P0.25Y` | 10 (SQLite, Shillelagh, GSheets, Ocient, …) |
Three of them are also advertised as valid by the API contract:
`ChartDataProphetOptionsSchema.time_grain` validates with
`validate.OneOf(choices=get_time_grain_choices())`, and `PT5S`, `PT30S` and
`PT6H` are all in `builtin_time_grains`. So the OpenAPI spec publishes them
as
accepted values for the forecast operation, and the request then fails.
Two of the five are simply alternate ISO-8601 spellings of grains that
already
work — `PT0.5H` is `PT30M`, `P0.25Y` is `P3M` — so picking one spelling
forecasts and the other errors, for the same interval.
Reproducing on `master`:
```python
>>> prophet(df=prophet_df, time_grain="PT6H", periods=3,
confidence_interval=0.9)
InvalidPostProcessingError: Unsupported time grain: PT6H
```
This PR maps all five to their pandas frequency aliases (`5s`, `30s`,
`30min`,
`6h`, and the same quarter alias `QUARTER` already uses). No `TimeGrain`
value
is left unmapped.
Related but distinct: #42145 fixed `prophet()` being called with a *missing*
`time_grain`. This fixes grains that are present and valid but unmapped.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — backend-only fix.
### TESTING INSTRUCTIONS
```bash
pytest tests/unit_tests/pandas_postprocessing/test_prophet.py
```
Three tests are added:
| test | asserts |
| --- | --- |
| `test_prophet_previously_unmapped_time_grains` | all five grains now
produce a forecast (parametrized; fails on `master`) |
| `test_prophet_every_time_grain_is_mapped` | no `TimeGrain` is missing from
the map, so this cannot regress |
| `test_prophet_alias_time_grains_match_their_canonical_form` |
`HALF_HOUR`/`QUARTER_YEAR` resolve identically to `THIRTY_MINUTES`/`QUARTER` |
Manually: on a Postgres or SQLite dataset, build a time-series chart, set
Time
Grain to **6 hour** (or **5 second** / **30 second**), then enable Forecast
under Advanced Analytics. On `master` the chart errors with "Unsupported time
grain"; with this change it forecasts.
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
### CHECKLIST
- [ ] CI checks pass
- [x] Tests added/updated
- [ ] Documentation updated
- [x] PR title follows conventions
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]