-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. ... I guess I just mean There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
except ValueError: | ||
raise ValueError( | ||
f"'{name}err' (shape: {np.shape(err)}) must be a scalar " | ||
f"or a 1D or (2, n) array-like whose shape matches " | ||
f"'{name}' (shape: {np.shape(data)})") from None | ||
return data - low * ~lolims, data + high * ~uplims # low, high | ||
# This is like | ||
# low, high = np.broadcast_to(...) | ||
# return data - low * ~lolims, data + high * ~uplims | ||
# except that broadcast_to would strip units. | ||
return data + np.row_stack([-(1 - lolims), 1 - uplims]) * err | ||
|
||
if xerr is not None: | ||
left, right = extract_err('x', xerr, x, xlolims, xuplims) | ||
|
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
withsubok
?