Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added _update-notifier-last-checked
Empty file.
59 changes: 0 additions & 59 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,65 +1076,6 @@ def get_data(self, df: pd.DataFrame) -> VizData:
}


class BigNumberViz(BaseViz):

"""Put emphasis on a single metric with this big number viz"""

viz_type = "big_number"
verbose_name = _("Big Number with Trendline")
credits = 'a <a href="https://github.com/airbnb/superset">Superset</a> original'
is_timeseries = True

@deprecated(deprecated_in="3.0")
def query_obj(self) -> QueryObjectDict:
query_obj = super().query_obj()
metric = self.form_data.get("metric")
if not metric:
raise QueryObjectValidationError(_("Pick a metric!"))
query_obj["metrics"] = [self.form_data.get("metric")]
self.form_data["metric"] = metric
return query_obj

@deprecated(deprecated_in="3.0")
def get_data(self, df: pd.DataFrame) -> VizData:
if df.empty:
return None

df = df.pivot_table(
index=DTTM_ALIAS,
columns=[],
values=self.metric_labels,
dropna=False,
aggfunc=np.min, # looking for any (only) value, preserving `None`
)
df = self.apply_rolling(df)
df[DTTM_ALIAS] = df.index
return super().get_data(df)


class BigNumberTotalViz(BaseViz):

"""Put emphasis on a single metric with this big number viz"""

viz_type = "big_number_total"
verbose_name = _("Big Number")
credits = 'a <a href="https://github.com/airbnb/superset">Superset</a> original'
is_timeseries = False

@deprecated(deprecated_in="3.0")
def query_obj(self) -> QueryObjectDict:
query_obj = super().query_obj()
metric = self.form_data.get("metric")
if not metric:
raise QueryObjectValidationError(_("Pick a metric!"))
query_obj["metrics"] = [self.form_data.get("metric")]
self.form_data["metric"] = metric

# Limiting rows is not required as only one cell is returned
query_obj["row_limit"] = None
return query_obj


class NVD3TimeSeriesViz(NVD3Viz):

"""A rich line chart component with tons of options"""
Expand Down
36 changes: 4 additions & 32 deletions tests/integration_tests/viz_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ def test_apply_rolling(self):
data={"y": [1.0, 2.0, 3.0, 4.0]},
)
self.assertEqual(
viz.BigNumberViz(
viz.NVD3TimeSeriesViz(
datasource,
{
"metrics": ["y"],
Expand All @@ -1325,7 +1325,7 @@ def test_apply_rolling(self):
[1.0, 3.0, 6.0, 10.0],
)
self.assertEqual(
viz.BigNumberViz(
viz.NVD3TimeSeriesViz(
datasource,
{
"metrics": ["y"],
Expand All @@ -1339,7 +1339,7 @@ def test_apply_rolling(self):
[1.0, 3.0, 5.0, 7.0],
)
self.assertEqual(
viz.BigNumberViz(
viz.NVD3TimeSeriesViz(
datasource,
{
"metrics": ["y"],
Expand All @@ -1361,7 +1361,7 @@ def test_apply_rolling_without_data(self):
),
data={"y": [1.0, 2.0, 3.0, 4.0]},
)
test_viz = viz.BigNumberViz(
test_viz = viz.NVD3TimeSeriesViz(
datasource,
{
"metrics": ["y"],
Expand All @@ -1374,34 +1374,6 @@ def test_apply_rolling_without_data(self):
test_viz.apply_rolling(df)


class TestBigNumberViz(SupersetTestCase):
def test_get_data(self):
datasource = self.get_datasource_mock()
df = pd.DataFrame(
data={
DTTM_ALIAS: pd.to_datetime(
["2019-01-01", "2019-01-02", "2019-01-05", "2019-01-07"]
),
"y": [1.0, 2.0, 3.0, 4.0],
}
)
data = viz.BigNumberViz(datasource, {"metrics": ["y"]}).get_data(df)
self.assertEqual(data[2], {DTTM_ALIAS: pd.Timestamp("2019-01-05"), "y": 3})

def test_get_data_with_none(self):
datasource = self.get_datasource_mock()
df = pd.DataFrame(
data={
DTTM_ALIAS: pd.to_datetime(
["2019-01-01", "2019-01-02", "2019-01-05", "2019-01-07"]
),
"y": [1.0, 2.0, None, 4.0],
}
)
data = viz.BigNumberViz(datasource, {"metrics": ["y"]}).get_data(df)
assert np.isnan(data[2]["y"])


class TestFilterBoxViz(SupersetTestCase):
def test_get_data(self):
form_data = {
Expand Down