-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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. |
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 to @story645, does categoricals do OK under this change? I assume categoricals tests @ngoldbaum are you able to check that this change is OK from the |
@jklymak yup, categoricals tests bar so assuming the tests are run, the tests are still doing what's expected. |
@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. |
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. |
I think that was my point. If this PR is correct, then |
@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. |
I'm just asking that we add a We need such a test. That its not already there is certainly not your fault. Its probably not there because 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? |
OK - fine. I put this test in:
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. |
@TD22057 Thanks a lot for the extra effort. Sorry that it didn't pan out, but this PR definitely doesn't make things worse.... |
Seems to work just fine with yt's unit system. |
I think this PR is more evidence that my "convert units" decorator would be very useful ;) (#10411) |
Backport PR #10623 on branch v2.2.x
Thanks @TD22057 ! |
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.