How to use the dtale.utils.make_list function in dtale

To help you get started, we’ve selected a few dtale examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github man-group / dtale / tests / dtale / test_utils.py View on Github external
def test_make_list():
    assert utils.make_list(None) == []
    assert utils.make_list([1]) == [1]
    assert utils.make_list(1) == [1]
github man-group / dtale / tests / dtale / test_utils.py View on Github external
def test_make_list():
    assert utils.make_list(None) == []
    assert utils.make_list([1]) == [1]
    assert utils.make_list(1) == [1]
github man-group / dtale / dtale / views.py View on Github external
:param params: properties & values passed as query parameters to the route
        :type params: dict, optional
        :param width: width of the ipython cell
        :type width: str or int, optional
        :param height: height of the ipython cell
        :type height: str or int, optional
        :return: :class:`ipython:IPython.display.IFrame`
        """
        try:
            from IPython.display import IFrame
        except ImportError:
            logger.info('in order to use this function, please install IPython')
            return None
        iframe_url = '{}{}{}'.format(self._url, route, self._data_id)
        if params is not None:
            formatted_params = ['{}={}'.format(k, ','.join(make_list(params[k]))) for k in sorted(params)]
            iframe_url = '{}?{}'.format(iframe_url, '&'.join(formatted_params))
        return IFrame(iframe_url, width=width, height=height)
github man-group / dtale / dtale / views.py View on Github external
if len(data[group_col].drop_duplicates()) > max_groups:
            msg = (
                'Group ({}) contains more than {} unique values, please add additional filter'
                ' or else chart will be unreadable'
            ).format(', '.join(group_col), max_groups)
            raise Exception(msg)
        f = grid_formatter(
            grid_columns(data[[x_col, y_col]]), overrides={'D': lambda f, i, c: f.add_timestamp(i, c)}, nan_display=None
        )
        y_fmt = next((fmt for _, name, fmt in f.fmts if name == y_col), None)
        ret_data = dict(data={}, min=y_fmt(data[y_col].min(), None), max=y_fmt(data[y_col].max(), None))
        dtypes = get_dtypes(data)
        group_fmts = {c: find_dtype_formatter(dtypes[c]) for c in group_col}
        for group_val, grp in data.groupby(group_col):
            group_val = '/'.join([
                group_fmts[gc](gv) for gv, gc in zip(make_list(group_val), group_col)
            ])
            ret_data['data'][group_val] = f.format_lists(grp)
        return ret_data
    data = data[[x, y]].sort_values(x)
    data.columns = [x_col, y_col]
    if agg is not None:
        data = data.groupby(x_col)
        data = getattr(data, agg)().reset_index()

    if any(data[x_col].duplicated()):
        raise Exception('{} contains duplicates, please specify group or additional filtering'.format(x))
    f = grid_formatter(
        grid_columns(data), overrides={'D': lambda f, i, c: f.add_timestamp(i, c)}, nan_display=None
    )
    y_fmt = next((fmt for _, name, fmt in f.fmts if name == y_col), None)
    ret_data = dict(
github man-group / dtale / dtale / views.py View on Github external
def format_data(data):
    """
    Helper function to build globally managed state pertaining to a D-Tale instances data.  Some updates being made:
     - convert all column names to strings
     - drop any indexes back into the dataframe so what we are left is a natural index [0,1,2,...,n]
     - convert inputs that are indexes into dataframes

    :param data: dataframe to build data type information for
    :type data: :class:`pandas:pandas.DataFrame`
    :return: formatted :class:`pandas:pandas.DataFrame` and a list of strings constituting what columns were originally
             in the index
    """
    if isinstance(data, (pd.DatetimeIndex, pd.MultiIndex)):
        data = data.to_frame(index=False)

    index = [str(i) for i in make_list(data.index.name or data.index.names) if i is not None]
    data = data.reset_index().drop('index', axis=1, errors='ignore')
    data.columns = [str(c) for c in data.columns]
    return data, index
github man-group / dtale / dtale / views.py View on Github external
:type y: str
        :param group: comma-separated string of columns to group chart data by
        :type group: str, optional
        :param aggregation: points to a specific function that can be applied to
                            :func: pandas.core.groupby.DataFrameGroupBy.  Possible values are: count, first, last mean,
                            median, min, max, std, var, mad, prod, sum
        :type aggregation: str, optional
        :param width: width of the ipython cell
        :type width: str or int, optional
        :param height: height of the ipython cell
        :type height: str or int, optional
        :return: :class:`ipython:IPython.display.IFrame`
        """
        params = dict(x=x, y=y)
        if group:
            params['group'] = ','.join(make_list(group))
        if aggregation:
            params['aggregation'] = aggregation
        self.notebook('/dtale/popup/charts/', params=params, width=width, height=height)