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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]