Skip to content

Commit

Permalink
Handling pandas ExtensionDtypes (#2937)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianmenges authored and mistercrunch committed Sep 12, 2017
1 parent 7c1b56f commit 490c707
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion superset/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from past.builtins import basestring

import pandas as pd
from pandas.core.dtypes.dtypes import ExtensionDtype

import numpy as np


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 490c707

Please sign in to comment.