Skip to content

TYP: pandas/core/frame.py #38416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
Mar 15, 2021
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
46bf318
typing
arw2019 Dec 9, 2020
eba7251
typing
arw2019 Dec 11, 2020
1a45267
typing
arw2019 Dec 11, 2020
f5cb185
typing
arw2019 Dec 11, 2020
4c9b764
review comments
arw2019 Dec 11, 2020
a273e5c
review comment
arw2019 Dec 13, 2020
e0558c5
review comment
arw2019 Dec 13, 2020
e156caa
merge master
arw2019 Dec 14, 2020
13ff245
merge master
arw2019 Dec 14, 2020
617e228
revert hints to pivot_table
arw2019 Dec 14, 2020
9a4d187
take out merge
arw2019 Dec 14, 2020
77e1142
minimize diff
arw2019 Dec 14, 2020
2352e45
fix eval return type annotation
arw2019 Dec 14, 2020
a3b7b1b
merge master
arw2019 Dec 14, 2020
1c942fd
review comments
arw2019 Dec 15, 2020
0e747dd
Merge branch 'master' of https://github.com/pandas-dev/pandas into ty…
arw2019 Dec 15, 2020
11247d9
review comments
arw2019 Dec 21, 2020
d82d81e
merge master
arw2019 Dec 21, 2020
56ee7c4
Merge branch 'master' of https://github.com/pandas-dev/pandas into ty…
arw2019 Dec 27, 2020
168cad2
review comments
arw2019 Jan 5, 2021
e12ed2e
Merge branch 'master' of https://github.com/pandas-dev/pandas into ty…
arw2019 Jan 5, 2021
6c876ff
review comments
arw2019 Jan 5, 2021
0e780ce
review comments
arw2019 Jan 5, 2021
a93489a
review: remove NpDtype usage
arw2019 Jan 6, 2021
2cd6823
merge master
arw2019 Jan 6, 2021
3e39e44
Merge branch 'master' of https://github.com/pandas-dev/pandas into ty…
arw2019 Jan 10, 2021
a28deaf
merge master
arw2019 Feb 11, 2021
9243c6b
merge master
arw2019 Feb 21, 2021
58fcad8
typing
arw2019 Feb 21, 2021
ff317d3
restore return type for memory_usage
arw2019 Feb 22, 2021
02647b5
remove return type for _series
arw2019 Feb 22, 2021
cc517a5
rogue comma
arw2019 Feb 22, 2021
666533c
Merge branch 'master' of https://github.com/pandas-dev/pandas into ty…
arw2019 Feb 22, 2021
5d08d71
Merge remote-tracking branch 'upstream/master' into typing-frame
simonjayhawkins Mar 14, 2021
3b52fc9
Merge remote-tracking branch 'upstream/master' into typing-frame
simonjayhawkins Mar 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 39 additions & 17 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
TYPE_CHECKING,
Any,
AnyStr,
Callable,
Dict,
FrozenSet,
Hashable,
Expand Down Expand Up @@ -71,6 +72,7 @@
NpDtype,
PythonFuncType,
Renamer,
Scalar,
StorageOptions,
Suffixes,
ValueKeyFunc,
Expand Down Expand Up @@ -1215,7 +1217,9 @@ def iterrows(self) -> Iterable[Tuple[Hashable, Series]]:
s = klass(v, index=columns, name=k)
yield k, s

def itertuples(self, index: bool = True, name: Optional[str] = "Pandas"):
def itertuples(
self, index: bool = True, name: Optional[str] = "Pandas"
) -> Iterable[Tuple[Any, ...]]:
"""
Iterate over DataFrame rows as namedtuples.

Expand Down Expand Up @@ -1459,7 +1463,11 @@ def __rmatmul__(self, other):

@classmethod
def from_dict(
cls, data, orient="columns", dtype: Optional[Dtype] = None, columns=None
cls,
data,
orient: str = "columns",
dtype: Optional[Dtype] = None,
columns=None,
) -> DataFrame:
"""
Construct DataFrame from dict of array-like or dicts.
Expand Down Expand Up @@ -1897,7 +1905,7 @@ def from_records(
exclude=None,
columns=None,
coerce_float: bool = False,
nrows=None,
nrows: Optional[int] = None,
) -> DataFrame:
"""
Convert structured or record ndarray to DataFrame.
Expand Down Expand Up @@ -3087,7 +3095,7 @@ def info(
show_counts=show_counts,
)

def memory_usage(self, index=True, deep=False) -> Series:
def memory_usage(self, index: bool = True, deep: bool = False) -> Series:
"""
Return the memory usage of each column in bytes.

