Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

FIX: let pandas IndexInt64 work for boxplot#13398

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
NelleV merged 3 commits intomatplotlib:masterfromjklymak:fix-boxplot-pandas
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes fromall 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: 4 additions & 0 deletionslib/matplotlib/axes/_axes.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3926,6 +3926,10 @@ def dopatch(xs, ys, **kwargs):
elif len(positions) != N:
raise ValueError(datashape_message.format("positions"))

positions = np.array(positions)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is a good fix for the case described in the ticket, but I think the code will continue raising obscure error when positions are not numbers. Can you add a check after this line about the dtype of the array being a number? Maybe something like:

ifnotisinstance(positions.dtype,numbers.Number):raiseTypeError("positions should be a iterable of dtype number, but found dtype %s"%blahblahblah.)

When we end up supporting something else than numbers, this can be updated.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I couldn't quite get that check to work; I had to check the first element. But if there is a better way, let me know.

if len(positions) > 0 and not isinstance(positions[0], Number):
raise TypeError("positions should be an iterable of numbers")

# width
if widths is None:
widths = [np.clip(0.15 * np.ptp(positions), 0.15, 0.5)] * N
Expand Down
9 changes: 9 additions & 0 deletionslib/matplotlib/tests/test_axes.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1524,6 +1524,15 @@ def test_bar_timedelta():
(10, 20))


def test_boxplot_dates_pandas(pd):
# smoke test for boxplot and dates in pandas
data = np.random.rand(5, 2)
years = pd.date_range('1/1/2000',
periods=2, freq=pd.DateOffset(years=1)).year
plt.figure()
plt.boxplot(data, positions=years)


def test_bar_pandas(pd):
# Smoke test for pandas

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp