@@ -167,9 +167,12 @@ def trans(x): # noqa
167
167
return result
168
168
169
169
170
- def maybe_upcast_putmask (result , mask , other ):
170
+ def maybe_upast_putmask (result , mask , other ):
171
171
"""
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.
173
176
174
177
Parameters
175
178
----------
@@ -185,8 +188,18 @@ def maybe_upcast_putmask(result, mask, other):
185
188
result : ndarray
186
189
changed : boolean
187
190
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])
188
198
"""
189
199
200
+ if not isinstance (result , np .ndarray ):
201
+ raise ValueError ("The result input must be a ndarray." )
202
+
190
203
if mask .any ():
191
204
# Two conversions for date-like dtypes that can't be done automatically
192
205
# in np.place:
@@ -241,7 +254,7 @@ def changeit():
241
254
# we have an ndarray and the masking has nans in it
242
255
else :
243
256
244
- if isna (other [ mask ] ).any ():
257
+ if isna (other ).any ():
245
258
return changeit ()
246
259
247
260
try :
0 commit comments