in python-package/lets_plot/plot/geom_function_.py [0:0]
def _get_fun_data(mapping, data, fun, xlim, n):
aes_x_value = None
if mapping is not None and 'x' in mapping.as_dict():
aes_x_value = mapping.as_dict()['x']
if isinstance(aes_x_value, str) and data is not None:
xs = data[aes_x_value]
elif hasattr(aes_x_value, '__iter__'):
xs = aes_x_value
else:
xs = _get_default_xrange(xlim, n)
if fun is None:
ys = [None] * len(xs)
else:
ys = [fun(x) for x in xs]
if data is None:
return {_fun_x_name: xs, _fun_y_name: ys}
else:
if isinstance(data, dict):
return {**data, **{_fun_y_name: ys}}
elif pd is not None and isinstance(data, pd.DataFrame):
return data.assign(**{_fun_y_name: ys})
elif pl is not None and isinstance(data, pl.DataFrame):
return data.with_columns(**{_fun_y_name: pl.Series(values=ys)})
else:
raise Exception("Unsupported type of data: {0}".format(data))