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 2022/07/19 03:35:36 UTC

[GitHub] [superset] john-bodley commented on a diff in pull request #20760: fix(csv): Do not coerce persisted data integer columns to float

john-bodley commented on code in PR #20760:
URL: https://github.com/apache/superset/pull/20760#discussion_r924024074


##########
superset/views/core.py:
##########
@@ -2502,8 +2502,7 @@ def csv(  # pylint: disable=no-self-use,too-many-locals
             obj = _deserialize_results_payload(
                 payload, query, cast(bool, results_backend_use_msgpack)
             )
-            columns = [c["name"] for c in obj["columns"]]
-            df = pd.DataFrame.from_records(obj["data"], columns=columns)
+            df = pd.DataFrame(data=obj["data"], dtype=object)

Review Comment:
   No need to specify column names as they're present in the data. Furthermore—per the Pandas documentation, 
   
   > Column labels to use for resulting frame when data does not have them, defaulting to RangeIndex(0, 1, 2, …, n). If data contains column labels, will perform column selection instead.
   
   the `columns` option doesn't rename existing columns if column labels are present, but performs column selection instead, i.e., 
   
   ```python
   >>> pd.DataFrame(data=[{"foo": 1}, {"foo": None}], dtype=object, columns=["foo"])
       foo
   0     1
   1  None
   
   >>> pd.DataFrame(data=[{"foo": 1}, {"foo": None}], dtype=object, columns=["bar"])
      bar
   0  NaN
   1  NaN
   ``` 



-- 
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