Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def thrift_cast(data, mapd_type, scale=0):
"""Cast data type to the expected thrift types"""
if mapd_type == 'TIMESTAMP':
return datetime_to_seconds(data)
elif mapd_type == 'TIME':
return pd.Series(time_to_seconds(x) for x in data)
elif mapd_type == 'DATE':
data = date_to_seconds(data)
data = data.fillna(mapd_to_na[mapd_type])
return data.astype(int)
elif mapd_type == 'BOOL':
# fillna before converting to int, since int cols
# in Pandas do not support None or NaN
data = data.fillna(mapd_to_na[mapd_type])
return data.astype(int)
elif mapd_type == 'DECIMAL':
# Multiply by 10^scale
data = data * 10**scale
# fillna and convert to int
data = data.fillna(mapd_to_na[mapd_type])