From cb7d25ca69414d7e9fae7412174ab98a18a7296d Mon Sep 17 00:00:00 2001 From: John Bodley <4567245+john-bodley@users.noreply.github.com> Date: Mon, 18 Jul 2022 20:12:43 -0700 Subject: [PATCH 1/6] Replace pd.DataFrame.from_records with pd.DataFrame --- superset/views/core.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/superset/views/core.py b/superset/views/core.py index 0598c72446832..8fdbc40dcd9d4 100755 --- a/superset/views/core.py +++ b/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) logger.info("Using pandas to convert to CSV") else: logger.info("Running a query to turn into CSV") From 2915836e5da44a82aa14c06c49dc39609f528be1 Mon Sep 17 00:00:00 2001 From: John Bodley <4567245+john-bodley@users.noreply.github.com> Date: Mon, 18 Jul 2022 20:15:39 -0700 Subject: [PATCH 2/6] Remove unused code --- superset/utils/csv.py | 1 - 1 file changed, 1 deletion(-) diff --git a/superset/utils/csv.py b/superset/utils/csv.py index 54f30362fede3..bfda82ac19ab5 100644 --- a/superset/utils/csv.py +++ b/superset/utils/csv.py @@ -65,7 +65,6 @@ def escape_value(value: str) -> str: def df_to_escaped_csv(df: pd.DataFrame, **kwargs: Any) -> Any: - escape_values = lambda v: escape_value(v) if isinstance(v, str) else v # Escape csv headers df = df.rename(columns=escape_values) From c6110c7d2e71afe9dc1b9e06e52fa3696aa7c3a0 Mon Sep 17 00:00:00 2001 From: John Bodley <4567245+john-bodley@users.noreply.github.com> Date: Mon, 18 Jul 2022 20:36:16 -0700 Subject: [PATCH 3/6] Update core.py --- superset/views/core.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/superset/views/core.py b/superset/views/core.py index 8fdbc40dcd9d4..7c007ba936192 100755 --- a/superset/views/core.py +++ b/superset/views/core.py @@ -2502,7 +2502,8 @@ def csv( # pylint: disable=no-self-use,too-many-locals obj = _deserialize_results_payload( payload, query, cast(bool, results_backend_use_msgpack) ) - df = pd.DataFrame(data=obj["data"], dtype=object) + columns = [c['name'] for c in obj['columns']] + df = pd.DataFrame(data=obj["data"], dtype=object, columns=columns) logger.info("Using pandas to convert to CSV") else: logger.info("Running a query to turn into CSV") From 2a4686e773972971dbe98634750904eb61ec3d6a Mon Sep 17 00:00:00 2001 From: John Bodley <4567245+john-bodley@users.noreply.github.com> Date: Mon, 18 Jul 2022 20:37:35 -0700 Subject: [PATCH 4/6] Update core.py --- superset/views/core.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/superset/views/core.py b/superset/views/core.py index 7c007ba936192..46583a1c7f862 100755 --- a/superset/views/core.py +++ b/superset/views/core.py @@ -2502,8 +2502,13 @@ 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(data=obj["data"], dtype=object, columns=columns) + + df = pd.DataFrame( + data=obj["data"], + dtype=object, + columns=[c["name"] for c in obj["columns"]], + ) + logger.info("Using pandas to convert to CSV") else: logger.info("Running a query to turn into CSV") From 9ca2df25c1a3021dddb7edc63348d35981c2cbeb Mon Sep 17 00:00:00 2001 From: John Bodley <4567245+john-bodley@users.noreply.github.com> Date: Mon, 18 Jul 2022 22:03:04 -0700 Subject: [PATCH 5/6] Update csv.py --- superset/utils/csv.py | 1 + 1 file changed, 1 insertion(+) diff --git a/superset/utils/csv.py b/superset/utils/csv.py index bfda82ac19ab5..54f30362fede3 100644 --- a/superset/utils/csv.py +++ b/superset/utils/csv.py @@ -65,6 +65,7 @@ def escape_value(value: str) -> str: def df_to_escaped_csv(df: pd.DataFrame, **kwargs: Any) -> Any: + escape_values = lambda v: escape_value(v) if isinstance(v, str) else v # Escape csv headers df = df.rename(columns=escape_values) From 4d2f439ddaf2a95fd213551ced056005ed6df5e1 Mon Sep 17 00:00:00 2001 From: John Bodley <4567245+john-bodley@users.noreply.github.com> Date: Mon, 18 Jul 2022 23:33:23 -0700 Subject: [PATCH 6/6] Update core.py --- superset/views/core.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/superset/views/core.py b/superset/views/core.py index 46583a1c7f862..c27dcfb4a6497 100755 --- a/superset/views/core.py +++ b/superset/views/core.py @@ -2504,11 +2504,11 @@ def csv( # pylint: disable=no-self-use,too-many-locals ) df = pd.DataFrame( - data=obj["data"], - dtype=object, + data=obj["data"], + dtype=object, columns=[c["name"] for c in obj["columns"]], ) - + logger.info("Using pandas to convert to CSV") else: logger.info("Running a query to turn into CSV")