Expand Down Expand Up @@ -3489,7 +3497,7 @@ def _getitem_multilevel(self, key):
# loc is neither a slice nor ndarray, so must be an int
return self._ixs(loc, axis=1)

def _get_value(self, index, col, takeable: bool = False):
def _get_value(self, index, col, takeable: bool = False) -> Scalar:
"""
Quickly retrieve single value at passed column and index.

Expand Down Expand Up @@ -3657,7 +3665,7 @@ def _iset_item(self, loc: int, value):
if len(self):
self._check_setitem_copy()

def _set_item(self, key, value):
def _set_item(self, key, value) -> None:
"""
Add series to DataFrame in specified column.

Expand All @@ -3682,16 +3690,21 @@ def _set_item(self, key, value):

self._set_item_mgr(key, value)

def _set_value(self, index, col, value, takeable: bool = False):
def _set_value(
self, index: IndexLabel, col, value: Scalar, takeable: bool = False
) -> None:
"""
Put single value at passed column and index.

Parameters
----------
index : row label
col : column label
index : Label
row label
col : Label
column label
value : scalar
takeable : interpret the index/col as indexers, default False
takeable : bool, default False
Sets whether or not index/col interpreted as indexers
"""
try:
if takeable:
Expand All @@ -3715,7 +3728,7 @@ def _set_value(self, index, col, value, takeable: bool = False):
self.loc[index, col] = value
self._item_cache.pop(col, None)

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

if inplace:
self._update_inplace(result)
return None
else:
return result

Expand Down Expand Up @@ -4379,7 +4393,9 @@ def _series(self):
for idx, item in enumerate(self.columns)
}

def lookup(self, row_labels, col_labels) -> np.ndarray:
def lookup(
self, row_labels: Sequence[IndexLabel], col_labels: Sequence[IndexLabel]
) -> np.ndarray:
"""
Label-based "fancy indexing" function for DataFrame.
Given equal-length arrays of row and column labels, return an
Expand Down Expand Up @@ -6574,7 +6590,7 @@ def _arith_method(self, other, op):

_logical_method = _arith_method

def _dispatch_frame_op(self, right, func, axis: Optional[int] = None):
def _dispatch_frame_op(self, right, func: Callable, axis: Optional[int] = None):
"""
Evaluate the frame operation func(left, right) by evaluating
column-by-column, dispatching to the Series implementation.
Expand Down Expand Up @@ -7910,7 +7926,7 @@ def explode(

return result

def unstack(self, level=-1, fill_value=None):
def unstack(self, level: Level = -1, fill_value=None):
"""
Pivot a level of the (necessarily hierarchical) index labels.

Expand Down Expand Up @@ -7981,7 +7997,7 @@ def melt(
var_name=None,
value_name="value",
col_level: Optional[Level] = None,
ignore_index=True,
ignore_index: bool = True,
) -> DataFrame:

return melt(
Expand Down Expand Up @@ -8846,7 +8862,9 @@ def merge(
validate=validate,
)

def round(self, decimals=0, *args, **kwargs) -> DataFrame:
def round(
self, decimals: Union[int, Dict[IndexLabel, int], Series] = 0, *args, **kwargs
) -> DataFrame:
"""
Round a DataFrame to a variable number of decimal places.

Expand Down Expand Up @@ -8960,7 +8978,11 @@ def _series_round(s, decimals):
# ----------------------------------------------------------------------
# Statistical methods, etc.

def corr(self, method="pearson", min_periods=1) -> DataFrame:
def corr(
self,
method: Union[str, Callable[[np.ndarray, np.ndarray], float]] = "pearson",
min_periods: int = 1,
) -> DataFrame:
"""
Compute pairwise correlation of columns, excluding NA/null values.

Expand Down