How to use the autovizwidget.autovizwidget.widget.invalidencodingerror.InvalidEncodingError function in autovizwidget

To help you get started, we’ve selected a few autovizwidget 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 jupyter-incubator / sparkmagic / autovizwidget / autovizwidget / plotlygraphs / graphbase.py View on Github external
def render(self, df, encoding, output):
        if encoding.x is None or encoding.y is None:
            with output:
                print("\n\n\nPlease select an X and Y axis.")
                return

        try:
            data = self._get_data(df, encoding)
        except InvalidEncodingError as err:
            with output:
                print("\n\n\n{}".format(err))
                return

        type_x_axis = self._get_type_axis(encoding.logarithmic_x_axis)
        type_y_axis = self._get_type_axis(encoding.logarithmic_y_axis)

        layout = Layout(xaxis=dict(type=type_x_axis, rangemode="tozero", title=encoding.x),
                        yaxis=dict(type=type_y_axis, rangemode="tozero", title=encoding.y))

        with output:
            try:
                fig = Figure(data=Data(data), layout=layout)
                iplot(fig, show_link=False)
            except TypeError:
                print("\n\n\nPlease select another set of X and Y axis, because the type of the current axis do\n"
github jupyter-incubator / sparkmagic / autovizwidget / autovizwidget / plotlygraphs / graphbase.py View on Github external
def _get_x_y_values_aggregated(df, x_column, y_column, y_aggregation):
        if y_aggregation == Encoding.y_agg_none:
            raise ValueError("No Y aggregation function specified.")

        # Pandas has some confusing behavior when it comes to aggregating
        # over empty dataframes. We're just going to explicitly block against that here.
        if len(df) == 0:
            raise InvalidEncodingError("Cannot display graph for an empty data set.")

        try:
            df_grouped = df.groupby(x_column)
        except TypeError:
            raise InvalidEncodingError("Cannot group by X column '{}' because of its type: '{}'."
                                       .format(df[x_column].dtype))
        else:
            try:
                if y_aggregation == Encoding.y_agg_avg:
                    df_transformed = df_grouped.mean()
                elif y_aggregation == Encoding.y_agg_min:
                    df_transformed = df_grouped.min()
                elif y_aggregation == Encoding.y_agg_max:
                    df_transformed = df_grouped.max()
                elif y_aggregation == Encoding.y_agg_sum:
                    df_transformed = df_grouped.sum()
                elif y_aggregation == Encoding.y_agg_count:
                    df_transformed = df_grouped.count()
                else:
                    raise ValueError("Y aggregation '{}' not supported.".format(y_aggregation))
            except (DataError, ValueError) as err:
github jupyter-incubator / sparkmagic / autovizwidget / autovizwidget / plotlygraphs / graphbase.py View on Github external
df_transformed = df_grouped.mean()
                elif y_aggregation == Encoding.y_agg_min:
                    df_transformed = df_grouped.min()
                elif y_aggregation == Encoding.y_agg_max:
                    df_transformed = df_grouped.max()
                elif y_aggregation == Encoding.y_agg_sum:
                    df_transformed = df_grouped.sum()
                elif y_aggregation == Encoding.y_agg_count:
                    df_transformed = df_grouped.count()
                else:
                    raise ValueError("Y aggregation '{}' not supported.".format(y_aggregation))
            except (DataError, ValueError) as err:
                raise InvalidEncodingError("Cannot aggregate column '{}' with aggregation function '{}' because:\n\t'{}'."
                                           .format(y_column, y_aggregation, err))
            except TypeError:
                raise InvalidEncodingError("Cannot aggregate column '{}' with aggregation function '{}' because the type\n"
                                           "cannot be aggregated over."
                                           .format(y_column, y_aggregation))
            else:
                df_transformed = df_transformed.reset_index()

                if y_column not in df_transformed.columns:
                    raise InvalidEncodingError("Y column '{}' is not valid with aggregation function '{}'. Please select "
                                               "a different\naggregation function.".format(y_column, y_aggregation))

                x_values = df_transformed[x_column].tolist()
                y_values = df_transformed[y_column].tolist()

                return x_values, y_values
github jupyter-incubator / sparkmagic / autovizwidget / autovizwidget / plotlygraphs / graphbase.py View on Github external
def _get_x_y_values_aggregated(df, x_column, y_column, y_aggregation):
        if y_aggregation == Encoding.y_agg_none:
            raise ValueError("No Y aggregation function specified.")

        # Pandas has some confusing behavior when it comes to aggregating
        # over empty dataframes. We're just going to explicitly block against that here.
        if len(df) == 0:
            raise InvalidEncodingError("Cannot display graph for an empty data set.")

        try:
            df_grouped = df.groupby(x_column)
        except TypeError:
            raise InvalidEncodingError("Cannot group by X column '{}' because of its type: '{}'."
                                       .format(df[x_column].dtype))
        else:
            try:
                if y_aggregation == Encoding.y_agg_avg:
                    df_transformed = df_grouped.mean()
                elif y_aggregation == Encoding.y_agg_min:
                    df_transformed = df_grouped.min()
                elif y_aggregation == Encoding.y_agg_max:
                    df_transformed = df_grouped.max()
                elif y_aggregation == Encoding.y_agg_sum:
                    df_transformed = df_grouped.sum()

autovizwidget

AutoVizWidget: An Auto-Visualization library for pandas dataframes

BSD-3-Clause
Latest version published 28 days ago

Package Health Score

79 / 100
Full package analysis