API: Improper x/y arg given to df.plot
State: closed

- [x] closes #18671 
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry 

I'm not incredibly familiar with your codebase so I did my best to follow conventions. Not sure what to do with whatsnew for this case?

Description:

- Validation of x or y arg to `df.plot` to match specifications in documentation


Labels:
name: Bug
name: Visualization
description: plotting

Comments:
Thanks, this will be for 0.22 since it's an API change. Some people may have been ignoring the warning and relying on this.

Did you look into how difficult it'd be to properly support multiple columns for `y`? At the very least, we would need to make sure that `label` was a a list-like of the same length as `y`. Not sure what else.
> Did you look into how difficult it'd be to properly support multiple columns for y?

I did think about this - the usecase that isn't already covered wasn't clear to me, especially given the complexity it would add to the method/API. The `plot` method already has `subplots` and `secondary_y` for example. What do you think?
I don't have a strong opinion. I think the equivalent output would be `df.set_index("x")[y].plot()`, which isn't so bad. It's probably best to just assert that `y` is a a single column, so your changes here look good.

The release not can go in `doc/source/whatsnew/v0.22.0.txt` under plotting.
> The release not can go in doc/source/whatsnew/v0.22.0.txt under plotting.

Thanks, I see api changes section will update that
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18695?src=pr&el=h1) Report
> Merging [#18695](https://codecov.io/gh/pandas-dev/pandas/pull/18695?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/288bf6e5e3287a8c66a7ed41050db0ebf56d7ea6?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/18695/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/18695?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #18695      +/-   ##
==========================================
- Coverage    91.6%   91.59%   -0.02%     
==========================================
  Files         153      153              
  Lines       51272    51276       +4     
==========================================
- Hits        46967    46964       -3     
- Misses       4305     4312       +7
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.45% <100%> (ø)` | :arrow_up: |
| #single | `40.67% <0%> (-0.12%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/18695?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/plotting/\_core.py](https://codecov.io/gh/pandas-dev/pandas/pull/18695/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb3JlLnB5) | `82.42% <100%> (+0.05%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/18695/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/18695/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.81% <0%> (-0.1%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/18695/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `82.01% <0%> (+0.19%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18695?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18695?src=pr&el=footer). Last update [288bf6e...e190aa3](https://codecov.io/gh/pandas-dev/pandas/pull/18695?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18695?src=pr&el=h1) Report
> Merging [#18695](https://codecov.io/gh/pandas-dev/pandas/pull/18695?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/288bf6e5e3287a8c66a7ed41050db0ebf56d7ea6?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/18695/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/18695?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #18695      +/-   ##
==========================================
- Coverage    91.6%   91.59%   -0.02%     
==========================================
  Files         153      153              
  Lines       51272    51276       +4     
==========================================
- Hits        46967    46964       -3     
- Misses       4305     4312       +7
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.45% <100%> (ø)` | :arrow_up: |
| #single | `40.68% <12.5%> (-0.11%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/18695?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/plotting/\_core.py](https://codecov.io/gh/pandas-dev/pandas/pull/18695/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb3JlLnB5) | `82.41% <100%> (+0.03%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/18695/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/18695/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.81% <0%> (-0.1%)` | :arrow_down: |
| [pandas/io/excel.py](https://codecov.io/gh/pandas-dev/pandas/pull/18695/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2V4Y2VsLnB5) | `90.13% <0%> (ø)` | :arrow_up: |
| [pandas/core/internals.py](https://codecov.io/gh/pandas-dev/pandas/pull/18695/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzLnB5) | `94.44% <0%> (ø)` | :arrow_up: |
| [pandas/io/parsers.py](https://codecov.io/gh/pandas-dev/pandas/pull/18695/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3BhcnNlcnMucHk=) | `95.55% <0%> (ø)` | :arrow_up: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/18695/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `82.01% <0%> (+0.19%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18695?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18695?src=pr&el=footer). Last update [288bf6e...aea8383](https://codecov.io/gh/pandas-dev/pandas/pull/18695?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

thanks @MasonGallo nice patch! keep em coming!
See https://github.com/pandas-dev/pandas/issues/19699

On Tue, Mar 20, 2018 at 1:29 PM, flutefreak7 <notifications@github.com>
wrote:

> *@flutefreak7* commented on this pull request.
> ------------------------------
>
> In pandas/plotting/_core.py
> <https://github.com/pandas-dev/pandas/pull/18695#discussion_r175877322>:
>
> >                  data = data.set_index(x)
>
>              if y is not None:
>                  if is_integer(y) and not data.columns.holds_integer():
>                      y = data.columns[y]
> +                elif not isinstance(data[y], Series):
>
> So if I do df.plot.line(x='x', y=['y1', 'y2', 'y3']) this is now a
> ValueError?
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/18695#pullrequestreview-105481471>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABQHIlLuQemvhx7IqH8azMnUaXdQQf1Qks5tgUqAgaJpZM4Q7XF0>
> .
>