22
22
TYPE_CHECKING ,
23
23
Any ,
24
24
AnyStr ,
25
+ Callable ,
25
26
Dict ,
26
27
FrozenSet ,
27
28
Hashable ,
71
72
NpDtype ,
72
73
PythonFuncType ,
73
74
Renamer ,
75
+ Scalar ,
74
76
StorageOptions ,
75
77
Suffixes ,
76
78
ValueKeyFunc ,
@@ -1215,7 +1217,9 @@ def iterrows(self) -> Iterable[Tuple[Hashable, Series]]:
1215
1217
s = klass (v , index = columns , name = k )
1216
1218
yield k , s
1217
1219
1218
- def itertuples (self , index : bool = True , name : Optional [str ] = "Pandas" ):
1220
+ def itertuples (
1221
+ self , index : bool = True , name : Optional [str ] = "Pandas"
1222
+ ) -> Iterable [Tuple [Any , ...]]:
1219
1223
"""
1220
1224
Iterate over DataFrame rows as namedtuples.
1221
1225
@@ -1459,7 +1463,11 @@ def __rmatmul__(self, other):
1459
1463
1460
1464
@classmethod
1461
1465
def from_dict (
1462
- cls , data , orient = "columns" , dtype : Optional [Dtype ] = None , columns = None
1466
+ cls ,
1467
+ data ,
1468
+ orient : str = "columns" ,
1469
+ dtype : Optional [Dtype ] = None ,
1470
+ columns = None ,
1463
1471
) -> DataFrame :
1464
1472
"""
1465
1473
Construct DataFrame from dict of array-like or dicts.
@@ -1897,7 +1905,7 @@ def from_records(
1897
1905
exclude = None ,
1898
1906
columns = None ,
1899
1907
coerce_float : bool = False ,
1900
- nrows = None ,
1908
+ nrows : Optional [ int ] = None ,
1901
1909
) -> DataFrame :
1902
1910
"""
1903
1911
Convert structured or record ndarray to DataFrame.
@@ -3087,7 +3095,7 @@ def info(
3087
3095
show_counts = show_counts ,
3088
3096
)
3089
3097
3090
- def memory_usage (self , index = True , deep = False ) -> Series :
3098
+ def memory_usage (self , index : bool = True , deep : bool = False ) -> Series :
3091
3099
"""
3092
3100
Return the memory usage of each column in bytes.
3093
3101
@@ -3489,7 +3497,7 @@ def _getitem_multilevel(self, key):
3489
3497
# loc is neither a slice nor ndarray, so must be an int
3490
3498
return self ._ixs (loc , axis = 1 )
3491
3499
3492
- def _get_value (self , index , col , takeable : bool = False ):
3500
+ def _get_value (self , index , col , takeable : bool = False ) -> Scalar :
3493
3501
"""
3494
3502
Quickly retrieve single value at passed column and index.
3495
3503
@@ -3657,7 +3665,7 @@ def _iset_item(self, loc: int, value):
3657
3665
if len (self ):
3658
3666
self ._check_setitem_copy ()
3659
3667
3660
- def _set_item (self , key , value ):
3668
+ def _set_item (self , key , value ) -> None :
3661
3669
"""
3662
3670
Add series to DataFrame in specified column.
3663
3671
@@ -3682,16 +3690,21 @@ def _set_item(self, key, value):
3682
3690
3683
3691
self ._set_item_mgr (key , value )
3684
3692
3685
- def _set_value (self , index , col , value , takeable : bool = False ):
3693
+ def _set_value (
3694
+ self , index : IndexLabel , col , value : Scalar , takeable : bool = False
3695
+ ) -> None :
3686
3696
"""
3687
3697
Put single value at passed column and index.
3688
3698
3689
3699
Parameters
3690
3700
----------
3691
- index : row label
3692
- col : column label
3701
+ index : Label
3702
+ row label
3703
+ col : Label
3704
+ column label
3693
3705
value : scalar
3694
- takeable : interpret the index/col as indexers, default False
3706
+ takeable : bool, default False
3707
+ Sets whether or not index/col interpreted as indexers
3695
3708
"""
3696
3709
try :
3697
3710
if takeable :
@@ -3715,7 +3728,7 @@ def _set_value(self, index, col, value, takeable: bool = False):
3715
3728
self .loc [index , col ] = value
3716
3729
self ._item_cache .pop (col , None )
3717
3730
3718
- def _ensure_valid_index (self , value ):
3731
+ def _ensure_valid_index (self , value ) -> None :
3719
3732
"""
3720
3733
Ensure that if we don't have an index, that we can create one from the
3721
3734
passed value.
@@ -3912,6 +3925,7 @@ def query(self, expr: str, inplace: bool = False, **kwargs):
3912
3925
3913
3926
if inplace :
3914
3927
self ._update_inplace (result )
3928
+ return None
3915
3929
else :
3916
3930
return result
3917
3931
@@ -4379,7 +4393,9 @@ def _series(self):
4379
4393
for idx , item in enumerate (self .columns )
4380
4394
}
4381
4395
4382
- def lookup (self , row_labels , col_labels ) -> np .ndarray :
4396
+ def lookup (
4397
+ self , row_labels : Sequence [IndexLabel ], col_labels : Sequence [IndexLabel ]
4398
+ ) -> np .ndarray :
4383
4399
"""
4384
4400
Label-based "fancy indexing" function for DataFrame.
4385
4401
Given equal-length arrays of row and column labels, return an
@@ -6574,7 +6590,7 @@ def _arith_method(self, other, op):
6574
6590
6575
6591
_logical_method = _arith_method
6576
6592
6577
- def _dispatch_frame_op (self , right , func , axis : Optional [int ] = None ):
6593
+ def _dispatch_frame_op (self , right , func : Callable , axis : Optional [int ] = None ):
6578
6594
"""
6579
6595
Evaluate the frame operation func(left, right) by evaluating
6580
6596
column-by-column, dispatching to the Series implementation.
@@ -7910,7 +7926,7 @@ def explode(
7910
7926
7911
7927
return result
7912
7928
7913
- def unstack (self , level = - 1 , fill_value = None ):
7929
+ def unstack (self , level : Level = - 1 , fill_value = None ):
7914
7930
"""
7915
7931
Pivot a level of the (necessarily hierarchical) index labels.
7916
7932
@@ -7981,7 +7997,7 @@ def melt(
7981
7997
var_name = None ,
7982
7998
value_name = "value" ,
7983
7999
col_level : Optional [Level ] = None ,
7984
- ignore_index = True ,
8000
+ ignore_index : bool = True ,
7985
8001
) -> DataFrame :
7986
8002
7987
8003
return melt (
@@ -8846,7 +8862,9 @@ def merge(
8846
8862
validate = validate ,
8847
8863
)
8848
8864
8849
- def round (self , decimals = 0 , * args , ** kwargs ) -> DataFrame :
8865
+ def round (
8866
+ self , decimals : Union [int , Dict [IndexLabel , int ], Series ] = 0 , * args , ** kwargs
8867
+ ) -> DataFrame :
8850
8868
"""
8851
8869
Round a DataFrame to a variable number of decimal places.
8852
8870
@@ -8960,7 +8978,11 @@ def _series_round(s, decimals):
8960
8978
# ----------------------------------------------------------------------
8961
8979
# Statistical methods, etc.
8962
8980
8963
- def corr (self , method = "pearson" , min_periods = 1 ) -> DataFrame :
8981
+ def corr (
8982
+ self ,
8983
+ method : Union [str , Callable [[np .ndarray , np .ndarray ], float ]] = "pearson" ,
8984
+ min_periods : int = 1 ,
8985
+ ) -> DataFrame :
8964
8986
"""
8965
8987
Compute pairwise correlation of columns, excluding NA/null values.
8966
8988
0 commit comments