Skip to content

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

Merged
merged 2 commits into from
Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2138,12 +2138,12 @@ 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)
Copy link
Member Author

@jklymak jklymak Sep 1, 2019

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....

except (TypeError, IndexError, KeyError):
x0 = x0

try:
x = xconv[0]
x = cbook.safe_first_element(xconv)
except (TypeError, IndexError, KeyError):
x = xconv

Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,14 @@ def test_bar_pandas(pd):
ax.plot(dates, baseline, color='orange', lw=4)


def test_bar_pandas_indexed(pd):
# Smoke test for indexed pandas
df = pd.DataFrame({"x": [1., 2., 3.], "width": [.2, .4, .6]},
index=[1, 2, 3])
fig, ax = plt.subplots()
ax.bar(df.x, 1., width=df.width)


@image_comparison(['hist_log'], remove_text=True)
def test_hist_log():
data0 = np.linspace(0, 1, 200)**3
Expand Down