@@ -3285,26 +3285,17 @@ def _upcast_err(err):
3285
3285
"""
3286
3286
Safely handle tuple of containers that carry units.
3287
3287
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
-
3292
3288
This function covers the case where the input to the xerr/yerr is a
3293
3289
length 2 tuple of equal length ndarray-subclasses that carry the
3294
3290
unit information in the container.
3295
3291
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
3297
3294
library (and implicitly the broadcasting).
3298
3295
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.
3302
3297
"""
3303
3298
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
-
3308
3299
if (
3309
3300
# make sure it is not a scalar
3310
3301
np .iterable (err ) and
@@ -3316,14 +3307,17 @@ def _upcast_err(err):
3316
3307
# fails.
3317
3308
isinstance (cbook .safe_first_element (err ), np .ndarray )
3318
3309
):
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
3321
3311
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
3323
3313
if atype is np .ndarray :
3314
+ # Converts using np.asarray, because data cannot
3315
+ # be directly passed to init of np.ndarray
3324
3316
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
3326
3319
return atype (err )
3320
+ # Otherwise wrap it in an object array
3327
3321
return np .asarray (err , dtype = object )
3328
3322
3329
3323
if xerr is not None and not isinstance (xerr , np .ndarray ):
0 commit comments