You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/08/29 03:35:59 UTC
(superset) branch master updated: fix(chart): map the remaining time grains for Prophet forecasting (#43205)
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new b30d5690286 fix(chart): map the remaining time grains for Prophet forecasting (#43205)
b30d5690286 is described below
commit b30d56902861741efc1fc84fbc466cc7620608a9
Author: Sepuri Sai Krishna <sa...@gmail.com>
AuthorDate: Sat Aug 29 09:05:52 2026 +0530
fix(chart): map the remaining time grains for Prophet forecasting (#43205)
---
superset/utils/pandas_postprocessing/utils.py | 8 ++++
.../pandas_postprocessing/test_prophet.py | 46 ++++++++++++++++++++++
2 files changed, 54 insertions(+)
diff --git a/superset/utils/pandas_postprocessing/utils.py b/superset/utils/pandas_postprocessing/utils.py
index 79b4796a737..75bbc0411a2 100644
--- a/superset/utils/pandas_postprocessing/utils.py
+++ b/superset/utils/pandas_postprocessing/utils.py
@@ -86,16 +86,24 @@ ALLOWLIST_CUMULATIVE_FUNCTIONS = (
PROPHET_TIME_GRAIN_MAP: dict[str, str] = {
TimeGrain.SECOND: "s",
+ TimeGrain.FIVE_SECONDS: "5s",
+ TimeGrain.THIRTY_SECONDS: "30s",
TimeGrain.MINUTE: "min",
TimeGrain.FIVE_MINUTES: "5min",
TimeGrain.TEN_MINUTES: "10min",
TimeGrain.FIFTEEN_MINUTES: "15min",
TimeGrain.THIRTY_MINUTES: "30min",
+ # An alternate ISO-8601 spelling of THIRTY_MINUTES that a number of engine
+ # specs expose instead; the two denote the same interval.
+ TimeGrain.HALF_HOUR: "30min",
TimeGrain.HOUR: "h",
+ TimeGrain.SIX_HOURS: "6h",
TimeGrain.DAY: "D",
TimeGrain.WEEK: "W",
TimeGrain.MONTH: "ME" if _PANDAS_VERSION >= (2, 2) else "M",
TimeGrain.QUARTER: "QE" if _PANDAS_VERSION >= (2, 2) else "Q",
+ # An alternate ISO-8601 spelling of QUARTER, as with HALF_HOUR above.
+ TimeGrain.QUARTER_YEAR: "QE" if _PANDAS_VERSION >= (2, 2) else "Q",
TimeGrain.YEAR: "YE" if _PANDAS_VERSION >= (2, 2) else "A",
TimeGrain.WEEK_STARTING_SUNDAY: "W-SUN",
TimeGrain.WEEK_STARTING_MONDAY: "W-MON",
diff --git a/tests/unit_tests/pandas_postprocessing/test_prophet.py b/tests/unit_tests/pandas_postprocessing/test_prophet.py
index 8e7e1b225eb..6e15f56ca1e 100644
--- a/tests/unit_tests/pandas_postprocessing/test_prophet.py
+++ b/tests/unit_tests/pandas_postprocessing/test_prophet.py
@@ -392,3 +392,49 @@ def test_prophet_does_not_clamp_yhat_below_zero_for_negative_actuals():
forecast_periods = 2
forecast_yhat = result["balance__yhat"].iloc[-forecast_periods:]
assert (forecast_yhat < 0).any()
+
+
+def test_prophet_every_time_grain_is_mapped():
+ """No `TimeGrain` may be missing from `PROPHET_TIME_GRAIN_MAP`.
+
+ Engine specs offer these grains in the Time Grain control, and the
+ `ChartDataProphetOptionsSchema.time_grain` field advertises them in the
+ OpenAPI spec, so an unmapped grain surfaces as "Unsupported time grain"
+ on a value the UI and the API both present as valid.
+ """
+ from superset.constants import TimeGrain
+ from superset.utils.pandas_postprocessing.utils import PROPHET_TIME_GRAIN_MAP
+
+ unmapped = [
+ grain.name for grain in TimeGrain if grain not in PROPHET_TIME_GRAIN_MAP
+ ]
+ assert not unmapped, f"TimeGrain values missing a pandas frequency: {unmapped}"
+
+
+@pytest.mark.parametrize(
+ "time_grain",
+ ["PT5S", "PT30S", "PT0.5H", "PT6H", "P0.25Y"],
+)
+def test_prophet_previously_unmapped_time_grains(time_grain):
+ """These five grains raised "Unsupported time grain" despite being offered
+ by engine specs such as Postgres, SQLite, Presto and Druid."""
+ df = prophet(
+ df=prophet_df, time_grain=time_grain, periods=3, confidence_interval=0.9
+ )
+ assert {"a__yhat", "a__yhat_upper", "a__yhat_lower"} <= set(df.columns)
+
+
+def test_prophet_alias_time_grains_match_their_canonical_form():
+ """`HALF_HOUR`/`QUARTER_YEAR` are alternate ISO-8601 spellings of
+ `THIRTY_MINUTES`/`QUARTER` and must resolve to the same frequency."""
+ from superset.constants import TimeGrain
+ from superset.utils.pandas_postprocessing.utils import PROPHET_TIME_GRAIN_MAP
+
+ assert (
+ PROPHET_TIME_GRAIN_MAP[TimeGrain.HALF_HOUR]
+ == PROPHET_TIME_GRAIN_MAP[TimeGrain.THIRTY_MINUTES]
+ )
+ assert (
+ PROPHET_TIME_GRAIN_MAP[TimeGrain.QUARTER_YEAR]
+ == PROPHET_TIME_GRAIN_MAP[TimeGrain.QUARTER]
+ )