mirror of
https://github.com/apache/superset.git
synced 2026-04-07 18:35:15 +00:00
fix(viz): missing groupby and broken adhoc metrics for boxplot (#12556)
This commit is contained in:
@@ -142,7 +142,7 @@ class QueryContext:
|
||||
def df_metrics_to_num(df: pd.DataFrame, query_object: QueryObject) -> None:
|
||||
"""Converting metrics to numeric when pandas.read_sql cannot"""
|
||||
for col, dtype in df.dtypes.items():
|
||||
if dtype.type == np.object_ and col in query_object.metrics:
|
||||
if dtype.type == np.object_ and col in query_object.metric_names:
|
||||
df[col] = pd.to_numeric(df[col], errors="coerce")
|
||||
|
||||
def get_data(self, df: pd.DataFrame,) -> Union[str, List[Dict[str, Any]]]:
|
||||
@@ -166,6 +166,7 @@ class QueryContext:
|
||||
if self.result_type == utils.ChartDataResultType.SAMPLES:
|
||||
row_limit = query_obj.row_limit or math.inf
|
||||
query_obj = copy.copy(query_obj)
|
||||
query_obj.is_timeseries = False
|
||||
query_obj.orderby = []
|
||||
query_obj.groupby = []
|
||||
query_obj.metrics = []
|
||||
|
||||
@@ -28,7 +28,7 @@ from superset import app, is_feature_enabled
|
||||
from superset.exceptions import QueryObjectValidationError
|
||||
from superset.typing import Metric
|
||||
from superset.utils import pandas_postprocessing
|
||||
from superset.utils.core import DTTM_ALIAS, json_int_dttm_ser
|
||||
from superset.utils.core import DTTM_ALIAS, get_metric_names, json_int_dttm_ser
|
||||
from superset.utils.date_parser import get_since_until, parse_human_timedelta
|
||||
from superset.views.utils import get_time_range_endpoints
|
||||
|
||||
@@ -212,6 +212,10 @@ class QueryObject:
|
||||
)
|
||||
self.extras[field.new_name] = value
|
||||
|
||||
@property
|
||||
def metric_names(self) -> List[str]:
|
||||
return get_metric_names(self.metrics)
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
query_object_dict = {
|
||||
"granularity": self.granularity,
|
||||
|
||||
@@ -993,6 +993,7 @@ class SqlaTable( # pylint: disable=too-many-public-methods,too-many-instance-at
|
||||
|
||||
time_range_endpoints = extras.get("time_range_endpoints")
|
||||
groupby_exprs_with_timestamp = OrderedDict(groupby_exprs_sans_timestamp.items())
|
||||
|
||||
if granularity:
|
||||
dttm_col = columns_by_name[granularity]
|
||||
time_grain = extras.get("time_grain_sqla")
|
||||
@@ -1032,7 +1033,7 @@ class SqlaTable( # pylint: disable=too-many-public-methods,too-many-instance-at
|
||||
|
||||
tbl = self.get_from_clause(template_processor)
|
||||
|
||||
if (is_sip_38 and metrics) or (not is_sip_38 and not columns):
|
||||
if groupby_exprs_with_timestamp:
|
||||
qry = qry.group_by(*groupby_exprs_with_timestamp.values())
|
||||
|
||||
where_clause_and = []
|
||||
|
||||
Reference in New Issue
Block a user