Skip to content

Commit 9c31717

Browse files
authored
TYP: pandas/core/frame.py (#38416)
1 parent f111175 commit 9c31717

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

pandas/core/frame.py

+39-17
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
TYPE_CHECKING,
2323
Any,
2424
AnyStr,
25+
Callable,
2526
Dict,
2627
FrozenSet,
2728
Hashable,
@@ -71,6 +72,7 @@
7172
NpDtype,
7273
PythonFuncType,
7374
Renamer,
75+
Scalar,
7476
StorageOptions,
7577
Suffixes,
7678
ValueKeyFunc,
@@ -1215,7 +1217,9 @@ def iterrows(self) -> Iterable[Tuple[Hashable, Series]]:
12151217
s = klass(v, index=columns, name=k)
12161218
yield k, s
12171219

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, ...]]:
12191223
"""
12201224
Iterate over DataFrame rows as namedtuples.
12211225
@@ -1459,7 +1463,11 @@ def __rmatmul__(self, other):
14591463

14601464
@classmethod
14611465
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,
14631471
) -> DataFrame:
14641472
"""
14651473
Construct DataFrame from dict of array-like or dicts.
@@ -1897,7 +1905,7 @@ def from_records(
18971905
exclude=None,
18981906
columns=None,
18991907
coerce_float: bool = False,
1900-
nrows=None,
1908+
nrows: Optional[int] = None,
19011909
) -> DataFrame:
19021910
"""
19031911
Convert structured or record ndarray to DataFrame.
@@ -3087,7 +3095,7 @@ def info(
30873095
show_counts=show_counts,
30883096
)
30893097

3090-
def memory_usage(self, index=True, deep=False) -> Series:
3098+
def memory_usage(self, index: bool = True, deep: bool = False) -> Series:
30913099
"""
30923100
Return the memory usage of each column in bytes.
30933101
@@ -3489,7 +3497,7 @@ def _getitem_multilevel(self, key):
34893497
# loc is neither a slice nor ndarray, so must be an int
34903498
return self._ixs(loc, axis=1)
34913499

3492-
def _get_value(self, index, col, takeable: bool = False):
3500+
def _get_value(self, index, col, takeable: bool = False) -> Scalar:
34933501
"""
34943502
Quickly retrieve single value at passed column and index.
34953503
@@ -3657,7 +3665,7 @@ def _iset_item(self, loc: int, value):
36573665
if len(self):
36583666
self._check_setitem_copy()
36593667

3660-
def _set_item(self, key, value):
3668+
def _set_item(self, key, value) -> None:
36613669
"""
36623670
Add series to DataFrame in specified column.
36633671
@@ -3682,16 +3690,21 @@ def _set_item(self, key, value):
36823690

36833691
self._set_item_mgr(key, value)
36843692

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:
36863696
"""
36873697
Put single value at passed column and index.
36883698
36893699
Parameters
36903700
----------
3691-
index : row label
3692-
col : column label
3701+
index : Label
3702+
row label
3703+
col : Label
3704+
column label
36933705
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
36953708
"""
36963709
try:
36973710
if takeable:
@@ -3715,7 +3728,7 @@ def _set_value(self, index, col, value, takeable: bool = False):
37153728
self.loc[index, col] = value
37163729
self._item_cache.pop(col, None)
37173730

3718-
def _ensure_valid_index(self, value):
3731+
def _ensure_valid_index(self, value) -> None:
37193732
"""
37203733
Ensure that if we don't have an index, that we can create one from the
37213734
passed value.
@@ -3912,6 +3925,7 @@ def query(self, expr: str, inplace: bool = False, **kwargs):
39123925

39133926
if inplace:
39143927
self._update_inplace(result)
3928+
return None
39153929
else:
39163930
return result
39173931

@@ -4379,7 +4393,9 @@ def _series(self):
43794393
for idx, item in enumerate(self.columns)
43804394
}
43814395

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:
43834399
"""
43844400
Label-based "fancy indexing" function for DataFrame.
43854401
Given equal-length arrays of row and column labels, return an
@@ -6574,7 +6590,7 @@ def _arith_method(self, other, op):
65746590

65756591
_logical_method = _arith_method
65766592

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):
65786594
"""
65796595
Evaluate the frame operation func(left, right) by evaluating
65806596
column-by-column, dispatching to the Series implementation.
@@ -7910,7 +7926,7 @@ def explode(
79107926

79117927
return result
79127928

7913-
def unstack(self, level=-1, fill_value=None):
7929+
def unstack(self, level: Level = -1, fill_value=None):
79147930
"""
79157931
Pivot a level of the (necessarily hierarchical) index labels.
79167932
@@ -7981,7 +7997,7 @@ def melt(
79817997
var_name=None,
79827998
value_name="value",
79837999
col_level: Optional[Level] = None,
7984-
ignore_index=True,
8000+
ignore_index: bool = True,
79858001
) -> DataFrame:
79868002

79878003
return melt(
@@ -8846,7 +8862,9 @@ def merge(
88468862
validate=validate,
88478863
)
88488864

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:
88508868
"""
88518869
Round a DataFrame to a variable number of decimal places.
88528870
@@ -8960,7 +8978,11 @@ def _series_round(s, decimals):
89608978
# ----------------------------------------------------------------------
89618979
# Statistical methods, etc.
89628980

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:
89648986
"""
89658987
Compute pairwise correlation of columns, excluding NA/null values.
89668988

0 commit comments

Comments
 (0)