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
@@ -1220,7 +1231,9 @@ def maybe_castable(arr: np.ndarray) -> bool:
1220
1231
return arr .dtype .name not in POSSIBLY_CAST_DTYPES
1221
1232
1222
1233
1223
- def maybe_infer_to_datetimelike (value , convert_dates : bool = False ):
1234
+ def maybe_infer_to_datetimelike (
1235
+ value : Union [ArrayLike , Scalar ], convert_dates : bool = False
1236
+ ):
1224
1237
"""
1225
1238
we might have a array (or single object) that is datetime like,
1226
1239
and no dtype is passed don't change the value unless we find a
@@ -1329,7 +1342,7 @@ def try_timedelta(v):
1329
1342
return value
1330
1343
1331
1344
1332
- def maybe_cast_to_datetime (value , dtype , errors : str = "raise" ):
1345
+ def maybe_cast_to_datetime (value , dtype : DtypeObj , errors : str = "raise" ):
1333
1346
"""
1334
1347
try to cast the array/value to a datetimelike dtype, converting float
1335
1348
nan to iNaT
@@ -1522,7 +1535,9 @@ def find_common_type(types: List[DtypeObj]) -> DtypeObj:
1522
1535
return np .find_common_type (types , [])
1523
1536
1524
1537
1525
- def cast_scalar_to_array (shape , value , dtype : Optional [DtypeObj ] = None ) -> np .ndarray :
1538
+ def cast_scalar_to_array (
1539
+ shape : Tuple , value : Scalar , dtype : Optional [DtypeObj ] = None
1540
+ ) -> np .ndarray :
1526
1541
"""
1527
1542
Create np.ndarray of specified shape and dtype, filled with values.
1528
1543
@@ -1550,7 +1565,7 @@ def cast_scalar_to_array(shape, value, dtype: Optional[DtypeObj] = None) -> np.n
1550
1565
1551
1566
1552
1567
def construct_1d_arraylike_from_scalar (
1553
- value , length : int , dtype : DtypeObj
1568
+ value : Scalar , length : int , dtype : DtypeObj
1554
1569
) -> ArrayLike :
1555
1570
"""
1556
1571
create a np.ndarray / pandas type of specified shape and dtype
@@ -1594,7 +1609,7 @@ def construct_1d_arraylike_from_scalar(
1594
1609
return subarr
1595
1610
1596
1611
1597
- def construct_1d_object_array_from_listlike (values ) -> np .ndarray :
1612
+ def construct_1d_object_array_from_listlike (values : Sized ) -> np .ndarray :
1598
1613
"""
1599
1614
Transform any list-like object in a 1-dimensional numpy array of object
1600
1615
dtype.
@@ -1620,7 +1635,7 @@ def construct_1d_object_array_from_listlike(values) -> np.ndarray:
1620
1635
1621
1636
1622
1637
def construct_1d_ndarray_preserving_na (
1623
- values , dtype : Optional [DtypeObj ] = None , copy : bool = False
1638
+ values : Sequence , dtype : Optional [DtypeObj ] = None , copy : bool = False
1624
1639
) -> np .ndarray :
1625
1640
"""
1626
1641
Construct a new ndarray, coercing `values` to `dtype`, preserving NA.
@@ -1654,7 +1669,7 @@ def construct_1d_ndarray_preserving_na(
1654
1669
return subarr
1655
1670
1656
1671
1657
- def maybe_cast_to_integer_array (arr , dtype , copy : bool = False ):
1672
+ def maybe_cast_to_integer_array (arr , dtype : Union [ str , np . dtype ] , copy : bool = False ):
1658
1673
"""
1659
1674
Takes any dtype and returns the casted version, raising for when data is
1660
1675
incompatible with integer/unsigned integer dtypes.
@@ -1724,7 +1739,7 @@ def maybe_cast_to_integer_array(arr, dtype, copy: bool = False):
1724
1739
raise ValueError ("Trying to coerce float values to integers" )
1725
1740
1726
1741
1727
- def convert_scalar_for_putitemlike (scalar , dtype : np .dtype ):
1742
+ def convert_scalar_for_putitemlike (scalar : Scalar , dtype : np .dtype ) -> Scalar :
1728
1743
"""
1729
1744
Convert datetimelike scalar if we are setting into a datetime64
1730
1745
or timedelta64 ndarray.
@@ -1755,7 +1770,7 @@ def convert_scalar_for_putitemlike(scalar, dtype: np.dtype):
1755
1770
return scalar
1756
1771
1757
1772
1758
- def validate_numeric_casting (dtype : np .dtype , value ) :
1773
+ def validate_numeric_casting (dtype : np .dtype , value : Scalar ) -> None :
1759
1774
"""
1760
1775
Check that we can losslessly insert the given value into an array
1761
1776
with the given dtype.
0 commit comments