-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix errorbar crash on nan values #24823
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 |
---|---|---|
|
@@ -3498,28 +3498,32 @@ def _upcast_err(err): | |
|
||
Otherwise, fallback to casting to an object array. | ||
""" | ||
|
||
if ( | ||
# make sure it is not a scalar | ||
np.iterable(err) and | ||
# and it is not empty | ||
len(err) > 0 and | ||
# and the first element is an array sub-class use | ||
# safe_first_element because getitem is index-first not | ||
# location first on pandas objects so err[0] almost always | ||
# fails. | ||
isinstance(cbook._safe_first_finite(err), np.ndarray) | ||
): | ||
# Get the type of the first element | ||
atype = type(cbook._safe_first_finite(err)) | ||
# Promote the outer container to match the inner container | ||
if atype is np.ndarray: | ||
# Converts using np.asarray, because data cannot | ||
# be directly passed to init of np.ndarray | ||
return np.asarray(err, dtype=object) | ||
# If atype is not np.ndarray, directly pass data to init. | ||
# This works for types such as unyts and astropy units | ||
return atype(err) | ||
try: | ||
if ( | ||
# make sure it is not a scalar | ||
np.iterable(err) and | ||
# and it is not empty | ||
len(err) > 0 and | ||
# and the first element is an array sub-class use | ||
# safe_first_element because getitem is index-first not | ||
# location first on pandas objects so err[0] almost | ||
# always fails. | ||
isinstance(cbook._safe_first_finite(err), np.ndarray) | ||
): | ||
# Get the type of the first element | ||
atype = type(cbook._safe_first_finite(err)) | ||
# Promote the outer container to match the inner container | ||
if atype is np.ndarray: | ||
# Converts using np.asarray, because data cannot | ||
# be directly passed to init of np.ndarray | ||
return np.asarray(err, dtype=object) | ||
# If atype is not np.ndarray, directly pass data to init. | ||
# This works for types such as unyts and astropy units | ||
return atype(err) | ||
except StopIteration: | ||
# this means we found no finite element, fall back to default | ||
# case. | ||
pass | ||
Comment on lines
+3523
to
+3526
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. What do you expect to raise this exception? Is it 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. Should we raise a more telling error in |
||
# Otherwise wrap it in an object array | ||
return np.asarray(err, dtype=object) | ||
|
||
|
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.