-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX: bar mixed units, allow ValueError as well #13187
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
QT tests are failing - not this PR |
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.
Can you add a test that the error is not being raised when using pandas?
100% agree that pandas datetimes + bar should be tested. OTOH, I'm not 100% convinced its matplotlib that should be responsible for those tests if the pandas datetime unit converters are registered, which they are in this case. See #11664 for where I propose we explictly unregister pandas datetime unit conversion so then we can test our own converters (which work with basic pandas objects without the need for their converters). This was prompted by Not to say pandas' own converters shouldn't work - but it seems that they should be responsible for reporting breakages to us (like this one). However, I'm open to the idea we should fully test pandas if that is how it should be done. For this particular case, I'm pretty ignorant about how the user got to the point where |
Have we reported the breakage to pandas? If that is the case, we may want to simply add a test and a comment that this should be fixed in pandas version XXX, and remove the work around and and the test when times come. |
Hmm, looking at it again, I guess pandas thinks its a ValueError because In any case, not convinced this needs a test from our end, but the change should go in to make the |
fd5647b
to
293c529
Compare
... ah apparently |
lib/matplotlib/axes/_axes.py
Outdated
@@ -2057,7 +2057,7 @@ def _convert_dx(dx, x0, xconv, convert): | |||
dx = [convert(x0 + ddx) - x for ddx in dx] | |||
if delist: | |||
dx = dx[0] | |||
except (TypeError, AttributeError) as e: | |||
except Exception: |
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.
please leave a comment justifying (briefly) the nonspecific catch-everything behavior.
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.
Doesn't that catch everything?
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.
In principle I'm ok with except Exception:
, but for targetted code. That's a pretty big try
block to be catching with Exception
--a lot of unexpected behavior could happen in those lines. Is it possible to just wrap the try around dx = [convert(x0 + ddx) - x for ddx in dx]
?
FIX: make exception in bar for convert(x+dx) more liberal
293c529
to
e25f9f7
Compare
The current solution catches all exceptions, which we should avoid. It means will accidentally catch errors and exception we don't want to catch. I don't think the proposed solution is reasonable (sorry!) |
(I need to run, but I'll review this more carefully in the next day or so) |
@NelleV I'm happy to go back to explicit exception types, but
so I thought this would be OK. |
@jklymak But making catching exception as liberal as possible is not good practice. It means the code "works", in cases where it should probably fail. It actually happened to me several time with Matplotlib that the plot would show and be wrong due to broad error catching such as this one. I'll dismiss my review, as I am about to board a plane and will be offline for the next 24h, but I think it is better to be as narrow and explicit as possible when catching errors. |
Not available in the near future to review this PR.
Tightened exception @dopplershift I can't make the try-except block shorter because the error is sometimes in the procedure that gets the first element. Just to be clear - the idea is "try some stuff to get this to work. If that fails just do what we did before this PR". So having this try/except block makes things a bit better at no cost (other than code complexity). OTOH I don't feel passionately about this solution. If someone has a better solution for |
@dopplershift sure, but is the new version OK? It has three explicit errors. |
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.
@jklymak Sorry, new version is fine. Was holding off on review due to failing CI and lack of time to dig in.
That PR was missing a test. I'll create a PR to fix this. |
Oops. Thanks. |
PR Summary
Closes #13186
Follow up to #12903 where we try and do math first for
bar
(x+dx) before units conversion. Pandas throws aValueError
for a previously working case. This adds that to the allowableexcepts
...PR Checklist