-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix pandas DataFrame align center #8785
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
lib/matplotlib/tests/test_axes.py
Outdated
fig, axArr = plt.subplots(2) | ||
|
||
curr = 1 | ||
for ax in axArr: |
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.
is there a reason you need to test this two ways? (and if so, why aren't they explicitly separate parameterized tests?)
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 could not recreate the error found inn 8767 without the 2 subplots.
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.
it is probably worth doing both bar
and barh
(as you changed the code path for both).
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 will add the test for barh to this pr tonight, and will add a fig.canvas.draw
to make sure the rendering finishes all the way.
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.
The trick is probably to have an index without 0 in it, I think df = pd.DataFrame({'a': range(5), 'b': range(5)}, index=list('abcde'))
would produce the exception.
lib/matplotlib/tests/test_axes.py
Outdated
|
||
curr = 1 | ||
for ax in axArr: | ||
rects = ax.bar(df.loc[df['col1'] == curr, 'col2'], |
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.
also, what's considered a passing test here? Just no error?
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.
Correct
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 it'd be worthwhile to do an affirmative test to verify it works as expected.
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.
We have a lot of other tests were not raising is sufficient. We do not really need an image test for this. Might be worth putting in a fig.canvas.draw
to make sure it renders all the way through though.
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 don't think it needs an image test either...but I do think just a not raises isn't great when testing a kwarg - like it could very well be doing something unexpected/not parsing the data correctly.
@ryanlaclair Thanks ! 👍 on the fix, would like to see a test for barh as well. |
You can also pass |
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.
The test could be tweaked to pass an explicit index
karg to the DataFrame init, but this is ok as it is
This is a candidate for squash merge.
Squashed. |
@ryanlaclair I think this was your first Matplotlib contribution. Congratulations 🎉 ! Hopefully we will hear from you again! |
Fixes pandas KeyError when
align=center
is specified for bar plot by replacing index access with a list comprehension usingzip
.PR Summary
Added test highlighting the bug to lib/matplotlib/tests/test_axes.py.
Fixed bug in lib/matplotlib/axes/_axes.py by replacing the index access with a list comprehension using
zip
.Bugfix for issue #8767 .
PR Checklist