dtale.charts package

Submodules

dtale.charts.utils module

dtale.charts.utils.build_agg_data(df, x, y, inputs, agg, z=None)[source]

Builds aggregated data when an aggregation (sum, mean, max, min…) is selected from the front-end.

Parameters:
  • df (pandas.DataFrame) – dataframe that contains data for chart
  • x (str) – column to use for the X-Axis
  • y (list of str) – columns to use for the Y-Axes
  • inputs (dict) – additional chart configurations (chart_type, group, rolling_win, rolling_comp…)
  • agg (str) – 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
  • z (str, optional) – column to use for the Z-Axis
Returns:

dataframe of aggregated data

Return type:

pandas.DataFrame

dtale.charts.utils.build_chart(raw_data, x, y, group_col=None, agg=None, allow_duplicates=False, **kwargs)[source]

Helper function to return data for ‘chart-data’ & ‘correlations-ts’ endpoints. Will return a dictionary of dictionaries (one for each series) which contain the data for the x & y axes of the chart as well as the minimum & maximum of all the series for the y-axis. If there is only one series (no group_col specified) the only key in the dictionary of series data will be ‘all’ otherwise the keys will be the values of the groups.

Parameters:
  • raw_data (pandas.DataFrame) – dataframe to be used for chart
  • x (str) – column to be used as x-axis of chart
  • y (list of strings) – column to be used as y-axis of chart
  • group (str, optional) – comma-separated string of columns to group chart data by
  • agg (str, optional) – 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
  • allow_duplicates (bool, optional) – flag to allow duplicates to be ignored (usually for scatter plots)
Returns:

dict

dtale.charts.utils.build_formatters(df)[source]

Helper around dtale.utils.grid_formatters() that will build a formatter for the data being fed into a chart as well as a formatter for the min/max values for each column used in the chart data.

Parameters:df (pandas.DataFrame) – dataframe which contains column names and data types for formatters
Returns:json formatters for chart data and min/max values for each column used in the chart
Return type:(dtale.utils.JSONFormatter, dtale.utils.JSONFormatter)
dtale.charts.utils.check_all_nan(df, cols=None)[source]

Checker function to test whether all data within a column of a dataframe is numpy.nan

Parameters:
  • df (pandas.DataFrame) – dataframe whose data needs to be checked
  • cols (list of str) – columns to test
Raises:

Exception – if all data within a column is numpy.nan

dtale.charts.utils.check_exceptions(df, allow_duplicates, data_limit=15000, limit_msg='Dataset exceeds {} records, cannot render. Please apply filter...')[source]
Checker function to test the output of any chart aggregations to see if it is one of the following:
  • too large to be rendered by web client
  • contains duplicate data points which can’t be rendered (ex: multiple points for a single point on the x-axis of a bar chart within the same series)
Parameters:
  • df (pandas.DataFrame) – dataframe whose data needs to be checked
  • allow_duplicates (bool) – flag to allow duplicates to be ignored (usually for scatter plots)
  • data_limit (int, optional) – maximum rows allowed for chart rendering (default: 15,000)
  • limit_msg (str, optional) – error message template
Raises:

Exception – if any failure condition is met

dtale.charts.utils.date_freq_handler(df)[source]

This returns a column definition handler which returns a series based on the specs from the front-end. Column definitions can be a column name ‘Col1’ or a column name with a frequency ‘Col1|M’ for columns which are of type datetime.

Example:Col1 -> returns series for Col1 Col1|M -> returns series for Col1 in monthly format with name ‘Col1|M’
Parameters:df (pandas.DataFrame) – dataframe whose data needs to be checked
Returns:handler function
Return type:func
dtale.charts.utils.retrieve_chart_data(df, x, y, z, group=None)[source]

Retrieves data from a dataframe for x, y, z & group inputs complete with date frequency formatting (dtale.charts.utils.date_freq_handler()) if specified

Parameters:
  • df (pandas.DataFrame) – dataframe that contains data for chart
  • x (str) – column to use for the X-Axis
  • y (list of str) – columns to use for the Y-Axes
  • z (str) – column to use for the Z-Axis
  • group (list of str or str) – column(s) to use for grouping
Returns:

dataframe of data required for chart construction

Return type:

pandas.DataFrame

dtale.charts.utils.valid_chart(chart_type=None, x=None, y=None, z=None, **inputs)[source]

Helper function to determine based on inputs (chart_type, x, y, z…) whether a chart can be build or not. For example, charts must have an x & y value and for 3-dimensional charts they must have a Z-Axis as well.

Parameters:
  • chart_type (str, optional) – type of chart to build (line, bar, scatter, pie, heatmap, wordcloud, 3dscatter, surface)
  • x (str, optional) – column to use for the X-Axis
  • y (list of str, optional) – columns to use for the Y-Axes
  • z (str, optional) – column to use for the Z-Axis
  • inputs – keyword arguments containing
Returns:

True if executed from test, False otherwise

Return type:

bool

dtale.charts.utils.weekday_tick_handler(col_data, col)[source]

Output handler for datetime data which needs to be returned as weekdays. If the column definition ends with ‘|WD’ then the integer values in ‘data’ will be mapped to their standard weekday test (Mon, Tues, Wed, Thur, Fri, Sat, Sun)

Parameters:
  • col_data (list) – iterable of values within column
  • col (str) – column definition
Returns:

formatted column data

Return type:

list

Module contents