3
3
"""
4
4
5
5
from datetime import date , datetime , timedelta
6
- from typing import TYPE_CHECKING , Any , List , Optional , Sequence , Set , Tuple , Type , Union
6
+ from typing import (
7
+ TYPE_CHECKING ,
8
+ Any ,
9
+ List ,
10
+ Optional ,
11
+ Sequence ,
12
+ Set ,
13
+ Sized ,
14
+ Tuple ,
15
+ Type ,
16
+ Union ,
17
+ )
7
18
8
19
import numpy as np
9
20
@@ -1287,7 +1298,9 @@ def maybe_castable(arr: np.ndarray) -> bool:
1287
1298
return arr .dtype .name not in POSSIBLY_CAST_DTYPES
1288
1299
1289
1300
1290
- def maybe_infer_to_datetimelike (value , convert_dates : bool = False ):
1301
+ def maybe_infer_to_datetimelike (
1302
+ value : Union [ArrayLike , Scalar ], convert_dates : bool = False
1303
+ ):
1291
1304
"""
1292
1305
we might have a array (or single object) that is datetime like,
1293
1306
and no dtype is passed don't change the value unless we find a
@@ -1396,7 +1409,7 @@ def try_timedelta(v):
1396
1409
return value
1397
1410
1398
1411
1399
- def maybe_cast_to_datetime (value , dtype , errors : str = "raise" ):
1412
+ def maybe_cast_to_datetime (value , dtype : DtypeObj , errors : str = "raise" ):
1400
1413
"""
1401
1414
try to cast the array/value to a datetimelike dtype, converting float
1402
1415
nan to iNaT
@@ -1589,7 +1602,9 @@ def find_common_type(types: List[DtypeObj]) -> DtypeObj:
1589
1602
return np .find_common_type (types , [])
1590
1603
1591
1604
1592
- def cast_scalar_to_array (shape , value , dtype : Optional [DtypeObj ] = None ) -> np .ndarray :
1605
+ def cast_scalar_to_array (
1606
+ shape : Tuple , value : Scalar , dtype : Optional [DtypeObj ] = None
1607
+ ) -> np .ndarray :
1593
1608
"""
1594
1609
Create np.ndarray of specified shape and dtype, filled with values.
1595
1610
@@ -1617,7 +1632,7 @@ def cast_scalar_to_array(shape, value, dtype: Optional[DtypeObj] = None) -> np.n
1617
1632
1618
1633
1619
1634
def construct_1d_arraylike_from_scalar (
1620
- value , length : int , dtype : DtypeObj
1635
+ value : Scalar , length : int , dtype : DtypeObj
1621
1636
) -> ArrayLike :
1622
1637
"""
1623
1638
create a np.ndarray / pandas type of specified shape and dtype
@@ -1661,7 +1676,7 @@ def construct_1d_arraylike_from_scalar(
1661
1676
return subarr
1662
1677
1663
1678
1664
- def construct_1d_object_array_from_listlike (values ) -> np .ndarray :
1679
+ def construct_1d_object_array_from_listlike (values : Sized ) -> np .ndarray :
1665
1680
"""
1666
1681
Transform any list-like object in a 1-dimensional numpy array of object
1667
1682
dtype.
@@ -1687,7 +1702,7 @@ def construct_1d_object_array_from_listlike(values) -> np.ndarray:
1687
1702
1688
1703
1689
1704
def construct_1d_ndarray_preserving_na (
1690
- values , dtype : Optional [DtypeObj ] = None , copy : bool = False
1705
+ values : Sequence , dtype : Optional [DtypeObj ] = None , copy : bool = False
1691
1706
) -> np .ndarray :
1692
1707
"""
1693
1708
Construct a new ndarray, coercing `values` to `dtype`, preserving NA.
@@ -1721,7 +1736,7 @@ def construct_1d_ndarray_preserving_na(
1721
1736
return subarr
1722
1737
1723
1738
1724
- def maybe_cast_to_integer_array (arr , dtype , copy : bool = False ):
1739
+ def maybe_cast_to_integer_array (arr , dtype : Union [ str , np . dtype ] , copy : bool = False ):
1725
1740
"""
1726
1741
Takes any dtype and returns the casted version, raising for when data is
1727
1742
incompatible with integer/unsigned integer dtypes.
@@ -1791,7 +1806,7 @@ def maybe_cast_to_integer_array(arr, dtype, copy: bool = False):
1791
1806
raise ValueError ("Trying to coerce float values to integers" )
1792
1807
1793
1808
1794
- def convert_scalar_for_putitemlike (scalar , dtype : np .dtype ):
1809
+ def convert_scalar_for_putitemlike (scalar : Scalar , dtype : np .dtype ) -> Scalar :
1795
1810
"""
1796
1811
Convert datetimelike scalar if we are setting into a datetime64
1797
1812
or timedelta64 ndarray.
@@ -1822,7 +1837,7 @@ def convert_scalar_for_putitemlike(scalar, dtype: np.dtype):
1822
1837
return scalar
1823
1838
1824
1839
1825
- def validate_numeric_casting (dtype : np .dtype , value ) :
1840
+ def validate_numeric_casting (dtype : np .dtype , value : Scalar ) -> None :
1826
1841
"""
1827
1842
Check that we can losslessly insert the given value into an array
1828
1843
with the given dtype.
0 commit comments