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 for failing bar plot w/ units#10623

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
dstansby merged 4 commits intomatplotlib:masterfromTD22057:jpl_unit_tests
Mar 1, 2018

Conversation

TD22057
Copy link
Contributor

@TD22057TD22057 commentedFeb 27, 2018
edited by jklymak
Loading

Fixes#10619

This re-orders the unit conversion calling in bar() to convert the units before casting to a numpy array. Only the code order in _axes.py changes. Unit test added to test_units.py to check bar() and barh() for this case.

FYI - I still have a few failing tests (not in the code I was touching) after doing this but I don't want to try and fix those since I don't think they're my fault. Notably test_bar_tick_label_single which is in bar() and calls set_ticks() with a scalar which isn't allowed. I'm assuming someone else is on top of that but if not, let me know and I can try and fix those too.

@TD22057
Copy link
ContributorAuthor

FYI I'm working on fixing the test builds now - I think those are the result of my change after all so I'll figure them out.

@jklymak
Copy link
Member

This looks good to me. But we should make sure our internal units also work, and maybe downstream packages. I don't understand how this could have been wrong before and still passed all the tests.

Can we add a test totest_dates.py to make sure that this does something intelligent w/ dates? I don't see thattest_dates.py ever checksbar().

@story645, does categoricals do OK under this change? I assume categoricals testsbar()?

@ngoldbaum are you able to check that this change is OK from theyt side of things?

@jklymakjklymak changed the titleFix for #10619 failing bar plot w/ unitsFix for failing bar plot w/ unitsFeb 28, 2018
@story645
Copy link
Member

@jklymak yup, categoricals tests bar so assuming the tests are run, the tests are still doing what's expected.

@TD22057
Copy link
ContributorAuthor

@jklymak This isn't a problem because of JPL's units, this is a problem with bar and any units. While testing it with different kinds of units would be nice, I don't see how it's necessary since all units go through the same API. All current tests pass (as the checks show) - I just added more tests to show this case. AFAIK, there were no unit tests for bar with units before. So I'd vote for merging the request and if you feel like adding even more tests after that, that would be great too. In the future, I'll be sending another pull request with even more general plot tests that use units as well.

@ngoldbaum
Copy link
Contributor

I don't see how it's necessary since all units go through the same API

I think that's only true if you register your unit system with matplotlib.

I'll try to test this PR with yt's unit system tomorrow.

@jklymak
Copy link
Member

I don't see how it's necessary since all units go through the same API.

I think that was my point. If this PR is correct, thenbar must not have worked with units before. That it works now it great, I just think it'd be nice to have a quick test. You are touching a general fcn, so I don't think its out of line to ask for tests that prove that it works generally.

@TD22057
Copy link
ContributorAuthor

@jklymak Sorry - I'm still confused. How am I suppose to prove that something works generally? I ran the unit tests that exist - to me, that's how to prove that it still works. If you feel that there is some specific use case in bar() that needs to be tested, feel free to spell out what it is but I have seen that.

Maybe I'm reading too much into this but to be honest with you, this is a little frustrating. An MPL developer updated bar() recently and broke this feature (I don't know why). If there are general bar unit tests that need to be written, I think they should have done that then. I found the bug, wrote a test case showing the bug, fixed the bug, and made sure all the existing tests still work. From my perspective, that's way more that most users are ever going to supply you with. It feels like you're asking a user (me) to do more work and be more rigorous than the actual developers are doing in the first place.

@jklymak
Copy link
Member

I'm just asking that we add abar test totest_dates.py, which are the only units we use internally (except for categories, which@story645 indicates are still working fine).

We need such a test. That its not already there is certainly not your fault. Its probably not there becausebar wasn't working before...

But, if we add the test after this PR goes in, and the test fails, then we have to revert this PR, and figure out how to make this PR work. Or, we could just add the test to this PR, which'll prove this PR doesn't break anything, and seems simpler in my opinion.

If you don't care to add the test yourself, would you be troubled if I force-pushed to this PR?

@TD22057
Copy link
ContributorAuthor

OK - fine. I put this test in:

@image_comparison(baseline_images=['bar_date'], extensions=['png'],                  savefig_kwarg={'dpi': 120}, style='mpl20')def test_bar():    day = datetime.timedelta(1)    x = [0, 1, 2]    w = [1*day, 2*day, 3*day]    b = datetime.datetime(2009, 4, 25)    fig, ax = plt.subplots()    ax.bar(x, w, bottom=b)    ax.set_ylim([b-1*day, b+w[-1]+1*day])

And that fails because the datetime unit converter doesn't handle units of duration (timedelta) values which (IMO) is the correct way to specify widths for a datetime bar plot. If I change the w variable to be floats, it will plot. But - the axis formatter is not set to be dates so it just shows floating point values (this may or may not be a problem depending on what you think should happen). So in my opinion, there are one or two issues with the datetime unit converter class that are exposed with this.

Neither of these really has anything to do with this pull request or the changes I made to bar - they are both issues inside the datetime converter. I'd recommend opening a new bug report and assigning it to whomever is cognizant of the datetime converters.

@jklymak
Copy link
Member

@TD22057 Thanks a lot for the extra effort. Sorry that it didn't pan out, but this PR definitely doesn't make things worse....

@ngoldbaum
Copy link
Contributor

Seems to work just fine with yt's unit system.

jklymak reacted with thumbs up emoji

@dstansby
Copy link
Member

I think this PR is more evidence that my "convert units" decorator would be very useful ;) (#10411)

@dstansbydstansby merged commit7a73864 intomatplotlib:masterMar 1, 2018
tacaswell added a commit that referenced this pull requestMar 2, 2018
@tacaswell
Copy link
Member

Thanks@TD22057 !

@TD22057TD22057 deleted the jpl_unit_tests branchMarch 2, 2018 17:59
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@jklymakjklymakjklymak approved these changes

@dstansbydstansbydstansby approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v2.2.0
Development

Successfully merging this pull request may close these issues.

bar plot fails with units
6 participants
@TD22057@jklymak@story645@ngoldbaum@dstansby@tacaswell

[8]ページ先頭

©2009-2025 Movatter.jp