mirror of
https://github.com/apache/superset.git
synced 2026-04-07 18:35:15 +00:00
fix: show error if rolling window returns empty df (#10572)
* fix: show error if rolling window returns empty df * add test
This commit is contained in:
@@ -216,6 +216,14 @@ class BaseViz:
|
||||
df = df.cumsum()
|
||||
if min_periods:
|
||||
df = df[min_periods:]
|
||||
if df.empty:
|
||||
raise QueryObjectValidationError(
|
||||
_(
|
||||
"Applied rolling window did not return any data. Please make sure "
|
||||
"the source query satisfies the minimum periods defined in the "
|
||||
"rolling window."
|
||||
)
|
||||
)
|
||||
return df
|
||||
|
||||
def get_samples(self) -> List[Dict[str, Any]]:
|
||||
|
||||
@@ -24,12 +24,13 @@ from typing import Any, Dict, List, Set
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import pytest
|
||||
|
||||
import tests.test_app
|
||||
import superset.viz as viz
|
||||
from superset import app
|
||||
from superset.constants import NULL_STRING
|
||||
from superset.exceptions import SpatialException
|
||||
from superset.exceptions import QueryObjectValidationError, SpatialException
|
||||
from superset.utils.core import DTTM_ALIAS
|
||||
|
||||
from .base_tests import SupersetTestCase
|
||||
@@ -1266,6 +1267,26 @@ class TestTimeSeriesViz(SupersetTestCase):
|
||||
[1.0, 1.5, 2.0, 2.5],
|
||||
)
|
||||
|
||||
def test_apply_rolling_without_data(self):
|
||||
datasource = self.get_datasource_mock()
|
||||
df = pd.DataFrame(
|
||||
index=pd.to_datetime(
|
||||
["2019-01-01", "2019-01-02", "2019-01-05", "2019-01-07"]
|
||||
),
|
||||
data={"y": [1.0, 2.0, 3.0, 4.0]},
|
||||
)
|
||||
test_viz = viz.BigNumberViz(
|
||||
datasource,
|
||||
{
|
||||
"metrics": ["y"],
|
||||
"rolling_type": "cumsum",
|
||||
"rolling_periods": 4,
|
||||
"min_periods": 4,
|
||||
},
|
||||
)
|
||||
with pytest.raises(QueryObjectValidationError):
|
||||
test_viz.apply_rolling(df)
|
||||
|
||||
|
||||
class TestBigNumberViz(SupersetTestCase):
|
||||
def test_get_data(self):
|
||||
|
||||
Reference in New Issue
Block a user