mirror of
https://github.com/apache/superset.git
synced 2026-04-21 00:54:44 +00:00
[viz flow] detect TIMESTAMP, transition to line chart (#5634)
* [viz flow] detect TIMESTAMP, transition to line chart * Refactor is_date
This commit is contained in:
committed by
GitHub
parent
6959b70c1c
commit
6e8c7f7b20
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user