From 490c707eb67c0497d1d70d2204a6919218d1f526 Mon Sep 17 00:00:00 2001 From: fabianmenges Date: Tue, 12 Sep 2017 12:36:28 -0400 Subject: [PATCH] Handling pandas ExtensionDtypes (#2937) --- superset/dataframe.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/superset/dataframe.py b/superset/dataframe.py index f3b9f3e1be41c..66034bb9e2c79 100644 --- a/superset/dataframe.py +++ b/superset/dataframe.py @@ -14,6 +14,8 @@ from past.builtins import basestring import pandas as pd +from pandas.core.dtypes.dtypes import ExtensionDtype + import numpy as np @@ -52,6 +54,8 @@ def data(self): @classmethod def db_type(cls, dtype): """Given a numpy dtype, Returns a generic database type""" + if isinstance(dtype, ExtensionDtype): + return cls.type_map.get(dtype.kind) return cls.type_map.get(dtype.char) @classmethod @@ -87,8 +91,10 @@ def agg_func(cls, dtype, column_name): # consider checking for key substring too. if cls.is_id(column_name): return 'count_distinct' - if np.issubdtype(dtype, np.number): + if (issubclass(dtype.type, np.generic) and + np.issubdtype(dtype, np.number)): return 'sum' + return None @property def columns(self):