@@ -3332,26 +3332,17 @@ def _upcast_err(err):
3332
3332
"""
3333
3333
Safely handle tuple of containers that carry units.
3334
3334
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
-
3339
3335
This function covers the case where the input to the xerr/yerr is a
3340
3336
length 2 tuple of equal length ndarray-subclasses that carry the
3341
3337
unit information in the container.
3342
3338
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
3344
3341
library (and implicitly the broadcasting).
3345
3342
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.
3349
3344
"""
3350
3345
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
-
3355
3346
if (
3356
3347
# make sure it is not a scalar
3357
3348
np .iterable (err ) and
@@ -3363,14 +3354,17 @@ def _upcast_err(err):
3363
3354
# fails.
3364
3355
isinstance (cbook .safe_first_element (err ), np .ndarray )
3365
3356
):
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
3368
3358
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
3370
3360
if atype is np .ndarray :
3361
+ # Converts using np.asarray, because data cannot
3362
+ # be directly passed to init of np.ndarray
3371
3363
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
3373
3366
return atype (err )
3367
+ # Otherwise wrap it in an object array
3374
3368
return np .asarray (err , dtype = object )
3375
3369
3376
3370
if xerr is not None and not isinstance (xerr , np .ndarray ):
0 commit comments