Skip to content

Correct KeyError from matplotlib when processing Series yerr #13114

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
wants to merge 1 commit into from
Closed

Conversation

gliptak
Copy link
Contributor

@gliptak gliptak commented May 8, 2016

# GH11858
i = np.array([1, 2, 3])
a = DataFrame(i, index=i)
a.plot(yerr=a)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use check_plot_works

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@jreback
Copy link
Contributor

jreback commented May 8, 2016

pls add a whatsnew note

@gliptak
Copy link
Contributor Author

gliptak commented May 8, 2016

@jreback Which section would this go in whatsnew?

@jreback
Copy link
Contributor

jreback commented May 8, 2016

bug fix

@tacaswell
Copy link
Contributor

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.

@gliptak
Copy link
Contributor Author

gliptak commented May 8, 2016

whatsnew added

@tacaswell
Copy link
Contributor

Also see matplotlib/matplotlib#6392

@gliptak
Copy link
Contributor Author

gliptak commented May 9, 2016

@tacaswell Based on the assessment by @diazona in #13114 (comment) , sending ndarray into matplotlib seems like a good modification (in addition to matplotlib/matplotlib#6392 proposed by you)

@tacaswell
Copy link
Contributor

That fixes the pandas problem, but not the case where

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.

@@ -1331,6 +1331,10 @@ def _plot(cls, ax, x, y, style=None, is_errorbar=False, **kwds):
x = x._mpl_repr()

if is_errorbar:
if 'xerr' in kwds:
kwds['xerr'] = com._values_from_object(kwds.get('xerr'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually just do: np.array(kwds.get('xerr'))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@diazona
Copy link
Contributor

diazona commented May 10, 2016

Yep, I've confirmed that a test program like the following still reproduces the KeyError. (The fix I was working on in diazona/pandas@4b04f80 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)

@gliptak
Copy link
Contributor Author

gliptak commented May 10, 2016

Would this above be worked in a followup issue? Thanks

@diazona
Copy link
Contributor

diazona commented May 10, 2016

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.

@jreback
Copy link
Contributor

jreback commented May 10, 2016

@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.

@tacaswell
Copy link
Contributor

The pr into mpl fixes both issues.

@gliptak
Copy link
Contributor Author

gliptak commented May 10, 2016

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

@gliptak
Copy link
Contributor Author

gliptak commented May 11, 2016

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

@jreback
Copy link
Contributor

jreback commented May 11, 2016

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

@diazona
Copy link
Contributor

diazona commented May 13, 2016

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.

@jreback jreback added this to the 0.18.2 milestone May 13, 2016
@jreback jreback closed this in e5c18b4 May 13, 2016
@jreback
Copy link
Contributor

jreback commented May 13, 2016

thanks @gliptak

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

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 this pull request may close these issues.

Index without 0 in xerr/yerr causes KeyError
4 participants