Skip to content

Commit

Permalink
fix(viz): missing groupby and broken adhoc metrics for boxplot (#12556)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmud committed Jan 16, 2021
1 parent 438be9a commit deebd6f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion superset/common/query_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def get_query_result(self, query_object: QueryObject) -> Dict[str, Any]:
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]]]:
Expand All @@ -166,6 +166,7 @@ def get_single_payload(
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 = []
Expand Down
6 changes: 5 additions & 1 deletion superset/common/query_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
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

Expand Down Expand Up @@ -212,6 +212,10 @@ def __init__(
)
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,
Expand Down
3 changes: 2 additions & 1 deletion superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma

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")
Expand Down Expand Up @@ -1032,7 +1033,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma

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 = []
Expand Down

0 comments on commit deebd6f

Please sign in to comment.