Skip to content

Index without 0 in xerr/yerr causes KeyError #11858

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
diazona opened this issue Dec 17, 2015 · 6 comments
Closed

Index without 0 in xerr/yerr causes KeyError #11858

diazona opened this issue Dec 17, 2015 · 6 comments
Labels
Milestone

Comments

@diazona
Copy link
Contributor

diazona commented Dec 17, 2015

When creating an errorbar plot, if the data object being used for the errors (xerr or yerr) doesn't have 0 in its index, it produces a KeyError from matplotlib code. I can produce this with the following code sample:

import pandas as pd, numpy as np
i = np.array([1,2,3])
a = pd.DataFrame(i, index=i)
a.plot(yerr=a)

The underlying bug (if it is a bug) in matplotlib is responsible for several other issues, including #4493 and #6127, but this case is different because it uses only Pandas API methods, rather than passing a Pandas object to a matplotlib method. So it's a little harder to justify passing this off on matplotlib to fix, as was done in e.g. #6127.

If the "proper" fix ever is implemented in matplotlib code, it should solve this as well as #4493 and #6127 and all the others of that nature, but until that point, Pandas can work around it by converting the error object (if it is a Series or DataFrame) to an ndarray. I'm working on this in 4b04f80 but I'm not sure if there's a better way to fix it, or if this breaks something. (If so, the tests don't indicate it.)

@jorisvandenbossche
Copy link
Member

@diazona This also seems a regression (in pandas or matplotlib), as I don't get an error with pandas 0.16.2 and matplotlib 1.4.3, but do get one with 0.17.1 and 1.5.0

@TomAugspurger
Copy link
Contributor

Haven't looked, but sounds similar to matplotlib/matplotlib#5550

@diazona I'm assuming you're using matplotlib 1.5? Can you try with 1.4.3?

@diazona
Copy link
Contributor Author

diazona commented Dec 18, 2015

Yeah, matplotlib/matplotlib#5550 seems like the exact same issue. That didn't come up in my search, so I hadn't realized the matplotlib developers were open to fixing it. If they do implement that fix, it renders my patch obsolete (though I think it's still a semantic improvement).

Let me take some time to get a previous version of matplotlib and test with that. I am indeed using 1.5.0. Here's the complete version info:

>>> pd.show_versions()

INSTALLED VERSIONS
------------------
commit: 4b04f80c41684ba9ab05ce8c87b17b96fde87290
python: 3.4.3.final.0
python-bits: 64
OS: Darwin
OS-release: 15.2.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.17.1+84.g4b04f80
nose: 1.3.7
pip: 7.1.2
setuptools: 18.5
Cython: 0.23.4
numpy: 1.10.1
scipy: 0.16.1
statsmodels: 0.6.1
IPython: 4.0.1
sphinx: None
patsy: 0.4.1
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: 1.0.0
tables: 3.2.2
numexpr: 2.4.6
matplotlib: 1.5.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8

@diazona
Copy link
Contributor Author

diazona commented Dec 18, 2015

Update: matplotlib 1.4.3 indeed does not exhibit the error. After an enthralling git bisect run, I traced the KeyError to code introduced in matplotlib/matplotlib@5f33e7d, on the 1.5.0 development branch.

For what it's worth, the current master HEAD matplotlib/matplotlib@9f6bb90 does raise the KeyError.

I haven't tested with other versions of Pandas.

@tacaswell
Copy link
Contributor

Can someone re-check if this is still a problem? I think we fixed this is v1.5.1.

@andres-aguilar
Copy link

yes, here v. 1.5.1 and the same problem

tacaswell added a commit to tacaswell/matplotlib that referenced this issue May 9, 2016
In errorbar do not assume that [0] or [1] will work correctly
(due to issues with pandas).

Closes pandas-dev/pandas#11858
@jreback jreback modified the milestones: 0.18.2, Next Major Release May 13, 2016
tacaswell added a commit to tacaswell/matplotlib that referenced this issue May 22, 2016
In errorbar do not assume that [0] or [1] will work correctly
(due to issues with pandas).

Closes pandas-dev/pandas#11858
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants