Skip to content

ENH: Add bw_method and ind kwargs to kind='kde' plot method #4298

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
khgitting opened this issue Jul 19, 2013 · 16 comments
Closed

ENH: Add bw_method and ind kwargs to kind='kde' plot method #4298

khgitting opened this issue Jul 19, 2013 · 16 comments
Milestone

Comments

@khgitting
Copy link

It'd be really cool when plotting kde's to be able to set the bandwidth used for the kde and the indices at which it is evaluated. This is done with the bw_method kwarg for scipy.stats.gaussian_kde for scipy >= 0.11, a couple years old now, for the former; a variable ind is created in the pandas class KdePlot's _make_plot method and passed to gkde.evaluate.

Here's a patch which implements this functionality: khgitting/pandas@master...kde_kwargs

I'm having trouble passing the Travis CI tests here: https://travis-ci.org/khgitting/pandas/jobs/9284591

It appears the tests use an older version of scipy where gaussian_kde does not take bw_method kwarg. I'd love to be able to resolve this, but am not sure what the right course of action is. Any advice?

@jtratner
Copy link
Contributor

Given that pandas has to support that version of scipy, you could check for version and go from there, but you need to figure out a version number that is guaranteed to have the argument for bw_method.

As an aside self.ind is None is preferred to self.ind == None.

@jreback
Copy link
Contributor

jreback commented Jul 20, 2013

see here for how to test for versions: https://github.com/pydata/pandas/wiki/Tips-&-Tricks

@jtratner
Copy link
Contributor

to be very explicit:

from distutils.version import LooseVersion
kwargs = dict()
if LooseVersion(scipy.__version__) >= SCIPYVERSION:
    kwargs["bw_method"] = self.bw_method
gkde = gaussian_kde(y, **kwargs)

Given that it looks like there is only one thing you are setting, you could skip the dictionary creation and do:

if RIGHT_VERSION:
    gkde = gaussian_kde(y, bw_method=self.bw_method)
else:
    gkde = gaussian_kde(y)

@khgitting
Copy link
Author

Thanks much. bw_method was added in scipy 0.11.0. I added the version check, corrected the '== None', also added a warning to alert the user for the case when scipy version < 0.11.0 but when bw_method is specified but ignored, and passed the Travis-CI test.

khgitting#1

@khgitting
Copy link
Author

I rebased and squashed to reduce to one commit, then pushed, and began failing Travis-CI. After some work to determine the problem, I tried to start from the beginning, making a new fork, one commit, passed tests locally, pushed, and again failed Travis-CI tests. It appears to be in code unrelated to my patch:

https://travis-ci.org/khgitting/pandas/jobs/9324896
File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pandas-0.12.0.dev_0d06729-py2.7-linux-x86_64.egg/pandas/io/tests/test_data.py", line 145, in test_get_components_nasdaq_100
assert 'AAPL' in df.index
AssertionError

Perhaps current master is not stable?

@jreback
Copy link
Contributor

jreback commented Jul 21, 2013

this is an unrelelated (recent) failing test

@jreback
Copy link
Contributor

jreback commented Jul 21, 2013

check back periodically
once master is fixed, rebase and it will retest

@cpcloud
Copy link
Member

cpcloud commented Jul 21, 2013

@khgitting fixed, rebase and force push should pass travis now

@khgitting
Copy link
Author

@cpcloud
Copy link
Member

cpcloud commented Jul 21, 2013

the parent commit for the change u just posted is 54243c7 which is not current master

current master is 424e187

@cpcloud
Copy link
Member

cpcloud commented Jul 21, 2013

see the wiki for git tips

short version, do:

git remote add upstream git://github.com/pydata/pandas.git
git fetch upstream
git rebase upstream/master

barring any merge conflicts, this should replay your commits on top of the latest commits in pandas git master

@khgitting
Copy link
Author

@cpcloud D'oh; thanks.

Pull request passing Travis-CI tests and replayed on top of latest pandas git master:
khgitting#1

@khgitting
Copy link
Author

One final question on this -- just want to make sure I'm observing proper etiquette. I guess because it passed the Travis-CI test I have a "This pull request can be automatically merged." Should I click to do this? From http://pandas.pydata.org/developers.html , "This request then appears to the repository maintainers, and they will review the code. "

@cpcloud
Copy link
Member

cpcloud commented Jul 21, 2013

@khgitting see my comment on your pr

@cpcloud
Copy link
Member

cpcloud commented Jul 21, 2013

"This pull request can be automatically merged." will only show up on repositories to which you have push privilges

@jreback
Copy link
Contributor

jreback commented Aug 26, 2013

closed by #4316

@jreback jreback closed this as completed Aug 26, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants