You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2023/08/11 16:08:17 UTC

[superset] branch fix_upload_gsheets created (now b91326a401)

This is an automated email from the ASF dual-hosted git repository.

beto pushed a change to branch fix_upload_gsheets
in repository https://gitbox.apache.org/repos/asf/superset.git


      at b91326a401 fix(gsheets): add column names on file upload

This branch includes the following new commits:

     new b91326a401 fix(gsheets): add column names on file upload

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[superset] 01/01: fix(gsheets): add column names on file upload

Posted by be...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch fix_upload_gsheets
in repository https://gitbox.apache.org/repos/asf/superset.git

commit b91326a40127d3f2f2d2e76553afdacb7259a9b3
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Fri Aug 11 09:07:54 2023 -0700

    fix(gsheets): add column names on file upload
---
 superset/db_engine_specs/gsheets.py              | 4 +++-
 tests/unit_tests/db_engine_specs/test_gsheets.py | 6 +++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/superset/db_engine_specs/gsheets.py b/superset/db_engine_specs/gsheets.py
index a9ec921188..c320df78dc 100644
--- a/superset/db_engine_specs/gsheets.py
+++ b/superset/db_engine_specs/gsheets.py
@@ -410,10 +410,12 @@ class GSheetsEngineSpec(ShillelaghEngineSpec):
             spreadsheet_url = payload["spreadsheetUrl"]
 
         # insert data
+        data = df.fillna("").values.tolist()
+        data.insert(0, df.columns.values.tolist())
         body = {
             "range": range_,
             "majorDimension": "ROWS",
-            "values": df.fillna("").values.tolist(),
+            "values": data,
         }
         url = (
             "https://sheets.googleapis.com/v4/spreadsheets/"
diff --git a/tests/unit_tests/db_engine_specs/test_gsheets.py b/tests/unit_tests/db_engine_specs/test_gsheets.py
index 7d7348c1a3..c425a1bfe3 100644
--- a/tests/unit_tests/db_engine_specs/test_gsheets.py
+++ b/tests/unit_tests/db_engine_specs/test_gsheets.py
@@ -333,7 +333,7 @@ def test_upload_new(mocker: MockFixture) -> None:
     database = mocker.MagicMock()
     database.get_extra.return_value = {}
 
-    df = pd.DataFrame([1, "foo", 3.0])
+    df = pd.DataFrame({"col": [1, "foo", 3.0]})
     table = Table("sample_data")
 
     GSheetsEngineSpec.df_to_sql(database, table, df, {})
@@ -367,7 +367,7 @@ def test_upload_existing(mocker: MockFixture) -> None:
         "engine_params": {"catalog": {"sample_data": "https://docs.example.org"}}
     }
 
-    df = pd.DataFrame([1, "foo", 3.0])
+    df = pd.DataFrame({"col": [1, "foo", 3.0]})
     table = Table("sample_data")
 
     with pytest.raises(SupersetException) as excinfo:
@@ -392,7 +392,7 @@ def test_upload_existing(mocker: MockFixture) -> None:
                 json={
                     "range": "sheet0",
                     "majorDimension": "ROWS",
-                    "values": [[1], ["foo"], [3.0]],
+                    "values": [["col"], [1], ["foo"], [3.0]],
                 },
                 params={"valueInputOption": "USER_ENTERED"},
             ),