superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [incubator-superset] branch master updated: [viz flow] detect TIMESTAMP, transition to line chart (#5634)
Date Wed, 22 Aug 2018 04:33:37 GMT
This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin 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 6e8c7f7  [viz flow] detect TIMESTAMP, transition to line chart (#5634)
6e8c7f7 is described below

commit 6e8c7f7b2044ba3c59baa7892c105aef098b3a59
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Tue Aug 21 21:33:34 2018 -0700

    [viz flow] detect TIMESTAMP, transition to line chart (#5634)
    
    * [viz flow] detect TIMESTAMP, transition to line chart
    
    * Refactor is_date
---
 superset/assets/src/explore/controls.jsx |  2 +-
 superset/assets/src/explore/visTypes.jsx |  3 ---
 superset/dataframe.py                    | 27 ++++++++++++++++-----------
 tests/dataframe_test.py                  | 10 +++++++---
 4 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/superset/assets/src/explore/controls.jsx b/superset/assets/src/explore/controls.jsx
index f2f12e0..0900d2c 100644
--- a/superset/assets/src/explore/controls.jsx
+++ b/superset/assets/src/explore/controls.jsx
@@ -898,7 +898,7 @@ export const controls = {
   time_grain_sqla: {
     type: 'SelectControl',
     label: t('Time Grain'),
-    default: control => control.choices && control.choices.length ? control.choices[0][0]
: null,
+    default: 'P1D',
     description: t('The time granularity for the visualization. This ' +
     'applies a date transformation to alter ' +
     'your time column and defines a new time granularity. ' +
diff --git a/superset/assets/src/explore/visTypes.jsx b/superset/assets/src/explore/visTypes.jsx
index 5df65df..69b1297 100644
--- a/superset/assets/src/explore/visTypes.jsx
+++ b/superset/assets/src/explore/visTypes.jsx
@@ -948,9 +948,6 @@ export const visTypes = {
       metrics: {
         validators: [],
       },
-      time_grain_sqla: {
-        default: null,
-      },
     },
   },
 
diff --git a/superset/dataframe.py b/superset/dataframe.py
index 447aa68..834f118 100644
--- a/superset/dataframe.py
+++ b/superset/dataframe.py
@@ -132,13 +132,18 @@ class SupersetDataFrame(object):
                 continue
         return 100 * success / total
 
-    @classmethod
-    def is_date(cls, dtype):
-        if dtype and dtype.name:
-            return any([
-                dtype.name.lower().startswith(s)
-                for s in ['date', 'time']
-            ])
+    @staticmethod
+    def is_date(np_dtype, db_type_str):
+
+        def looks_daty(s):
+            if isinstance(s, basestring):
+                return any([s.lower().startswith(ss) for ss in ('time', 'date')])
+            return False
+
+        if looks_daty(db_type_str):
+            return True
+        if np_dtype and np_dtype.name and looks_daty(np_dtype.name):
+            return True
         return False
 
     @classmethod
@@ -176,19 +181,19 @@ class SupersetDataFrame(object):
         if sample_size:
             sample = self.df.sample(sample_size)
         for col in self.df.dtypes.keys():
-            col_db_type = (
+            db_type_str = (
                 self._type_dict.get(col) or
                 self.db_type(self.df.dtypes[col])
             )
             column = {
                 'name': col,
                 'agg': self.agg_func(self.df.dtypes[col], col),
-                'type': col_db_type,
-                'is_date': self.is_date(self.df.dtypes[col]),
+                'type': db_type_str,
+                'is_date': self.is_date(self.df.dtypes[col], db_type_str),
                 'is_dim': self.is_dimension(self.df.dtypes[col], col),
             }
 
-            if column['type'] in ('OBJECT', None):
+            if not db_type_str or db_type_str.upper() == 'OBJECT':
                 v = sample[col].iloc[0] if not sample[col].empty else None
                 if isinstance(v, basestring):
                     column['type'] = 'STRING'
diff --git a/tests/dataframe_test.py b/tests/dataframe_test.py
index c5ea504..b52b950 100644
--- a/tests/dataframe_test.py
+++ b/tests/dataframe_test.py
@@ -122,10 +122,14 @@ class SupersetDataFrameTestCase(SupersetTestCase):
 
     def test_is_date(self):
         f = SupersetDataFrame.is_date
-        self.assertEquals(f(np.dtype('M')), True)
+        self.assertEquals(f(np.dtype('M'), ''), True)
+        self.assertEquals(f(np.dtype('f'), 'DATETIME'), True)
+        self.assertEquals(f(np.dtype('i'), 'TIMESTAMP'), True)
+        self.assertEquals(f(None, 'DATETIME'), True)
+        self.assertEquals(f(None, 'TIMESTAMP'), True)
 
-        self.assertEquals(f(None), False)
-        self.assertEquals(f(np.dtype(np.int32)), False)
+        self.assertEquals(f(None, ''), False)
+        self.assertEquals(f(np.dtype(np.int32), ''), False)
 
     def test_dedup_with_data(self):
         data = [


Mime
View raw message