-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX: indexed pandas bar #15166
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
FIX: indexed pandas bar #15166
Conversation
d472ac8
to
10770e9
Compare
Is this function used anywhere else then with bars? Should bar also support dataframes, like
This works with |
I don't think df = pd.DataFrame({'boo':[1,2,3]},index=[1,2,3])
plt.figure()
plt.bar(df, 1, width=.2) ever worked ( |
Ok, just take |
This PR is trying to fix something I broke, not expand the duck typing for bar. |
Use `safe_first_element` from cbook which does the `next(iter(x))` dance to get the first element of an object (as defined by what you get when you iterate over it).
@@ -2138,33 +2138,14 @@ def _convert_dx(dx, x0, xconv, convert): | |||
# removes the units from unit packages like `pint` that | |||
# wrap numpy arrays. | |||
try: | |||
x0 = x0[0] | |||
x0 = cbook.safe_first_element(x0) |
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.
This is great! Should have checked cbook....
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon! If these instruction are inaccurate, feel free to suggest an improvement. |
FIX: indexed pandas bar
Backport PR #15166 on branch v3.1.x
PR Summary
Closes #15162
basically if you do
df = pd.DataFrame({"x":[1,2,3],"width":[.2,.4,.6]},index=[1,2,3])
, thendf.x[0]
errors because that index doesn't exist, which breaksbar
.While I appreciate this is a bit more code than trying to call
iat(0)
, which is what we did before, this solution doesn't presupposeiat
exists.Now yields the expected (and pre 3.1.0):
PR Checklist