Skip to content

Commit

Permalink
[bugfix] TIMESTAMP not detected as date (apache#5629)
Browse files Browse the repository at this point in the history
* [bugfix] TIMESTAMP not detected as date

* minor tweak
  • Loading branch information
mistercrunch authored Aug 14, 2018
1 parent 85a6da1 commit 4c2be71
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions superset/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@ def datetime_conversion_rate(cls, data_series):

@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):
Expand Down
9 changes: 9 additions & 0 deletions tests/dataframe_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
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
Expand Down Expand Up @@ -118,6 +120,13 @@ def test_get_columns_type_inference(self):
],
)

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),
Expand Down

0 comments on commit 4c2be71

Please sign in to comment.