File tree 1 file changed +24
-2
lines changed
1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -3302,8 +3302,30 @@ def _upcast_err(err):
3302
3302
fallback to casting to an object array.
3303
3303
3304
3304
"""
3305
- if np .iterable (err ) and isinstance (err [0 ], np .ndarray ):
3306
- return type (err [0 ])(err )
3305
+
3306
+ # we are here because we the container is not a numpy array, but it
3307
+ # _is_ iterable (likely a list or a tuple but maybe something more
3308
+ # exotic)
3309
+
3310
+ if (
3311
+ # make sure it is not a scalar
3312
+ np .iterable (err ) and
3313
+ # and it is not empty
3314
+ len (err ) > 0 and
3315
+ # and the first element is an array sub-class use
3316
+ # safe_first_element because getitem is index-first not
3317
+ # location first on pandas objects so err[0] almost always
3318
+ # fails.
3319
+ isinstance (cbook .safe_first_element (err ), np .ndarray )
3320
+ ):
3321
+ # grab the type of the first element, we will try to promote
3322
+ # the outer container to match the inner container
3323
+ atype = type (cbook .safe_first_element (err ))
3324
+ # you can not directly pass data to the init of `np.ndarray`
3325
+ if atype is np .ndarray :
3326
+ return np .asarray (err , dtype = object )
3327
+ # but you can for unyt and astropy uints
3328
+ return atype (err )
3307
3329
return np .asarray (err , dtype = object )
3308
3330
3309
3331
if xerr is not None and not isinstance (xerr , np .ndarray ):
You can’t perform that action at this time.
0 commit comments