Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 439dbbe

Browse files
Fixed _upcast_err docstring and comments in _axes.py
1 parent 1ab4a53 commit 439dbbe

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3332,26 +3332,17 @@ def _upcast_err(err):
33323332
"""
33333333
Safely handle tuple of containers that carry units.
33343334
3335-
If the units are carried on the values then casting to object
3336-
arrays preserves the units, but if the units are on the containers
3337-
this will not work.
3338-
33393335
This function covers the case where the input to the xerr/yerr is a
33403336
length 2 tuple of equal length ndarray-subclasses that carry the
33413337
unit information in the container.
33423338
3343-
We defer coercing the units to be consistent to the underlying unit
3339+
If we have a tuple of nested numpy array (subclasses), we defer
3340+
coercing the units to be consistent to the underlying unit
33443341
library (and implicitly the broadcasting).
33453342
3346-
If we do not have a tuple of nested numpy array (subclasses),
3347-
fallback to casting to an object array.
3348-
3343+
Otherwise, fallback to casting to an object array.
33493344
"""
33503345

3351-
# we are here because we the container is not a numpy array, but it
3352-
# _is_ iterable (likely a list or a tuple but maybe something more
3353-
# exotic)
3354-
33553346
if (
33563347
# make sure it is not a scalar
33573348
np.iterable(err) and
@@ -3363,14 +3354,17 @@ def _upcast_err(err):
33633354
# fails.
33643355
isinstance(cbook.safe_first_element(err), np.ndarray)
33653356
):
3366-
# grab the type of the first element, we will try to promote
3367-
# the outer container to match the inner container
3357+
# Get the type of the first element
33683358
atype = type(cbook.safe_first_element(err))
3369-
# you can not directly pass data to the init of `np.ndarray`
3359+
# Promote the outer container to match the inner container
33703360
if atype is np.ndarray:
3361+
# Converts using np.asarray, because data cannot
3362+
# be directly passed to init of np.ndarray
33713363
return np.asarray(err, dtype=object)
3372-
# but you can for unyt and astropy uints
3364+
# If atype is not np.ndarray, directly pass data to init.
3365+
# This works for types such as unyts and astropy units
33733366
return atype(err)
3367+
# Otherwise wrap it in an object array
33743368
return np.asarray(err, dtype=object)
33753369

33763370
if xerr is not None and not isinstance(xerr, np.ndarray):

0 commit comments

Comments
 (0)