@@ -167,9 +167,12 @@ def trans(x): # noqa
167167 return result
168168
169169
170- def maybe_upcast_putmask (result , mask , other ):
170+ def maybe_upast_putmask (result , mask , other ):
171171 """
172- A safe version of putmask that potentially upcasts the result
172+ A safe version of putmask that potentially upcasts the result.
173+ The result is replaced with the first N elements of other,
174+ where N is the number of True values in mask.
175+ If the length of other is shorter than N, other will be repeated.
173176
174177 Parameters
175178 ----------
@@ -185,8 +188,18 @@ def maybe_upcast_putmask(result, mask, other):
185188 result : ndarray
186189 changed : boolean
187190 Set to true if the result array was upcasted
191+
192+ Examples
193+ --------
194+ >>> result, _ = maybe_upcast_putmask(np.arange(1,6),
195+ np.array([False, True, False, True, True]), np.arange(21,23))
196+ >>> result
197+ array([1, 21, 3, 22, 21])
188198 """
189199
200+ if not isinstance (result , np .ndarray ):
201+ raise ValueError ("The result input must be a ndarray." )
202+
190203 if mask .any ():
191204 # Two conversions for date-like dtypes that can't be done automatically
192205 # in np.place:
@@ -241,7 +254,7 @@ def changeit():
241254 # we have an ndarray and the masking has nans in it
242255 else :
243256
244- if isna (other [ mask ] ).any ():
257+ if isna (other ).any ():
245258 return changeit ()
246259
247260 try :
0 commit comments