superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From johnbod...@apache.org
Subject [incubator-superset] branch master updated: [travis] Adding Black tox environment (#7809)
Date Tue, 02 Jul 2019 01:05:23 GMT
This is an automated email from the ASF dual-hosted git repository.

johnbodley pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new ffa7c61  [travis] Adding Black tox environment (#7809)
ffa7c61 is described below

commit ffa7c617adea44902b432d0eac20b34161fbe380
Author: John Bodley <4567245+john-bodley@users.noreply.github.com>
AuthorDate: Mon Jul 1 18:05:15 2019 -0700

    [travis] Adding Black tox environment (#7809)
---
 .travis.yml                        |  3 +++
 superset/db_engine_specs/presto.py |  2 +-
 superset/views/core.py             |  2 +-
 superset/viz.py                    | 28 ++++++++++++++++------------
 tests/db_engine_specs_test.py      | 22 ++++++++++++----------
 5 files changed, 33 insertions(+), 24 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 9d4c523..d98ba97 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -53,6 +53,9 @@ jobs:
         - nvm install 10.14.2
     - language: python
       python: 3.6
+      env: TOXENV=black
+    - language: python
+      python: 3.6
       env: TOXENV=flake8
     - language: python
       python: 3.6
diff --git a/superset/db_engine_specs/presto.py b/superset/db_engine_specs/presto.py
index 6d6678b..ef2e2b7 100644
--- a/superset/db_engine_specs/presto.py
+++ b/superset/db_engine_specs/presto.py
@@ -920,7 +920,7 @@ class PrestoEngineSpec(BaseEngineSpec):
         if values is None:
             return False
 
-        column_names = {column.get('name') for column in columns or []}
+        column_names = {column.get("name") for column in columns or []}
         for col_name, value in zip(col_names, values):
             if col_name in column_names:
                 qry = qry.where(Column(col_name) == value)
diff --git a/superset/views/core.py b/superset/views/core.py
index bdbdf2d..6d18176 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -971,7 +971,7 @@ class KV(BaseSupersetView):
             kv = db.session.query(models.KeyValue).filter_by(id=key_id).one()
         except Exception as e:
             return json_error_response(e)
-        return Response(kv.value, status=200, content_type='text/plain')
+        return Response(kv.value, status=200, content_type="text/plain")
 
 
 appbuilder.add_view_no_menu(KV)
diff --git a/superset/viz.py b/superset/viz.py
index 7404a7f..b8d7770 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -654,10 +654,10 @@ class PivotTableViz(BaseViz):
 
     def query_obj(self):
         d = super().query_obj()
-        groupby = self.form_data.get('groupby')
-        columns = self.form_data.get('columns')
-        metrics = self.form_data.get('metrics')
-        transpose = self.form_data.get('transpose_pivot')
+        groupby = self.form_data.get("groupby")
+        columns = self.form_data.get("columns")
+        metrics = self.form_data.get("metrics")
+        transpose = self.form_data.get("transpose_pivot")
         if not columns:
             columns = []
         if not groupby:
@@ -665,10 +665,14 @@ class PivotTableViz(BaseViz):
         if not groupby:
             raise Exception(_("Please choose at least one 'Group by' field "))
         if transpose and not columns:
-            raise Exception(_((
-                "Please choose at least one 'Columns' field when "
-                "select 'Transpose Pivot' option"
-            )))
+            raise Exception(
+                _(
+                    (
+                        "Please choose at least one 'Columns' field when "
+                        "select 'Transpose Pivot' option"
+                    )
+                )
+            )
         if not metrics:
             raise Exception(_("Please choose at least one metric"))
         if any(v in groupby for v in columns) or any(v in columns for v in groupby):
@@ -685,14 +689,14 @@ class PivotTableViz(BaseViz):
         if aggfunc == "sum":
             aggfunc = lambda x: x.sum(min_count=1)  # noqa: E731
 
-        groupby = self.form_data.get('groupby')
-        columns = self.form_data.get('columns')
-        if self.form_data.get('transpose_pivot'):
+        groupby = self.form_data.get("groupby")
+        columns = self.form_data.get("columns")
+        if self.form_data.get("transpose_pivot"):
             groupby, columns = columns, groupby
         df = df.pivot_table(
             index=groupby,
             columns=columns,
-            values=[utils.get_metric_name(m) for m in self.form_data.get('metrics')],
+            values=[utils.get_metric_name(m) for m in self.form_data.get("metrics")],
             aggfunc=aggfunc,
             margins=self.form_data.get("pivot_margins"),
             dropna=False,
diff --git a/tests/db_engine_specs_test.py b/tests/db_engine_specs_test.py
index 4ec0f01..7ab389e 100644
--- a/tests/db_engine_specs_test.py
+++ b/tests/db_engine_specs_test.py
@@ -764,21 +764,23 @@ class DbEngineSpecsTestCase(SupersetTestCase):
 
     def test_presto_extra_table_metadata(self):
         db = mock.Mock()
-        db.get_indexes = mock.Mock(return_value=[{'column_names': ['ds', 'hour']}])
-        df = pd.DataFrame({'ds': ['01-01-19'], 'hour': [1]})
+        db.get_indexes = mock.Mock(return_value=[{"column_names": ["ds", "hour"]}])
+        df = pd.DataFrame({"ds": ["01-01-19"], "hour": [1]})
         db.get_df = mock.Mock(return_value=df)
-        result = PrestoEngineSpec.extra_table_metadata(db, 'test_table', 'test_schema')
-        self.assertEqual({'ds': '01-01-19', 'hour': 1}, result['partitions']['latest'])
+        result = PrestoEngineSpec.extra_table_metadata(db, "test_table", "test_schema")
+        self.assertEqual({"ds": "01-01-19", "hour": 1}, result["partitions"]["latest"])
 
     def test_presto_where_latest_partition(self):
         db = mock.Mock()
-        db.get_indexes = mock.Mock(return_value=[{'column_names': ['ds', 'hour']}])
-        df = pd.DataFrame({'ds': ['01-01-19'], 'hour': [1]})
+        db.get_indexes = mock.Mock(return_value=[{"column_names": ["ds", "hour"]}])
+        df = pd.DataFrame({"ds": ["01-01-19"], "hour": [1]})
         db.get_df = mock.Mock(return_value=df)
-        columns = [{'name': 'ds'}, {'name': 'hour'}]
-        result = PrestoEngineSpec.where_latest_partition('test_table', 'test_schema', db,
select(), columns)
-        query_result = str(result.compile(compile_kwargs={'literal_binds': True}))
-        self.assertEqual('SELECT  \nWHERE ds = \'01-01-19\' AND hour = 1', query_result)
+        columns = [{"name": "ds"}, {"name": "hour"}]
+        result = PrestoEngineSpec.where_latest_partition(
+            "test_table", "test_schema", db, select(), columns
+        )
+        query_result = str(result.compile(compile_kwargs={"literal_binds": True}))
+        self.assertEqual("SELECT  \nWHERE ds = '01-01-19' AND hour = 1", query_result)
 
     def test_hive_get_view_names_return_empty_list(self):
         self.assertEquals([], HiveEngineSpec.get_view_names(mock.ANY, mock.ANY))


Mime
View raw message