diff --git a/superset/common/query_context_processor.py b/superset/common/query_context_processor.py index 003c174c2a17..8078868493b6 100644 --- a/superset/common/query_context_processor.py +++ b/superset/common/query_context_processor.py @@ -322,6 +322,16 @@ def processing_time_offsets( # pylint: disable=too-many-locals # multi-dimensional charts granularity = query_object.granularity index = granularity if granularity in df.columns else DTTM_ALIAS + if not pd.api.types.is_datetime64_any_dtype( + offset_metrics_df.get(index) + ): + raise QueryObjectValidationError( + _( + "A time column must be specified " + "when using a Time Comparison." + ) + ) + offset_metrics_df[index] = offset_metrics_df[index] - DateOffset( **normalize_time_delta(offset) )