Fix bar datetime#25667
Conversation
| self._process_unit_info( | ||
| [("x", x), ("y", height)], kwargs, convert=False) | ||
| [("x", x), ("y", height + y)], kwargs, convert=False) |
There was a problem hiding this comment.
Should we use _convert_dx for these?
There was a problem hiding this comment.
I think that happens directly below, but this is the step that sets the units on the axes, and it was not working properly with timedelta + datetime (it works fine with timedelta because its just a float with a unit attached).
There was a problem hiding this comment.
Change y = 0 to y = [0] (similar for x) a few lines up to get rid of the errors?
There was a problem hiding this comment.
Grrrr... our units handling is such a PITA. The problem is height = [1, 2, 4], and y=bottom = 0 of course cannot be added together. y=[0] won't help that, and indeed is wildly incorrect.
Trying by extracting the first safe element from x and y. This should maybe move into the units checker...
|
This doesn't work for categorical in "height". (0 + 'cat') has no meaning. I'll be honest, I don't understand why |
4721d1f to
7bf2269
Compare
|
OK, this works, but not happy with all the try/except clauses. Just to summarize the issues:
|
diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py
index f80efddfe1..89e79d35a8 100644
--- a/lib/matplotlib/axes/_axes.py
+++ b/lib/matplotlib/axes/_axes.py
@@ -2391,12 +2391,12 @@ class Axes(_AxesBase):
if orientation == 'vertical':
self._process_unit_info(
- [("x", x), ("y", height)], kwargs, convert=False)
+ [("x", x), ("y", height), ("y", y)], kwargs, convert=False)
if log:
self.set_yscale('log', nonpositive='clip')
else: # horizontal
self._process_unit_info(
- [("x", width), ("y", y)], kwargs, convert=False)
+ [("x", width), ("x", x), ("y", y)], kwargs, convert=False)
if log:
self.set_xscale('log', nonpositive='clip')
I think this works just as well (and perhaps can even be simplified to remove the horizontal/vertical dependence on the difference for unit behavior. It would perhaps be odd if we were using the returns here, but this should, I belive, use the units from the first of the two with the same axis that has an associated Converter ( There is nothing preventing passing multiple tuples for the same axis, as far as I can tell. |
|
That does seem to work, and passes all the tests. OTOH I worry about the axis latching onto the wrong unit (eg in height) if for instance someone makes a timedelta converter, which has been talked about quite a bit. In that case, the timedelta converter would be used because height is passed in first, but we really meant to check datetime+timedelta. The point is "height" really should be in delta units, whereas bottom should be in absolute units. However, we have allowed 0 + 'cat', which is clearly in categorical units - or at least we have tests that do this, whether they are sensible or not is open to intepretation (and we allow empty lists, which we could probably just short circuit at the at top, so thats not really a problem) |
|
If we swapped the order (i.e. did I think it may still have delta problems, but not sure it would have any more delta problems than than the try/excepts implemented here... With try/except paths as implemented here: If With passing both separately to The raw float value will not assign units, the timedelta will. This is the same end result. As for categoricals, I can't think of a sensible way to have your categories be a "delta", as is needed for height with non-zero baseline. Current main already breaks if you try to pass categoricals to both bottom and height, though not in |
|
OK - note that |
|
Even so, it still returns a |
8226ad7 to
e3bd2fb
Compare
|
New implementation follows @ksunden suggestion, which works well, and as discussed on the call, I agree is semantically correct. |
| try: | ||
| return next(val for val in obj if safe_isfinite(val)) | ||
| except TypeError: | ||
| # not an iterable... | ||
| return obj |
There was a problem hiding this comment.
Is this still necessary? It looks like the calls to _safe_first_finite were reverted.
There was a problem hiding this comment.
Thats true... OTOH, if we pass _safe_first_element(12) do we want it to error?
e3bd2fb to
11f69de
Compare
FIX: bar handle datetime FIX: more checks for empty bars, and single-entry bars FIX: more checks for categorical DOC: fix
PR Summary
Closes #25654
used to not assign a AutoDateFormatter to the y axis. Now it does:
PR Checklist
Documentation and Tests
pytestpasses)Release Notes
.. versionadded::directive in the docstring and documented indoc/users/next_whats_new/.. versionchanged::directive in the docstring and documented indoc/api/next_api_changes/next_whats_new/README.rstornext_api_changes/README.rst