[Bug Fix] Returning timeseries_limit_metric in table viz get_data (#9196)
* Returning timeseries_limit_metric in table viz get_data * Fixing issue with include_time field * Reformatting and adding a test * Changing if/else structure * Reformatting
This commit is contained in:
parent
ace0ba9456
commit
4f73f8a1f9
|
|
@ -575,15 +575,30 @@ class TableViz(BaseViz):
|
|||
the percent metrics have yet to be transformed.
|
||||
"""
|
||||
|
||||
if not self.should_be_timeseries() and DTTM_ALIAS in df:
|
||||
del df[DTTM_ALIAS]
|
||||
|
||||
non_percent_metric_columns = []
|
||||
# Transform the data frame to adhere to the UI ordering of the columns and
|
||||
# metrics whilst simultaneously computing the percentages (via normalization)
|
||||
# for the percent metrics.
|
||||
non_percent_metric_columns = (
|
||||
|
||||
if DTTM_ALIAS in df:
|
||||
if self.should_be_timeseries():
|
||||
non_percent_metric_columns.append(DTTM_ALIAS)
|
||||
else:
|
||||
del df[DTTM_ALIAS]
|
||||
|
||||
non_percent_metric_columns.extend(
|
||||
self.form_data.get("all_columns") or self.form_data.get("groupby") or []
|
||||
) + utils.get_metric_names(self.form_data.get("metrics") or [])
|
||||
)
|
||||
|
||||
non_percent_metric_columns.extend(
|
||||
utils.get_metric_names(self.form_data.get("metrics") or [])
|
||||
)
|
||||
|
||||
timeseries_limit_metric = utils.get_metric_name(
|
||||
self.form_data.get("timeseries_limit_metric")
|
||||
)
|
||||
if timeseries_limit_metric:
|
||||
non_percent_metric_columns.append(timeseries_limit_metric)
|
||||
|
||||
percent_metric_columns = utils.get_metric_names(
|
||||
self.form_data.get("percent_metrics") or []
|
||||
|
|
|
|||
|
|
@ -407,6 +407,32 @@ class TableVizTestCase(SupersetTestCase):
|
|||
with self.assertRaises(Exception):
|
||||
test_viz.should_be_timeseries()
|
||||
|
||||
def test_adhoc_metric_with_sortby(self):
|
||||
metrics = [
|
||||
{
|
||||
"expressionType": "SIMPLE",
|
||||
"aggregate": "SUM",
|
||||
"label": "sum_value",
|
||||
"column": {"column_name": "value1", "type": "DOUBLE"},
|
||||
}
|
||||
]
|
||||
form_data = {
|
||||
"metrics": metrics,
|
||||
"timeseries_limit_metric": {
|
||||
"expressionType": "SIMPLE",
|
||||
"aggregate": "SUM",
|
||||
"label": "SUM(value1)",
|
||||
"column": {"column_name": "value1", "type": "DOUBLE"},
|
||||
},
|
||||
"order_desc": False,
|
||||
}
|
||||
|
||||
df = pd.DataFrame({"SUM(value1)": [15], "sum_value": [15]})
|
||||
datasource = self.get_datasource_mock()
|
||||
test_viz = viz.TableViz(datasource, form_data)
|
||||
data = test_viz.get_data(df)
|
||||
self.assertEqual(["sum_value", "SUM(value1)"], data["columns"])
|
||||
|
||||
|
||||
class DistBarVizTestCase(SupersetTestCase):
|
||||
def test_groupby_nulls(self):
|
||||
|
|
|
|||
Loading…
Reference in New Issue