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: [bugfix] TIMESTAMP not detected as date (#5629)
Date Tue, 14 Aug 2018 20:01:31 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 4c2be71  [bugfix] TIMESTAMP not detected as date (#5629)
4c2be71 is described below

commit 4c2be71e838dfde511d486104160d37642f4b3d8
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Tue Aug 14 13:01:28 2018 -0700

    [bugfix] TIMESTAMP not detected as date (#5629)
    
    * [bugfix] TIMESTAMP not detected as date
    
    * minor tweak
---
 superset/dataframe.py   | 8 ++++++--
 tests/dataframe_test.py | 9 +++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/superset/dataframe.py b/superset/dataframe.py
index 2fecad9..447aa68 100644
--- a/superset/dataframe.py
+++ b/superset/dataframe.py
@@ -134,8 +134,12 @@ class SupersetDataFrame(object):
 
     @classmethod
     def is_date(cls, dtype):
-        if dtype.name:
-            return dtype.name.startswith('datetime')
+        if dtype and dtype.name:
+            return any([
+                dtype.name.lower().startswith(s)
+                for s in ['date', 'time']
+            ])
+        return False
 
     @classmethod
     def is_dimension(cls, dtype, column_name):
diff --git a/tests/dataframe_test.py b/tests/dataframe_test.py
index a773f08..c5ea504 100644
--- a/tests/dataframe_test.py
+++ b/tests/dataframe_test.py
@@ -4,6 +4,8 @@ from __future__ import division
 from __future__ import print_function
 from __future__ import unicode_literals
 
+import numpy as np
+
 from superset.dataframe import dedup, SupersetDataFrame
 from superset.db_engine_specs import BaseEngineSpec
 from .base_tests import SupersetTestCase
@@ -118,6 +120,13 @@ class SupersetDataFrameTestCase(SupersetTestCase):
             ],
         )
 
+    def test_is_date(self):
+        f = SupersetDataFrame.is_date
+        self.assertEquals(f(np.dtype('M')), True)
+
+        self.assertEquals(f(None), False)
+        self.assertEquals(f(np.dtype(np.int32)), False)
+
     def test_dedup_with_data(self):
         data = [
             ('a', 1),


Mime
View raw message