Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(viz): missing groupby and broken adhoc metrics for boxplot #12556

Merged
merged 3 commits into from
Jan 16, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 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 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