Skip to content

TYP: type all arguments with int default values #48761

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 5 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ repos:
|/_testing/
- id: autotyping
name: autotyping
entry: python -m libcst.tool codemod autotyping.AutotypeCommand --none-return --scalar-return --annotate-magics --annotate-imprecise-magics --bool-param --bytes-param --str-param --float-param
entry: python -m libcst.tool codemod autotyping.AutotypeCommand --aggressive
types_or: [python, pyi]
files: ^pandas
exclude: ^(pandas/tests|pandas/_version.py|pandas/io/clipboard)
Expand Down
2 changes: 1 addition & 1 deletion pandas/_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ def _build_option_description(k: str) -> str:
return s


def pp_options_list(keys: Iterable[str], width=80, _print: bool = False):
def pp_options_list(keys: Iterable[str], width: int = 80, _print: bool = False):
"""Builds a concise listing of available options, grouped by prefix"""
from itertools import groupby
from textwrap import wrap
Expand Down
26 changes: 14 additions & 12 deletions pandas/_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,33 +341,35 @@ def getCols(k) -> str:


# make index
def makeStringIndex(k=10, name=None) -> Index:
def makeStringIndex(k: int = 10, name=None) -> Index:
return Index(rands_array(nchars=10, size=k), name=name)


def makeCategoricalIndex(k=10, n=3, name=None, **kwargs) -> CategoricalIndex:
def makeCategoricalIndex(
k: int = 10, n: int = 3, name=None, **kwargs
) -> CategoricalIndex:
"""make a length k index or n categories"""
x = rands_array(nchars=4, size=n, replace=False)
return CategoricalIndex(
Categorical.from_codes(np.arange(k) % n, categories=x), name=name, **kwargs
)


def makeIntervalIndex(k=10, name=None, **kwargs) -> IntervalIndex:
def makeIntervalIndex(k: int = 10, name=None, **kwargs) -> IntervalIndex:
"""make a length k IntervalIndex"""
x = np.linspace(0, 100, num=(k + 1))
return IntervalIndex.from_breaks(x, name=name, **kwargs)


def makeBoolIndex(k=10, name=None) -> Index:
def makeBoolIndex(k: int = 10, name=None) -> Index:
if k == 1:
return Index([True], name=name)
elif k == 2:
return Index([False, True], name=name)
return Index([False, True] + [False] * (k - 2), name=name)


def makeNumericIndex(k=10, name=None, *, dtype) -> NumericIndex:
def makeNumericIndex(k: int = 10, name=None, *, dtype) -> NumericIndex:
dtype = pandas_dtype(dtype)
assert isinstance(dtype, np.dtype)

Expand All @@ -385,21 +387,21 @@ def makeNumericIndex(k=10, name=None, *, dtype) -> NumericIndex:
return NumericIndex(values, dtype=dtype, name=name)


def makeIntIndex(k=10, name=None) -> Int64Index:
def makeIntIndex(k: int = 10, name=None) -> Int64Index:
base_idx = makeNumericIndex(k, name=name, dtype="int64")
return Int64Index(base_idx)


def makeUIntIndex(k=10, name=None) -> UInt64Index:
def makeUIntIndex(k: int = 10, name=None) -> UInt64Index:
base_idx = makeNumericIndex(k, name=name, dtype="uint64")
return UInt64Index(base_idx)


def makeRangeIndex(k=10, name=None, **kwargs) -> RangeIndex:
def makeRangeIndex(k: int = 10, name=None, **kwargs) -> RangeIndex:
return RangeIndex(0, k, 1, name=name, **kwargs)


def makeFloatIndex(k=10, name=None) -> Float64Index:
def makeFloatIndex(k: int = 10, name=None) -> Float64Index:
base_idx = makeNumericIndex(k, name=name, dtype="float64")
return Float64Index(base_idx)

Expand All @@ -423,7 +425,7 @@ def makePeriodIndex(k: int = 10, name=None, **kwargs) -> PeriodIndex:
return pd.period_range(start=dt, periods=k, freq="B", name=name, **kwargs)


