Skip to content

Commit 241f0ff

Browse files
authored
typing (bool/str) (#38440)
1 parent a3dc788 commit 241f0ff

File tree

1 file changed

+75
-49
lines changed

1 file changed

+75
-49
lines changed

pandas/core/frame.py

+75-49
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ def to_numpy(
14351435

14361436
return result
14371437

1438-
def to_dict(self, orient="dict", into=dict):
1438+
def to_dict(self, orient: str = "dict", into=dict):
14391439
"""
14401440
Convert the DataFrame to a dictionary.
14411441
@@ -1610,15 +1610,15 @@ def to_dict(self, orient="dict", into=dict):
16101610

16111611
def to_gbq(
16121612
self,
1613-
destination_table,
1614-
project_id=None,
1613+
destination_table: str,
1614+
project_id: Optional[str] = None,
16151615
chunksize=None,
1616-
reauth=False,
1617-
if_exists="fail",
1618-
auth_local_webserver=False,
1616+
reauth: bool = False,
1617+
if_exists: str = "fail",
1618+
auth_local_webserver: bool = False,
16191619
table_schema=None,
1620-
location=None,
1621-
progress_bar=True,
1620+
location: Optional[str] = None,
1621+
progress_bar: bool = True,
16221622
credentials=None,
16231623
) -> None:
16241624
"""
@@ -1723,7 +1723,7 @@ def from_records(
17231723
index=None,
17241724
exclude=None,
17251725
columns=None,
1726-
coerce_float=False,
1726+
coerce_float: bool = False,
17271727
nrows=None,
17281728
) -> DataFrame:
17291729
"""
@@ -2488,7 +2488,7 @@ def to_html(
24882488
max_rows=None,
24892489
max_cols=None,
24902490
show_dimensions=False,
2491-
decimal=".",
2491+
decimal: str = ".",
24922492
bold_rows=True,
24932493
classes=None,
24942494
escape=True,
@@ -3321,7 +3321,7 @@ def _box_col_values(self, values, loc: int) -> Series:
33213321
# ----------------------------------------------------------------------
33223322
# Unsorted
33233323

3324-
def query(self, expr, inplace=False, **kwargs):
3324+
def query(self, expr: str, inplace: bool = False, **kwargs):
33253325
"""
33263326
Query the columns of a DataFrame with a boolean expression.
33273327
@@ -3485,7 +3485,7 @@ def query(self, expr, inplace=False, **kwargs):
34853485
else:
34863486
return result
34873487

3488-
def eval(self, expr, inplace=False, **kwargs):
3488+
def eval(self, expr: str, inplace: bool = False, **kwargs):
34893489
"""
34903490
Evaluate a string describing operations on DataFrame columns.
34913491
@@ -3742,7 +3742,7 @@ def extract_unique_dtypes_from_dtypes_set(
37423742

37433743
return self.iloc[:, keep_these.values]
37443744

3745-
def insert(self, loc, column, value, allow_duplicates=False) -> None:
3745+
def insert(self, loc, column, value, allow_duplicates: bool = False) -> None:
37463746
"""
37473747
Insert column into DataFrame at specified location.
37483748
@@ -3856,7 +3856,7 @@ def assign(self, **kwargs) -> DataFrame:
38563856
data[k] = com.apply_if_callable(v, data)
38573857
return data
38583858

3859-
def _sanitize_column(self, key, value, broadcast=True):
3859+
def _sanitize_column(self, key, value, broadcast: bool = True):
38603860
"""
38613861
Ensures new columns (which go into the BlockManager as new blocks) are
38623862
always copied and converted into an array.
@@ -4049,7 +4049,7 @@ def _reindex_index(
40494049
self,
40504050
new_index,
40514051
method,
4052-
copy,
4052+
copy: bool,
40534053
level,
40544054
fill_value=np.nan,
40554055
limit=None,
@@ -4069,7 +4069,7 @@ def _reindex_columns(
40694069
self,
40704070
new_columns,
40714071
method,
4072-
copy,
4072+
copy: bool,
40734073
level,
40744074
fill_value=None,
40754075
limit=None,
@@ -4085,7 +4085,7 @@ def _reindex_columns(
40854085
allow_dups=False,
40864086
)
40874087

4088-
def _reindex_multi(self, axes, copy, fill_value) -> DataFrame:
4088+
def _reindex_multi(self, axes, copy: bool, fill_value) -> DataFrame:
40894089
"""
40904090
We are guaranteed non-Nones in the axes.
40914091
"""
@@ -4109,12 +4109,12 @@ def _reindex_multi(self, axes, copy, fill_value) -> DataFrame:
41094109
def align(
41104110
self,
41114111
other,
4112-
join="outer",
4112+
join: str = "outer",
41134113
axis=None,
41144114
level=None,
4115-
copy=True,
4115+
copy: bool = True,
41164116
fill_value=None,
4117-
method=None,
4117+
method: Optional[str] = None,
41184118
limit=None,
41194119
fill_axis=0,
41204120
broadcast_axis=None,
@@ -4202,8 +4202,8 @@ def drop(
42024202
index=None,
42034203
columns=None,
42044204
level=None,
4205-
inplace=False,
4206-
errors="raise",
4205+
inplace: bool = False,
4206+
errors: str = "raise",
42074207
):
42084208
"""
42094209
Drop specified labels from rows or columns.
@@ -4473,9 +4473,9 @@ def rename(
44734473
def fillna(
44744474
self,
44754475
value=None,
4476-
method=None,
4476+
method: Optional[str] = None,
44774477
axis=None,
4478-
inplace=False,
4478+
inplace: bool = False,
44794479
limit=None,
44804480
downcast=None,
44814481
) -> Optional[DataFrame]:
@@ -4536,10 +4536,10 @@ def replace(
45364536
self,
45374537
to_replace=None,
45384538
value=None,
4539-
inplace=False,
4539+
inplace: bool = False,
45404540
limit=None,
4541-
regex=False,
4542-
method="pad",
4541+
regex: bool = False,
4542+
method: str = "pad",
45434543
):
45444544
return super().replace(
45454545
to_replace=to_replace,
@@ -4619,7 +4619,12 @@ def shift(
46194619
)
46204620

46214621
def set_index(
4622-
self, keys, drop=True, append=False, inplace=False, verify_integrity=False
4622+
self,
4623+
keys,
4624+
drop: bool = True,
4625+
append: bool = False,
4626+
inplace: bool = False,
4627+
verify_integrity: bool = False,
46234628
):
46244629
"""
46254630
Set the DataFrame index using existing columns.
@@ -5068,7 +5073,9 @@ def notna(self) -> DataFrame:
50685073
def notnull(self) -> DataFrame:
50695074
return ~self.isna()
50705075

5071-
def dropna(self, axis=0, how="any", thresh=None, subset=None, inplace=False):
5076+
def dropna(
5077+
self, axis=0, how: str = "any", thresh=None, subset=None, inplace: bool = False
5078+
):
50725079
"""
50735080
Remove missing values.
50745081
@@ -5449,10 +5456,10 @@ def sort_values( # type: ignore[override]
54495456
by,
54505457
axis=0,
54515458
ascending=True,
5452-
inplace=False,
5453-
kind="quicksort",
5454-
na_position="last",
5455-
ignore_index=False,
5459+
inplace: bool = False,
5460+
kind: str = "quicksort",
5461+
na_position: str = "last",
5462+
ignore_index: bool = False,
54565463
key: ValueKeyFunc = None,
54575464
):
54585465
inplace = validate_bool_kwarg(inplace, "inplace")
@@ -5714,7 +5721,7 @@ def value_counts(
57145721

57155722
return counts
57165723

5717-
def nlargest(self, n, columns, keep="first") -> DataFrame:
5724+
def nlargest(self, n, columns, keep: str = "first") -> DataFrame:
57185725
"""
57195726
Return the first `n` rows ordered by `columns` in descending order.
57205727
@@ -5823,7 +5830,7 @@ def nlargest(self, n, columns, keep="first") -> DataFrame:
58235830
"""
58245831
return algorithms.SelectNFrame(self, n=n, keep=keep, columns=columns).nlargest()
58255832

5826-
def nsmallest(self, n, columns, keep="first") -> DataFrame:
5833+
def nsmallest(self, n, columns, keep: str = "first") -> DataFrame:
58275834
"""
58285835
Return the first `n` rows ordered by `columns` in ascending order.
58295836
@@ -6247,7 +6254,7 @@ def compare(
62476254
)
62486255

62496256
def combine(
6250-
self, other: DataFrame, func, fill_value=None, overwrite=True
6257+
self, other: DataFrame, func, fill_value=None, overwrite: bool = True
62516258
) -> DataFrame:
62526259
"""
62536260
Perform column-wise combine with another DataFrame.
@@ -6475,7 +6482,12 @@ def combiner(x, y):
64756482
return self.combine(other, combiner, overwrite=False)
64766483

64776484
def update(
6478-
self, other, join="left", overwrite=True, filter_func=None, errors="ignore"
6485+
self,
6486+
other,
6487+
join: str = "left",
6488+
overwrite: bool = True,
6489+
filter_func=None,
6490+
errors: str = "ignore",
64796491
) -> None:
64806492
"""
64816493
Modify in place using non-NA values from another DataFrame.
@@ -7068,7 +7080,7 @@ def pivot_table(
70687080
observed=observed,
70697081
)
70707082

7071-
def stack(self, level=-1, dropna=True):
7083+
def stack(self, level=-1, dropna: bool = True):
70727084
"""
70737085
Stack the prescribed level(s) from columns to index.
70747086
@@ -7649,7 +7661,7 @@ def transform(
76497661
assert isinstance(result, DataFrame)
76507662
return result
76517663

7652-
def apply(self, func, axis=0, raw=False, result_type=None, args=(), **kwds):
7664+
def apply(self, func, axis=0, raw: bool = False, result_type=None, args=(), **kwds):
76537665
"""
76547666
Apply a function along an axis of the DataFrame.
76557667
@@ -7874,7 +7886,11 @@ def infer(x):
78747886
# Merging / joining methods
78757887

78767888
def append(
7877-
self, other, ignore_index=False, verify_integrity=False, sort=False
7889+
self,
7890+
other,
7891+
ignore_index: bool = False,
7892+
verify_integrity: bool = False,
7893+
sort: bool = False,
78787894
) -> DataFrame:
78797895
"""
78807896
Append rows of `other` to the end of caller, returning a new object.
@@ -8015,7 +8031,13 @@ def append(
80158031
).__finalize__(self, method="append")
80168032

80178033
def join(
8018-
self, other, on=None, how="left", lsuffix="", rsuffix="", sort=False
8034+
self,
8035+
other,
8036+
on=None,
8037+
how: str = "left",
8038+
lsuffix: str = "",
8039+
rsuffix: str = "",
8040+
sort: bool = False,
80198041
) -> DataFrame:
80208042
"""
80218043
Join columns of another DataFrame.
@@ -8652,7 +8674,7 @@ def c(x):
86528674
# ----------------------------------------------------------------------
86538675
# ndarray-like stats methods
86548676

8655-
def count(self, axis=0, level=None, numeric_only=False):
8677+
def count(self, axis=0, level=None, numeric_only: bool = False):
86568678
"""
86578679
Count non-NA cells for each column or row.
86588680
@@ -8807,8 +8829,8 @@ def _reduce(
88078829
name: str,
88088830
*,
88098831
axis=0,
8810-
skipna=True,
8811-
numeric_only=None,
8832+
skipna: bool = True,
8833+
numeric_only: Optional[bool] = None,
88128834
filter_type=None,
88138835
**kwds,
88148836
):
@@ -8914,7 +8936,7 @@ def _get_data() -> DataFrame:
89148936
result = self._constructor_sliced(result, index=labels)
89158937
return result
89168938

8917-
def nunique(self, axis=0, dropna=True) -> Series:
8939+
def nunique(self, axis=0, dropna: bool = True) -> Series:
89188940
"""
89198941
Count distinct observations over requested axis.
89208942
@@ -8954,7 +8976,7 @@ def nunique(self, axis=0, dropna=True) -> Series:
89548976
"""
89558977
return self.apply(Series.nunique, axis=axis, dropna=dropna)
89568978

8957-
def idxmin(self, axis=0, skipna=True) -> Series:
8979+
def idxmin(self, axis=0, skipna: bool = True) -> Series:
89588980
"""
89598981
Return index of first occurrence of minimum over requested axis.
89608982
@@ -9031,7 +9053,7 @@ def idxmin(self, axis=0, skipna=True) -> Series:
90319053
result = [index[i] if i >= 0 else np.nan for i in indices]
90329054
return self._constructor_sliced(result, index=self._get_agg_axis(axis))
90339055

9034-
def idxmax(self, axis=0, skipna=True) -> Series:
9056+
def idxmax(self, axis=0, skipna: bool = True) -> Series:
90359057
"""
90369058
Return index of first occurrence of maximum over requested axis.
90379059
@@ -9119,7 +9141,9 @@ def _get_agg_axis(self, axis_num: int) -> Index:
91199141
else:
91209142
raise ValueError(f"Axis must be 0 or 1 (got {repr(axis_num)})")
91219143

9122-
def mode(self, axis=0, numeric_only=False, dropna=True) -> DataFrame:
9144+
def mode(
9145+
self, axis=0, numeric_only: bool = False, dropna: bool = True
9146+
) -> DataFrame:
91239147
"""
91249148
Get the mode(s) of each element along the selected axis.
91259149
@@ -9206,7 +9230,9 @@ def f(s):
92069230

92079231
return data.apply(f, axis=axis)
92089232

9209-
def quantile(self, q=0.5, axis=0, numeric_only=True, interpolation="linear"):
9233+
def quantile(
9234+
self, q=0.5, axis=0, numeric_only: bool = True, interpolation: str = "linear"
9235+
):
92109236
"""
92119237
Return values at the given quantile over requested axis.
92129238

0 commit comments

Comments
 (0)