You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2021/08/26 03:37:11 UTC

[GitHub] [superset] villebro commented on a change in pull request #16450: fix(query): handle Infinity in query results

villebro commented on a change in pull request #16450:
URL: https://github.com/apache/superset/pull/16450#discussion_r696263257



##########
File path: superset/common/query_context.py
##########
@@ -276,11 +278,19 @@ def get_query_result(self, query_object: QueryObject) -> QueryResult:
     @staticmethod
     def df_metrics_to_num(df: pd.DataFrame, query_object: QueryObject) -> None:
         """Converting metrics to numeric when pandas.read_sql cannot"""
+        metric_names: List[str] = query_object.metric_names
         for col, dtype in df.dtypes.items():
-            if dtype.type == np.object_ and col in query_object.metric_names:
+            if dtype.type == np.object_ and col in metric_names:
                 # soft-convert a metric column to numeric
                 # will stay as strings if conversion fails
-                df[col] = df[col].infer_objects()
+                df[col] = pd.to_numeric(
+                    df[col]
+                    .replace(INFINITY_LITERALS, np.inf)
+                    .replace(NEGATIVE_INFINITY_LITERALS, -np.inf),

Review comment:
       This logic should probably be moved into the Druid `db_engine_spec` to avoid running this logic on unaffected db engines. Something like 
   
   ```python
   BaseEngineSpec.replace_literal_values(val: str) -> Any:
       return val
   ``` 
   
   which then is implemented in the Druid spec with those specific literals.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org