def makeMultiIndex(k=10, names=None, **kwargs):
def makeMultiIndex(k: int = 10, names=None, **kwargs):
N = (k // 2) + 1
rng = range(N)
mi = MultiIndex.from_product([("foo", "bar"), rng], names=names, **kwargs)
Expand Down Expand Up @@ -665,8 +667,8 @@ def makeCustomDataframe(
ncols,
c_idx_names: bool | list[str] = True,
r_idx_names: bool | list[str] = True,
c_idx_nlevels=1,
r_idx_nlevels=1,
c_idx_nlevels: int = 1,
r_idx_nlevels: int = 1,
data_gen_f=None,
c_ndupe_l=None,
r_ndupe_l=None,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def _validate_searchsorted_value(
return value

@doc(ExtensionArray.shift)
def shift(self, periods=1, fill_value=None, axis=0):
def shift(self, periods: int = 1, fill_value=None, axis: AxisInt = 0):

fill_value = self._validate_shift_value(fill_value)
new_values = shift(self._ndarray, periods, axis, fill_value)
Expand Down
14 changes: 12 additions & 2 deletions pandas/core/arrays/masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,12 @@ def _wrap_reduction_result(self, name: str, result, skipna, **kwargs):
return result

def sum(
self, *, skipna: bool = True, min_count=0, axis: AxisInt | None = 0, **kwargs
self,
*,
skipna: bool = True,
min_count: int = 0,
axis: AxisInt | None = 0,
**kwargs,
):
nv.validate_sum((), kwargs)

Expand All @@ -1085,7 +1090,12 @@ def sum(
)

def prod(
self, *, skipna: bool = True, min_count=0, axis: AxisInt | None = 0, **kwargs
self,
*,
skipna: bool = True,
min_count: int = 0,
axis: AxisInt | None = 0,
**kwargs,
):
nv.validate_prod((), kwargs)
result = masked_reductions.prod(
Expand Down
20 changes: 15 additions & 5 deletions pandas/core/arrays/numpy_.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,12 @@ def max(
return self._wrap_reduction_result(axis, result)

def sum(
self, *, axis: AxisInt | None = None, skipna: bool = True, min_count=0, **kwargs
self,
*,
axis: AxisInt | None = None,
skipna: bool = True,
min_count: int = 0,
**kwargs,
) -> Scalar:
nv.validate_sum((), kwargs)
result = nanops.nansum(
Expand All @@ -252,7 +257,12 @@ def sum(
return self._wrap_reduction_result(axis, result)

def prod(
self, *, axis: AxisInt | None = None, skipna: bool = True, min_count=0, **kwargs
self,
*,
axis: AxisInt | None = None,
skipna: bool = True,
min_count: int = 0,
**kwargs,
) -> Scalar:
nv.validate_prod((), kwargs)
result = nanops.nanprod(
Expand Down Expand Up @@ -294,7 +304,7 @@ def std(
axis: AxisInt | None = None,
dtype: NpDtype | None = None,
out=None,
ddof=1,
ddof: int = 1,
keepdims: bool = False,
skipna: bool = True,
):
Expand All @@ -310,7 +320,7 @@ def var(
axis: AxisInt | None = None,
dtype: NpDtype | None = None,
out=None,
ddof=1,
ddof: int = 1,
keepdims: bool = False,
skipna: bool = True,
):
Expand All @@ -326,7 +336,7 @@ def sem(
axis: AxisInt | None = None,
dtype: NpDtype | None = None,
out=None,
ddof=1,
ddof: int = 1,
keepdims: bool = False,
skipna: bool = True,
):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ def dt64arr_to_periodarr(
return c_dt64arr_to_periodarr(data.view("i8"), base, tz, reso=reso), freq


def _get_ordinal_range(start, end, periods, freq, mult=1):
def _get_ordinal_range(start, end, periods, freq, mult: int = 1):
if com.count_not_none(start, end, periods) != 2:
raise ValueError(
"Of the three parameters: start, end, and periods, "
Expand Down
5 changes: 3 additions & 2 deletions pandas/core/arrays/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from pandas._typing import (
ArrayLike,
AstypeArg,
Axis,
AxisInt,
Dtype,
NpDtype,
Expand Down Expand Up @@ -1479,7 +1480,7 @@ def all(self, axis=None, *args, **kwargs):

return values.all()

def any(self, axis=0, *args, **kwargs):
def any(self, axis: AxisInt = 0, *args, **kwargs):
"""
Tests whether at least one of elements evaluate True

Expand Down Expand Up @@ -1576,7 +1577,7 @@ def cumsum(self, axis: AxisInt = 0, *args, **kwargs) -> SparseArray:
fill_value=self.fill_value,
)

def mean(self, axis=0, *args, **kwargs):
def mean(self, axis: Axis = 0, *args, **kwargs):
"""
Mean of non-NA/null values

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/string_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def _str_map(
return lib.map_infer_mask(arr, f, mask.view("uint8"))

def _str_contains(
self, pat, case: bool = True, flags=0, na=np.nan, regex: bool = True
self, pat, case: bool = True, flags: int = 0, na=np.nan, regex: bool = True
):
if flags:
fallback_performancewarning()
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import pandas._libs.lib as lib
from pandas._typing import (
ArrayLike,
Axis,
AxisInt,
DtypeObj,
IndexLabel,
Expand Down Expand Up @@ -784,7 +785,7 @@ def _reduce(
op,
name: str,
*,
axis=0,
axis: Axis = 0,
skipna: bool = True,
numeric_only=None,
filter_type=None,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/computation/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def eval(
local_dict=None,
global_dict=None,
resolvers=(),
level=0,
level: int = 0,
target=None,
inplace: bool = False,
):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/dtypes/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def _concatenate_2d(to_concat, axis: AxisInt):
return np.concatenate(to_concat, axis=axis)


def _concat_datetime(to_concat, axis=0):
def _concat_datetime(to_concat, axis: AxisInt = 0):
"""
provide concatenation of an datetimelike array of arrays each of which is a
single M8[ns], datetime64[ns, tz] or m8[ns] dtype
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10867,7 +10867,7 @@ def func(values: np.ndarray):
# We only use this in the case that operates on self.values
return op(values, axis=axis, skipna=skipna, **kwds)

def blk_func(values, axis=1):
def blk_func(values, axis: Axis = 1):
if isinstance(values, ExtensionArray):
if not is_1d_only_ea_dtype(values.dtype) and not isinstance(
self._mgr, ArrayManager
Expand Down
Loading