@@ -244,13 +244,13 @@ def maybe_upcast_putmask(result: np.ndarray, mask: np.ndarray, other):
244
244
necessary.
245
245
mask : boolean ndarray
246
246
other : scalar
247
- The source value
247
+ The source value.
248
248
249
249
Returns
250
250
-------
251
251
result : ndarray
252
- changed : boolean
253
- Set to true if the result array was upcasted
252
+ changed : bool
253
+ Set to true if the result array was upcasted.
254
254
255
255
Examples
256
256
--------
@@ -337,6 +337,21 @@ def changeit():
337
337
338
338
339
339
def maybe_promote (dtype , fill_value = np .nan ):
340
+ """
341
+ Find the minimal dtype that can hold both the given dtype and fill_value.
342
+
343
+ Parameters
344
+ ----------
345
+ dtype : np.dtype or ExtensionDtype
346
+ fill_value : scalar, default np.nan
347
+
348
+ Returns
349
+ -------
350
+ dtype
351
+ Upcasted from dtype argument if necessary.
352
+ fill_value
353
+ Upcasted from fill_value argument if necessary.
354
+ """
340
355
if not is_scalar (fill_value ) and not is_object_dtype (dtype ):
341
356
# with object dtype there is nothing to promote, and the user can
342
357
# pass pretty much any weird fill_value they like
@@ -592,11 +607,11 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False):
592
607
593
608
def infer_dtype_from_array (arr , pandas_dtype : bool = False ):
594
609
"""
595
- Infer the dtype from a scalar or array.
610
+ Infer the dtype from an array.
596
611
597
612
Parameters
598
613
----------
599
- arr : scalar or array
614
+ arr : array
600
615
pandas_dtype : bool, default False
601
616
whether to infer dtype including pandas extension types.
602
617
If False, array belongs to pandas extension types
@@ -622,7 +637,6 @@ def infer_dtype_from_array(arr, pandas_dtype: bool = False):
622
637
623
638
>>> infer_dtype_from_array([1, '1'])
624
639
(numpy.object_, [1, '1'])
625
-
626
640
"""
627
641
628
642
if isinstance (arr , np .ndarray ):
@@ -686,10 +700,12 @@ def maybe_upcast(values, fill_value=np.nan, dtype=None, copy: bool = False):
686
700
687
701
Parameters
688
702
----------
689
- values : the ndarray that we want to maybe upcast
703
+ values : ndarray or ExtensionArray
704
+ The array that we want to maybe upcast.
690
705
fill_value : what we want to fill with
691
706
dtype : if None, then use the dtype of the values, else coerce to this type
692
- copy : if True always make a copy even if no upcast is required
707
+ copy : bool, default True
708
+ If True always make a copy even if no upcast is required.
693
709
"""
694
710
if not is_scalar (fill_value ) and not is_object_dtype (values .dtype ):
695
711
# We allow arbitrary fill values for object dtype
0 commit comments