Skip to content

Improve error message in plotting.py's _plot #9400

Closed
@cel4

Description

@cel4

This a minor enhancement proposal. At the moment I cannot submit a pull request. I will probably have time to create one during the next week.

This is a snippet from tools/plotting.py: https://github.com/pydata/pandas/blob/master/pandas/tools/plotting.py#L2269-2283

def _plot(data, x=None, y=None, subplots=False,
          ax=None, kind='line', **kwds):
    kind = _get_standard_kind(kind.lower().strip())
    if kind in _all_kinds:
        klass = _plot_klass[kind]
    else:
        raise ValueError('Invalid chart type given %s' % kind)

    from pandas import DataFrame
    if kind in _dataframe_kinds:
        if isinstance(data, DataFrame):
            plot_obj = klass(data, x=x, y=y, subplots=subplots, ax=ax,
                             kind=kind, **kwds)
        else:
            raise ValueError('Invalid chart type given %s' % kind)

Which results in following error message:

C:\Anaconda3\lib\site-packages\pandas\tools\plotting.py in plot_series(series, label, kind, use_index, rot, xticks, yticks, xlim, ylim, ax, style, grid, legend, logx, logy, secondary_y, **kwds)
   2231         klass = _plot_klass[kind]
   2232     else:
-> 2233         raise ValueError('Invalid chart type given %s' % kind)
   2234 
   2235     """

ValueError: Invalid chart type given hist

I would suggest using the format string "Invalid chart type given: '%s'" instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions