@@ -498,55 +498,6 @@ def maybe_cast_to_extension_array(
498
498
return result
499
499
500
500
501
- def maybe_upcast_putmask (result : np .ndarray , mask : np .ndarray ) -> np .ndarray :
502
- """
503
- A safe version of putmask that potentially upcasts the result.
504
-
505
- The result is replaced with the first N elements of other,
506
- where N is the number of True values in mask.
507
- If the length of other is shorter than N, other will be repeated.
508
-
509
- Parameters
510
- ----------
511
- result : ndarray
512
- The destination array. This will be mutated in-place if no upcasting is
513
- necessary.
514
- mask : np.ndarray[bool]
515
-
516
- Returns
517
- -------
518
- result : ndarray
519
-
520
- Examples
521
- --------
522
- >>> arr = np.arange(1, 6)
523
- >>> mask = np.array([False, True, False, True, True])
524
- >>> result = maybe_upcast_putmask(arr, mask)
525
- >>> result
526
- array([ 1., nan, 3., nan, nan])
527
- """
528
- if not isinstance (result , np .ndarray ):
529
- raise ValueError ("The result input must be a ndarray." )
530
-
531
- # NB: we never get here with result.dtype.kind in ["m", "M"]
532
-
533
- if mask .any ():
534
-
535
- # we want to decide whether place will work
536
- # if we have nans in the False portion of our mask then we need to
537
- # upcast (possibly), otherwise we DON't want to upcast (e.g. if we
538
- # have values, say integers, in the success portion then it's ok to not
539
- # upcast)
540
- new_dtype = ensure_dtype_can_hold_na (result .dtype )
541
-
542
- if new_dtype != result .dtype :
543
- result = result .astype (new_dtype , copy = True )
544
-
545
- np .place (result , mask , np .nan )
546
-
547
- return result
548
-
549
-
550
501
@overload
551
502
def ensure_dtype_can_hold_na (dtype : np .dtype ) -> np .dtype :
552
503
...
0 commit comments