Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5c59e4a

Browse files
authored
Merge pull request matplotlib#22943 from meeseeksmachine/auto-backport-of-pr-22923-on-v3.5.x
Backport PR matplotlib#22923 on branch v3.5.x (Fixed _upcast_err docstring and comments in _axes.py)
2 parents 3420565 + e77c8e3 commit 5c59e4a

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
@@ -3285,26 +3285,17 @@ def _upcast_err(err):
32853285
"""
32863286
Safely handle tuple of containers that carry units.
32873287
3288-
If the units are carried on the values then casting to object
3289-
arrays preserves the units, but if the units are on the containers
3290-
this will not work.
3291-
32923288
This function covers the case where the input to the xerr/yerr is a
32933289
length 2 tuple of equal length ndarray-subclasses that carry the
32943290
unit information in the container.
32953291
3296-
We defer coercing the units to be consistent to the underlying unit
3292+
If we have a tuple of nested numpy array (subclasses), we defer
3293+
coercing the units to be consistent to the underlying unit
32973294
library (and implicitly the broadcasting).
32983295
3299-
If we do not have a tuple of nested numpy array (subclasses),
3300-
fallback to casting to an object array.
3301-
3296+
Otherwise, fallback to casting to an object array.
33023297
"""
33033298

3304-
# we are here because we the container is not a numpy array, but it
3305-
# _is_ iterable (likely a list or a tuple but maybe something more
3306-
# exotic)
3307-
33083299
if (
33093300
# make sure it is not a scalar
33103301
np.iterable(err) and
@@ -3316,14 +3307,17 @@ def _upcast_err(err):
33163307
# fails.
33173308
isinstance(cbook.safe_first_element(err), np.ndarray)
33183309
):
3319-
# grab the type of the first element, we will try to promote
3320-
# the outer container to match the inner container
3310+
# Get the type of the first element
33213311
atype = type(cbook.safe_first_element(err))
3322-
# you can not directly pass data to the init of `np.ndarray`
3312+
# Promote the outer container to match the inner container
33233313
if atype is np.ndarray:
3314+
# Converts using np.asarray, because data cannot
3315+
# be directly passed to init of np.ndarray
33243316
return np.asarray(err, dtype=object)
3325-
# but you can for unyt and astropy uints
3317+
# If atype is not np.ndarray, directly pass data to init.
3318+
# This works for types such as unyts and astropy units
33263319
return atype(err)
3320+
# Otherwise wrap it in an object array
33273321
return np.asarray(err, dtype=object)
33283322

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /