FIX: Introduced new keyword 'density' in the hist function #8408
FIX: Introduced new keyword 'density' in the hist function #8408moboehle wants to merge 4 commits intomatplotlib:masterfrom
Conversation
…istent with numpy
|
@tacaswell I thought we had a PR for this; did it not get merged? |
|
Sorry, I didn't see that there was a PR already, since it did not reference the issue. |
| slc = slice(None, None, -1) | ||
|
|
||
| if normed: | ||
| if density: |
There was a problem hiding this comment.
Looks like this path is never tested. Could you add a test that uses the density option?
lib/matplotlib/axes/_axes.py
Outdated
| if histtype == 'barstacked' and not stacked: | ||
| stacked = True | ||
|
|
||
| if density is not None and normed is not None and normed != density: |
lib/matplotlib/axes/_axes.py
Outdated
| stacked = True | ||
|
|
||
| if density is not None and normed is not None and normed != density: | ||
| raise ValueError("kwargs density and normed cannot have different\ |
There was a problem hiding this comment.
Minor style comment. Can you do:
raise ValueError("kwargs density and normed cannot have different "
"values. Use density only, since normed will be deprecated.")|
Thanks for your work on this! I definitely think it should raise if both kwargs are passed. If the uses passes in both, then they must be passed as identical values (so we do not have to document and people do not have understand the precedence rules). This can lead to very brittle code, will just move the frustration / debugging to a later time (when they two values get out of sync), and does not actually help improve the clarity. @moboehle Are you comfortable enough with git to merge the two pull requests together? |
…rmed cannot be set to not None at the same time anymore.
|
@phobson Thanks for your feedback, I added some tests now. @tacaswell You are right, allowing to set both 'normed' and 'density' could lead to odd behavior, I updated this now. I would be happy to merge the pull requests together, but I am not quite sure how to go about this. |
dstansby
left a comment
There was a problem hiding this comment.
This looks good - just need to get rid of the changes to the autogenerated file.
I also can't see any tests in the diff?
| bottom=None, histtype='bar', align='mid', orientation='vertical', | ||
| rwidth=None, log=False, color=None, label=None, stacked=False, | ||
| hold=None, data=None, **kwargs): | ||
| def hist(x, bins=None, range=None, density=None, normed=None, weights=None, |
There was a problem hiding this comment.
lib/matplotlib/pyplot.py is an autogenerated file, so these changes will need to be reverted.
|
#7856 has a test (that needs an image committed). @moboehle I suggest you do the following: You will probably have to clean up some conflicts, but then commit and push everything back to your branch. You will need commit the test image results as well. If you need help jump into https://gitter.im/matplotlib/matplotlib |
|
Ping @moboehle. |
Introduced new keyword 'density' in the hist function to be consistent with numpy.
This pull request closes issue #7364. Contrary to what was suggested in the comments, no error is raised in the case that both keywords density and normed are used. If neither are defined, default is 'False'.