in python-package/lets_plot/plot/series_meta.py [0:0]
def _infer_type_dict(var_name: str, var_content) -> str:
if isinstance(var_content, Iterable):
if not any(True for _ in var_content): # empty
return TYPE_UNKNOWN
else:
return TYPE_UNKNOWN
type_set = set(type(val) for val in var_content)
if type(None) in type_set:
type_set.remove(type(None))
if len(type_set) == 0:
return TYPE_UNKNOWN
if len(type_set) > 1:
if all(issubclass(type_obj, int) or issubclass(type_obj, float) for type_obj in type_set):
return TYPE_FLOATING
else:
return 'unknown(mixed types)'
lp_dtype = TYPE_UNKNOWN
type_obj = list(type_set)[0]
if type_obj == bool:
lp_dtype = TYPE_BOOLEAN
elif issubclass(type_obj, int):
lp_dtype = TYPE_INTEGER
elif issubclass(type_obj, float):
lp_dtype = TYPE_FLOATING
elif issubclass(type_obj, str):
lp_dtype = TYPE_STRING
elif issubclass(type_obj, datetime):
lp_dtype = TYPE_DATE_TIME
elif issubclass(type_obj, date) and not issubclass(type_obj, datetime):
lp_dtype = TYPE_DATE
elif issubclass(type_obj, time):
lp_dtype = TYPE_TIME
elif numpy and issubclass(type_obj, numpy.datetime64):
lp_dtype = TYPE_DATE_TIME
elif numpy and issubclass(type_obj, numpy.timedelta64):
# ToDo: time delta?
# lp_dtype = TYPE_DATE_TIME
lp_dtype = 'unknown(python:' + str(type_obj) + ')'
elif numpy and issubclass(type_obj, numpy.integer):
lp_dtype = TYPE_INTEGER
elif numpy and issubclass(type_obj, numpy.floating):
lp_dtype = TYPE_FLOATING
else:
lp_dtype = 'unknown(python:' + str(type_obj) + ')'
return lp_dtype