Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cel4 opened this issue Feb 3, 2015 · 2 comments · Fixed by #9417
Closed

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

cel4 opened this issue Feb 3, 2015 · 2 comments · Fixed by #9417
Labels
Error Reporting Incorrect or improved errors from pandas Visualization plotting
Milestone

Comments

@cel4
Copy link
Contributor

cel4 commented Feb 3, 2015

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.

@cel4 cel4 changed the title Improve error message in Dataframe.plot Improve error message in plotting.py's _plot Feb 3, 2015
@jorisvandenbossche
Copy link
Member

I think that is certainly a good proposal. Do a PR when you like!

@jorisvandenbossche jorisvandenbossche added the Error Reporting Incorrect or improved errors from pandas label Feb 3, 2015
@jorisvandenbossche jorisvandenbossche added this to the 0.16.0 milestone Feb 3, 2015
@cel4
Copy link
Contributor Author

cel4 commented Feb 4, 2015

PR: #9417

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas Visualization plotting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants