1
- """ routings for casting """
1
+ """
2
+ Routines for casting.
3
+ """
2
4
3
5
from datetime import date , datetime , timedelta
4
6
@@ -269,12 +271,12 @@ def maybe_upcast_putmask(result: np.ndarray, mask: np.ndarray, other):
269
271
270
272
Examples
271
273
--------
272
- >>> result, _ = maybe_upcast_putmask(np.arange(1,6),
273
- np.array([False, True, False, True, True]), np.arange(21,23))
274
+ >>> arr = np.arange(1, 6)
275
+ >>> mask = np.array([False, True, False, True, True])
276
+ >>> result, _ = maybe_upcast_putmask(arr, mask, False)
274
277
>>> result
275
- array([1, 21 , 3, 22, 21 ])
278
+ array([1, 0 , 3, 0, 0 ])
276
279
"""
277
-
278
280
if not isinstance (result , np .ndarray ):
279
281
raise ValueError ("The result input must be a ndarray." )
280
282
if not is_scalar (other ):
@@ -662,9 +664,8 @@ def infer_dtype_from_array(arr, pandas_dtype: bool = False):
662
664
array(['1', '1'], dtype='<U21')
663
665
664
666
>>> infer_dtype_from_array([1, '1'])
665
- (numpy.object_, [1, '1'])
667
+ (<class ' numpy.object_'> , [1, '1'])
666
668
"""
667
-
668
669
if isinstance (arr , np .ndarray ):
669
670
return arr .dtype , arr
670
671
@@ -709,7 +710,7 @@ def maybe_infer_dtype_type(element):
709
710
>>> from collections import namedtuple
710
711
>>> Foo = namedtuple("Foo", "dtype")
711
712
>>> maybe_infer_dtype_type(Foo(np.dtype("i8")))
712
- numpy. int64
713
+ dtype(' int64')
713
714
"""
714
715
tipo = None
715
716
if hasattr (element , "dtype" ):
@@ -1555,8 +1556,8 @@ def maybe_cast_to_integer_array(arr, dtype, copy: bool = False):
1555
1556
1556
1557
Returns
1557
1558
-------
1558
- int_arr : ndarray
1559
- An array of integer or unsigned integer dtype
1559
+ ndarray
1560
+ Array of integer or unsigned integer dtype.
1560
1561
1561
1562
Raises
1562
1563
------
@@ -1567,19 +1568,18 @@ def maybe_cast_to_integer_array(arr, dtype, copy: bool = False):
1567
1568
--------
1568
1569
If you try to coerce negative values to unsigned integers, it raises:
1569
1570
1570
- >>> Series([-1], dtype="uint64")
1571
+ >>> pd. Series([-1], dtype="uint64")
1571
1572
Traceback (most recent call last):
1572
1573
...
1573
1574
OverflowError: Trying to coerce negative values to unsigned integers
1574
1575
1575
1576
Also, if you try to coerce float values to integers, it raises:
1576
1577
1577
- >>> Series([1, 2, 3.5], dtype="int64")
1578
+ >>> pd. Series([1, 2, 3.5], dtype="int64")
1578
1579
Traceback (most recent call last):
1579
1580
...
1580
1581
ValueError: Trying to coerce float values to integers
1581
1582
"""
1582
-
1583
1583
try :
1584
1584
if not hasattr (arr , "astype" ):
1585
1585
casted = np .array (arr , dtype = dtype , copy = copy )
0 commit comments