Skip to content

TYP: pandas/core/frame.py (easy: bool/str) #38440

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 1 commit into from
Dec 13, 2020
Merged
Changes from all commits
Commits
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
124 changes: 75 additions & 49 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ def to_numpy(

return result

def to_dict(self, orient="dict", into=dict):
def to_dict(self, orient: str = "dict", into=dict):
"""
Convert the DataFrame to a dictionary.

Expand Down Expand Up @@ -1615,15 +1615,15 @@ def to_dict(self, orient="dict", into=dict):

def to_gbq(
self,
destination_table,
project_id=None,
destination_table: str,
project_id: Optional[str] = None,
chunksize=None,
reauth=False,
if_exists="fail",
auth_local_webserver=False,
reauth: bool = False,
if_exists: str = "fail",
auth_local_webserver: bool = False,
table_schema=None,
location=None,
progress_bar=True,
location: Optional[str] = None,
progress_bar: bool = True,
credentials=None,
) -> None:
"""
Expand Down Expand Up @@ -1728,7 +1728,7 @@ def from_records(
index=None,
exclude=None,
columns=None,
coerce_float=False,
coerce_float: bool = False,
nrows=None,
) -> DataFrame:
"""
Expand Down Expand Up @@ -2489,7 +2489,7 @@ def to_html(
max_rows=None,
max_cols=None,
show_dimensions=False,
decimal=".",
decimal: str = ".",
bold_rows=True,
classes=None,
escape=True,
Expand Down Expand Up @@ -3311,7 +3311,7 @@ def _box_col_values(self, values, loc: int) -> Series:
# ----------------------------------------------------------------------
# Unsorted

def query(self, expr, inplace=False, **kwargs):
def query(self, expr: str, inplace: bool = False, **kwargs):
"""
Query the columns of a DataFrame with a boolean expression.

Expand Down Expand Up @@ -3475,7 +3475,7 @@ def query(self, expr, inplace=False, **kwargs):
else:
return result

def eval(self, expr, inplace=False, **kwargs):
def eval(self, expr: str, inplace: bool = False, **kwargs):
"""
Evaluate a string describing operations on DataFrame columns.

Expand Down Expand Up @@ -3732,7 +3732,7 @@ def extract_unique_dtypes_from_dtypes_set(

return self.iloc[:, keep_these.values]

def insert(self, loc, column, value, allow_duplicates=False) -> None:
def insert(self, loc, column, value, allow_duplicates: bool = False) -> None:
"""
Insert column into DataFrame at specified location.

Expand Down Expand Up @@ -3846,7 +3846,7 @@ def assign(self, **kwargs) -> DataFrame:
data[k] = com.apply_if_callable(v, data)
return data

def _sanitize_column(self, key, value, broadcast=True):
def _sanitize_column(self, key, value, broadcast: bool = True):
"""
Ensures new columns (which go into the BlockManager as new blocks) are
always copied and converted into an array.
Expand Down Expand Up @@ -4046,7 +4046,7 @@ def _reindex_index(
self,
new_index,
method,
copy,
copy: bool,
level,
fill_value=np.nan,
limit=None,
Expand All @@ -4066,7 +4066,7 @@ def _reindex_columns(
self,
new_columns,
method,
copy,
copy: bool,
level,
fill_value=None,
limit=None,
Expand All @@ -4082,7 +4082,7 @@ def _reindex_columns(
allow_dups=False,
)

def _reindex_multi(self, axes, copy, fill_value) -> DataFrame:
def _reindex_multi(self, axes, copy: bool, fill_value) -> DataFrame:
"""
We are guaranteed non-Nones in the axes.
"""
Expand All @@ -4106,12 +4106,12 @@ def _reindex_multi(self, axes, copy, fill_value) -> DataFrame:
def align(
self,
other,
join="outer",
join: str = "outer",
axis=None,
level=None,
copy=True,
copy: bool = True,
fill_value=None,
method=None,
method: Optional[str] = None,
limit=None,
fill_axis=0,
broadcast_axis=None,
Expand Down Expand Up @@ -4199,8 +4199,8 @@ def drop(
index=None,
columns=None,
level=None,
inplace=False,
errors="raise",
inplace: bool = False,
errors: str = "raise",
):
"""
Drop specified labels from rows or columns.
Expand Down Expand Up @@ -4470,9 +4470,9 @@ def rename(
def fillna(
self,
value=None,
method=None,
method: Optional[str] = None,
axis=None,
inplace=False,
inplace: bool = False,
limit=None,
downcast=None,
) -> Optional[DataFrame]:
Expand Down Expand Up @@ -4533,10 +4533,10 @@ def replace(
self,
to_replace=None,
value=None,
inplace=False,
inplace: bool = False,
limit=None,
regex=False,
method="pad",
regex: bool = False,
method: str = "pad",
):
return super().replace(
to_replace=to_replace,
Expand Down Expand Up @@ -4616,7 +4616,12 @@ def shift(
)

def set_index(
self, keys, drop=True, append=False, inplace=False, verify_integrity=False
self,
keys,
drop: bool = True,
append: bool = False,
inplace: bool = False,
verify_integrity: bool = False,
):
"""
Set the DataFrame index using existing columns.
Expand Down Expand Up @@ -5055,7 +5060,9 @@ def notna(self) -> DataFrame:
def notnull(self) -> DataFrame:
return ~self.isna()

def dropna(self, axis=0, how="any", thresh=None, subset=None, inplace=False):
def dropna(
self, axis=0, how: str = "any", thresh=None, subset=None, inplace: bool = False
):
"""
Remove missing values.

Expand Down Expand Up @@ -5436,10 +5443,10 @@ def sort_values( # type: ignore[override]
by,
axis=0,
ascending=True,
inplace=False,
kind="quicksort",
na_position="last",
ignore_index=False,
inplace: bool = False,
kind: str = "quicksort",
na_position: str = "last",
ignore_index: bool = False,
key: ValueKeyFunc = None,
):
inplace = validate_bool_kwarg(inplace, "inplace")
Expand Down Expand Up @@ -5701,7 +5708,7 @@ def value_counts(

return counts

def nlargest(self, n, columns, keep="first") -> DataFrame:
def nlargest(self, n, columns, keep: str = "first") -> DataFrame:
"""
Return the first `n` rows ordered by `columns` in descending order.

Expand Down Expand Up @@ -5810,7 +5817,7 @@ def nlargest(self, n, columns, keep="first") -> DataFrame:
"""
return algorithms.SelectNFrame(self, n=n, keep=keep, columns=columns).nlargest()

def nsmallest(self, n, columns, keep="first") -> DataFrame:
def nsmallest(self, n, columns, keep: str = "first") -> DataFrame:
"""
Return the first `n` rows ordered by `columns` in ascending order.

Expand Down Expand Up @@ -6234,7 +6241,7 @@ def compare(
)

def combine(
self, other: DataFrame, func, fill_value=None, overwrite=True
self, other: DataFrame, func, fill_value=None, overwrite: bool = True
) -> DataFrame:
"""
Perform column-wise combine with another DataFrame.
Expand Down Expand Up @@ -6462,7 +6469,12 @@ def combiner(x, y):
return self.combine(other, combiner, overwrite=False)

def update(
self, other, join="left", overwrite=True, filter_func=None, errors="ignore"
self,
other,
join: str = "left",
overwrite: bool = True,
filter_func=None,
errors: str = "ignore",
) -> None:
"""
Modify in place using non-NA values from another DataFrame.
Expand Down Expand Up @@ -7055,7 +7067,7 @@ def pivot_table(
observed=observed,
)

def stack(self, level=-1, dropna=True):
def stack(self, level=-1, dropna: bool = True):
"""
Stack the prescribed level(s) from columns to index.

Expand Down Expand Up @@ -7636,7 +7648,7 @@ def transform(
assert isinstance(result, DataFrame)
return result

def apply(self, func, axis=0, raw=False, result_type=None, args=(), **kwds):
def apply(self, func, axis=0, raw: bool = False, result_type=None, args=(), **kwds):
"""
Apply a function along an axis of the DataFrame.

Expand Down Expand Up @@ -7861,7 +7873,11 @@ def infer(x):
# Merging / joining methods

def append(
self, other, ignore_index=False, verify_integrity=False, sort=False
self,
other,
ignore_index: bool = False,
verify_integrity: bool = False,
sort: bool = False,
) -> DataFrame:
"""
Append rows of `other` to the end of caller, returning a new object.
Expand Down Expand Up @@ -8002,7 +8018,13 @@ def append(
).__finalize__(self, method="append")

def join(
self, other, on=None, how="left", lsuffix="", rsuffix="", sort=False
self,
other,
on=None,
how: str = "left",
lsuffix: str = "",
rsuffix: str = "",
sort: bool = False,
) -> DataFrame:
"""
Join columns of another DataFrame.
Expand Down Expand Up @@ -8639,7 +8661,7 @@ def c(x):
# ----------------------------------------------------------------------
# ndarray-like stats methods

def count(self, axis=0, level=None, numeric_only=False):
def count(self, axis=0, level=None, numeric_only: bool = False):
"""
Count non-NA cells for each column or row.

Expand Down Expand Up @@ -8794,8 +8816,8 @@ def _reduce(
name: str,
*,
axis=0,
skipna=True,
numeric_only=None,
skipna: bool = True,
numeric_only: Optional[bool] = None,
filter_type=None,
**kwds,
):
Expand Down Expand Up @@ -8901,7 +8923,7 @@ def _get_data() -> DataFrame:
result = self._constructor_sliced(result, index=labels)
return result

def nunique(self, axis=0, dropna=True) -> Series:
def nunique(self, axis=0, dropna: bool = True) -> Series:
"""
Count distinct observations over requested axis.

Expand Down Expand Up @@ -8941,7 +8963,7 @@ def nunique(self, axis=0, dropna=True) -> Series:
"""
return self.apply(Series.nunique, axis=axis, dropna=dropna)

def idxmin(self, axis=0, skipna=True) -> Series:
def idxmin(self, axis=0, skipna: bool = True) -> Series:
"""
Return index of first occurrence of minimum over requested axis.

Expand Down Expand Up @@ -9018,7 +9040,7 @@ def idxmin(self, axis=0, skipna=True) -> Series:
result = [index[i] if i >= 0 else np.nan for i in indices]
return self._constructor_sliced(result, index=self._get_agg_axis(axis))

def idxmax(self, axis=0, skipna=True) -> Series:
def idxmax(self, axis=0, skipna: bool = True) -> Series:
"""
Return index of first occurrence of maximum over requested axis.

Expand Down Expand Up @@ -9106,7 +9128,9 @@ def _get_agg_axis(self, axis_num: int) -> Index:
else:
raise ValueError(f"Axis must be 0 or 1 (got {repr(axis_num)})")

def mode(self, axis=0, numeric_only=False, dropna=True) -> DataFrame:
def mode(
self, axis=0, numeric_only: bool = False, dropna: bool = True
) -> DataFrame:
"""
Get the mode(s) of each element along the selected axis.

Expand Down Expand Up @@ -9193,7 +9217,9 @@ def f(s):

return data.apply(f, axis=axis)

def quantile(self, q=0.5, axis=0, numeric_only=True, interpolation="linear"):
def quantile(
self, q=0.5, axis=0, numeric_only: bool = True, interpolation: str = "linear"
):
"""
Return values at the given quantile over requested axis.

Expand Down