Skip to content

DOC: Exposed arguments in plot.kde #19229

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

Merged
merged 8 commits into from
Feb 2, 2018
Merged

DOC: Exposed arguments in plot.kde #19229

merged 8 commits into from
Feb 2, 2018

Conversation

tommyod
Copy link
Contributor

@tommyod tommyod commented Jan 13, 2018

The documentation for plot.kde did not show the bw_method and ind arguments, which are specific to plot.kde (and plot.density, which refers to the same method).

There is also a change in the actual code, and a corresponding test added. I added an option for ind to be an integer number of sample points, instead of necessarily a np.array. I image that a user typically just wants a number of equidistant sample points, and does not want to construct an array.

  • tests added / passed
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

Comments very welcome.

@pep8speaks
Copy link

pep8speaks commented Jan 13, 2018

Hello @tommyod! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on February 01, 2018 at 14:12 Hours UTC

@tommyod
Copy link
Contributor Author

tommyod commented Jan 13, 2018

Ran the flake8 tool while in the wrong subdirectory locally. Will fix the errors tomorrow and push.

Copy link
Contributor

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

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

Thanks. Could fixup the linting errors, and add a release note in whatsnew/v0.23.0.txt?

@@ -1398,6 +1398,10 @@ def _get_ind(self, y):
sample_range = np.nanmax(y) - np.nanmin(y)
ind = np.linspace(np.nanmin(y) - 0.5 * sample_range,
np.nanmax(y) + 0.5 * sample_range, 1000)
elif isinstance(self.ind, (int, np.int)):
Copy link
Contributor

Choose a reason for hiding this comment

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

Use isinstance(self.ind, numbers.Integral). It should catch both of these (may have to import numbers).

Copy link
Contributor

Choose a reason for hiding this comment

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

instead of this, just use is_integer, which is our version of this and handles all the cases.
import from pandas.core.dtypes.common (if not already imported)

@@ -622,6 +622,7 @@ def test_kde_kwargs(self):
pytest.skip("mpl is not supported")

from numpy import linspace
_check_plot_works(self.ts.plot.kde, bw_method=None, ind=20)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a test with np.int(20) as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a use with bw_method as a string.

@codecov
Copy link

codecov bot commented Jan 14, 2018

Codecov Report

Merging #19229 into master will decrease coverage by <.01%.
The diff coverage is 42.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #19229      +/-   ##
==========================================
- Coverage   91.67%   91.67%   -0.01%     
==========================================
  Files         148      148              
  Lines       48553    48556       +3     
==========================================
  Hits        44513    44513              
- Misses       4040     4043       +3
Flag Coverage Δ
#multiple 90.03% <42.85%> (-0.01%) ⬇️
#single 41.71% <28.57%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/plotting/_core.py 82.23% <42.85%> (-0.18%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 35812ea...826a124. Read the comment docs.

@tommyod
Copy link
Contributor Author

tommyod commented Jan 14, 2018

@jreback, @TomAugspurger - I have addressed the comments.

  • Wrote an additional test.
  • Fixed linting errors.
  • Type checked with is_integer.
  • Added whatsnew comment.

@tommyod
Copy link
Contributor Author

tommyod commented Jan 20, 2018

@jreback Friendly reminder to consider this PR, in case it has been forgotten. If there is anything else that needs to be done, please let me know.

The method used to calculate the estimator bandwidth. This can be
'scott', 'silverman', a scalar constant or a callable.
If None (default), 'scott' is used.
See :scipy:class:`stats.gaussian_kde` for more information.
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you verified that this link works? I thought it would be

:func:`scipy.stats.gaussian_kde`.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Changed it.

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

small changes.

@@ -478,7 +478,7 @@ Plotting

- :func: `DataFrame.plot` now raises a ``ValueError`` when the ``x`` or ``y`` argument is improperly formed (:issue:`18671`)
- Bug in formatting tick labels with ``datetime.time()`` and fractional seconds (:issue:`18478`).
-
- The arguments ``ind`` and ``bw_method`` are added to the docstring of :meth:`Series.plot.kde` (:issue:`18461`). The argument ``ind`` may now also be an integer (number of sample points).
Copy link
Contributor

Choose a reason for hiding this comment

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

:meth:`Series.plot.kde` has exposed the args......in the doc-string.

@@ -622,6 +622,7 @@ def test_kde_kwargs(self):
pytest.skip("mpl is not supported")

from numpy import linspace
_check_plot_works(self.ts.plot.kde, bw_method=None, ind=20)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a use with bw_method as a string.

@@ -622,6 +622,8 @@ def test_kde_kwargs(self):
pytest.skip("mpl is not supported")

from numpy import linspace
Copy link
Contributor

Choose a reason for hiding this comment

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

don't import here, rather use np.linspace

@@ -622,6 +622,8 @@ def test_kde_kwargs(self):
pytest.skip("mpl is not supported")

from numpy import linspace
_check_plot_works(self.ts.plot.kde, bw_method=None, ind=20)
_check_plot_works(self.ts.plot.kde, bw_method=None, ind=np.int(20))
Copy link
Contributor

Choose a reason for hiding this comment

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

ideally would parametrize this test instead of repeating.

@jreback jreback added this to the 0.23.0 milestone Jan 21, 2018
`**kwds` : optional
Keyword arguments to pass on to :py:meth:`pandas.DataFrame.plot`.
Keyword arguments to pass on to :py:meth:`pandas.Series.plot`.
Copy link
Contributor

Choose a reason for hiding this comment

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

is this change right? This the DataFrame one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. My bad. It should be pandas.DataFrame.plot, and I have made the change.

@tommyod
Copy link
Contributor Author

tommyod commented Feb 2, 2018

@jreback I believe this PR is good to go now.

@TomAugspurger TomAugspurger merged commit 69cd5fb into pandas-dev:master Feb 2, 2018
@TomAugspurger
Copy link
Contributor

Thanks @tommyod!

harisbal pushed a commit to harisbal/pandas that referenced this pull request Feb 28, 2018
* Exposed arguments in plot.kde, added number of sample points as option

* Added a test for plot.kde with  as an integer

* Added whatsnew. Fixed flake8 errors. Used is_integer  to infer type.

* Updated scipy reference

* Added test, rewrote whatsnew, removed import

* Changed from Series to DataFrame in doc

* Fixed PEP8 errors in test file

* Fixed typo which made tests crash
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.

4 participants