-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix unit handling in errorbar for astropy. #19872
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
Unfortunately, this bug only triggers with astropy's unit implementation, but not with either of matplotlib's "test" units (testing.jpl_units and test_units.Quantity). So I don't have a self-contained way to add a test...
This seems fine. It would be nice if astropy could kick us back a mock-units interface that shadows theirs and added some tests. Its pretty hard for us to not break things if we can't directly test them. |
@@ -3427,13 +3427,17 @@ def extract_err(name, err, data, lolims, uplims): | |||
the note in the main docstring about this parameter's name. | |||
""" | |||
try: | |||
low, high = np.broadcast_to(err, (2, len(data))) | |||
np.broadcast_to(err, (2, len(data))) |
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.
Is it possible to check for this directly, rather than via an error? Maybe this is just as efficient?
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.
I can't find anything under https://numpy.org/doc/stable/reference/routines.array-manipulation.html#changing-number-of-dimensions :(
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.
... I guess I just mean int(len(err)/2)==len(err)/2
, or whatever is more elegant than that?
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.
Performance should not matter. This should be proportional to len(data) in computation/mempry and is only called once twice for the whole errorbar function.
@@ -3427,13 +3427,17 @@ def extract_err(name, err, data, lolims, uplims): | |||
the note in the main docstring about this parameter's name. | |||
""" | |||
try: | |||
low, high = np.broadcast_to(err, (2, len(data))) | |||
np.broadcast_to(err, (2, len(data))) |
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.
Performance should not matter. This should be proportional to len(data) in computation/mempry and is only called once twice for the whole errorbar function.
Thank you for the quick fix!
Not sure how easy that would be. Perhaps @mhvk can advise. |
To close the loop, I can confirm that this patch works for |
Great! Thanks for testing our Master branch! |
@@ -3427,13 +3427,17 @@ def extract_err(name, err, data, lolims, uplims): | |||
the note in the main docstring about this parameter's name. | |||
""" | |||
try: | |||
low, high = np.broadcast_to(err, (2, len(data))) |
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.
Sorry I looked at this so late. A simpler solution here is to add subok=True
...
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.
Just today, I decided to look at how matplotlib does this, because I need a similar interface (accept a scalar and 1 d array or a 2 d array - just like err here. I guess that's a rare case that that happens, but should I open a PR to simplify this back to np.boradcast_to
with subok
?
On providing a mock unit/quantity: that would be good, but also somewhat tricky, as our |
We already have some "importorskip" tests for pandas so, depending on how long installing the astorpy wheels adds to the CI, I am nominally 👍 on adding some that depend on astropy. I suspect we can add a module that looks like
which should both skip the whole module if astropy is not installed and let us run the astropy tests without having to re-implement them! |
Not sure if that's possible, but could the tests be |
Our tests are super-localized (to |
Or you can wait for us to open issues when things fail... 😆 |
Is this really an approach we want to take? I would rather we actually define what rules we expect unit implementations to follow and then test against those rules, rather than bless a particular implementation of those rules. But absent anyone actually defining those rules, I guess this is ok as a stopgap. The problem with unit support is that it is hard. The fact that astropy had to dig into the ufuncs hopefully makes that clear. Do we trust that another downstream package has made the same low-level choices? What range of choices are we going to accept? |
is the minimal stopgap solution. Since astropy thankfully tests against master, we at least realize if something gets broken before any release. That way we keep astropy working without explicit unit rules and without formally blessing astropy as reference implementation. (Yes, this is stealing away from a proper solution, but may be good enough for the time being). |
OK, definitely fine with astropy just being a slightly delayed test case! Would be the same with some weekly or monthly test as well.... |
Unfortunately, this bug only triggers with astropy's unit
implementation, but not with either of matplotlib's "test" units
(testing.jpl_units and test_units.Quantity). So I don't have a
self-contained way to add a test...
Closes #19526 (comment).
PR Summary
PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).