Correct KeyError from matplotlib when processing Series yerr
State: closed

- [x] closes #11858
- [x] tests added / passed
- [x] passes `git diff upstream/master | flake8 --diff`
- [x] whatsnew entry


Labels:
name: Bug
name: Visualization
description: plotting

Comments:
pls add a whatsnew note

@jreback Which section would this go in whatsnew?

bug fix 

left note on orginal issue, but can you please check if this is still a problem on mpl 1.5.1, 2.x or master?  If so, please make an issue upstream.

whatsnew added

Also see https://github.com/matplotlib/matplotlib/pull/6392

@tacaswell Based on the assessment by @diazona  in https://github.com/pydata/pandas/pull/13114#issuecomment-218006317 , sending `ndarray` into `matplotlib` seems like a good modification (in addition to https://github.com/matplotlib/matplotlib/pull/6392 proposed by you)

That fixes the pandas problem, but not the case where

``` python
ax.errorbar('x', 'y', yerr='ye', data=df)
```

This should probably go into pandas for use with non-patched versions of mpl, but in the long run mpl should be able to cope with `Series` anyplace we can cope with ndarray.

Yep, I've confirmed that a test program like the following still reproduces the `KeyError`. (The fix I was working on in diazona/pandas@4b04f80c41684ba9ab05ce8c87b17b96fde87290 doesn't help with this case either.) Maybe there's one single place to make a change that would cover all these cases?

```
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.uniform(size=(5, 4)),
                  columns=['x', 'y', 'xe', 'ye'],
                  index=[1, 2, 3, 4, 5])
plt.errorbar('x', 'y', xerr='xe', yerr='ye', data=df)
```

Would this above be worked in a followup issue? Thanks

I think it's worth investigating how to do a more "proper" fix, but I don't have time to get on that right now. Perhaps it is better to just incorporate this commit into the master branch and take care of the other cases later with a separate issue. I guess it's up to the Pandas developers.

@gliptak if you can incorporate @diazona more extensive tests and make the changes I suggested.

You can debug the other case that was brought up and see if its possible to fix as well.

The pr into mpl fixes both issues.

@jreback @diazona The code above directly calls into mpl, so changes to pandas will not offer a fix ...

Build fail seems to be unrelated:

```
  File "/home/travis/miniconda/envs/pandas/lib/python3.5/imp.py", line 234, in load_module

    return load_source(name, filename, file)

  File "/home/travis/miniconda/envs/pandas/lib/python3.5/imp.py", line 172, in load_source

    module = _load(spec)

  File "/usr/share/google/boto/boto_plugins/compute_auth.py", line 64

    except (urllib2.URLError, urllib2.HTTPError, IOError), e:

                                                         ^

SyntaxError: invalid syntax
```

yeah go ahead and rebase, fixed a weird boto import issue

I thought we were talking about allowing Pandas to work with older versions of matplotlib that don't have @tacaswell's patch. But if you'd rather say people should simply to upgrade matplotlib to avoid this bug, and leave it at that, that works too. Just checking that I'm on the same page as everyone else.

thanks @gliptak 

yeh important that pandas fixes this (and of course even moreso for mpl)