-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST: DataFrame.hist() does not get along with matplotlib.pyplot.tight_layout() #15515
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
Conversation
Note: in addition to the #9351 unit test this PR also adds a |
pandas/util/testing.py
Outdated
v = matplotlib.__version__ | ||
if v < LooseVersion('2.0.0') or v[0] == '0' or v[0] == '1': | ||
import pytest | ||
pytest.skip("matplotlib 1.5") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
matpotlib < 2.0.0
df.plot.hist() | ||
|
||
try: | ||
self.plt.tight_layout() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need the try/except (if it works it won't raise)
add a 1-line comment & the issue number as a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couple of small comments
pandas/util/testing.py
Outdated
@@ -286,6 +286,14 @@ def _skip_if_mpl_1_5(): | |||
pytest.skip("matplotlib 1.5") | |||
|
|||
|
|||
def _skip_if_mpl_1(): | |||
import matplotlib |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually you don't need this, instead use:
if self.mpl_ge_2_0_0:
as these are defined in the base class (you can look in pandas.tools.plotting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.mpl_get_2_0_0
I assume? Edit: nvm, I see it is indeed ge
. What does that stand for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no take this function out
I rewrote the test using |
Codecov Report
@@ Coverage Diff @@
## master #15515 +/- ##
==========================================
+ Coverage 90.36% 90.36% +<.01%
==========================================
Files 136 136
Lines 49553 49554 +1
==========================================
+ Hits 44780 44781 +1
Misses 4773 4773
Continue to review full report at Codecov.
|
if self.mpl_ge_2_0_0: | ||
df = DataFrame(randn(100, 2)) | ||
df.plot.hist() | ||
self.plt.tight_layout() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need a _check_plot_works
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would _check_plot_works(df.hist); self.plt.tight_layout()
work? The method seems to be designed for testing parameter inputs, but tight_layout
isn't a histogram parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes that's fine. I realize this just raises AttributeError
, so that would be caught by the tests anyhow.
lgtm. ping on green. |
actually, pls add a whatsnew note as well (I guess in Bug Fixes). This is really a mpl compat issue, and there isn't much we can do about it with < 2.0.0, so best just to note this in the whatsnew as well so readers can react to this. |
lgtm. thanks. |
thanks! |
…_layout() (pandas-dev#15515) * Add unit test for pandas-dev#9351 * Tweaks. * add _check_plot_works; rm aux method * Add whatsnew entry.
git diff upstream/master | flake8 --diff