Skip to content

TYP: type all arguments with bool default values #48624

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 3 commits into from
Sep 19, 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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ repos:
|/_testing/
- id: autotyping
name: autotyping
entry: python -m libcst.tool codemod autotyping.AutotypeCommand --none-return --scalar-return --annotate-magics --annotate-imprecise-magics
entry: python -m libcst.tool codemod autotyping.AutotypeCommand --none-return --scalar-return --annotate-magics --annotate-imprecise-magics --bool-param
types_or: [python, pyi]
files: ^pandas
exclude: ^(pandas/tests|pandas/io/clipboard)
exclude: ^(pandas/tests|pandas/_version.py|pandas/io/clipboard)
language: python
additional_dependencies:
- autotyping==22.9.0
Expand Down
8 changes: 4 additions & 4 deletions pandas/_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def equalContents(arr1, arr2) -> bool:
return frozenset(arr1) == frozenset(arr2)


def box_expected(expected, box_cls, transpose=True):
def box_expected(expected, box_cls, transpose: bool = True):
"""
Helper function to wrap the expected output of a test in a given box_class.

Expand Down Expand Up @@ -656,8 +656,8 @@ def keyfunc(x):
def makeCustomDataframe(
nrows,
ncols,
c_idx_names=True,
r_idx_names=True,
c_idx_names: bool | list[str] = True,
r_idx_names: bool | list[str] = True,
c_idx_nlevels=1,
r_idx_nlevels=1,
data_gen_f=None,
Expand All @@ -673,7 +673,7 @@ def makeCustomDataframe(
Parameters
----------
nrows, ncols - number of data rows/cols
c_idx_names, idx_names - False/True/list of strings, yields No names ,
c_idx_names, r_idx_names - False/True/list of strings, yields No names ,
default names or uses the provided names for the levels of the
corresponding index. You can provide a single string when
c_idx_nlevels ==1.
Expand Down
7 changes: 4 additions & 3 deletions pandas/_testing/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ def dec(f):
return wrapper


@optional_args
# error: Untyped decorator makes function "network" untyped
@optional_args # type: ignore[misc]
def network(
t,
url="https://www.google.com",
raise_on_error=False,
check_before_test=False,
raise_on_error: bool = False,
check_before_test: bool = False,
error_classes=None,
skip_errnos=_network_errno_vals,
_skip_on_messages=_network_error_messages,
Expand Down
2 changes: 1 addition & 1 deletion pandas/_testing/_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def randbool(size=(), p: float = 0.5):
)


def rands_array(nchars, size, dtype="O", replace=True) -> np.ndarray:
def rands_array(nchars, size, dtype="O", replace: bool = True) -> np.ndarray:
"""
Generate an array of byte strings.
"""
Expand Down
62 changes: 33 additions & 29 deletions pandas/_testing/asserters.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,11 @@ def assert_is_sorted(seq) -> None:


def assert_categorical_equal(
left, right, check_dtype=True, check_category_order=True, obj="Categorical"
left,
right,
check_dtype: bool = True,
check_category_order: bool = True,
obj="Categorical",
) -> None:
"""
Test that Categoricals are equivalent.
Expand Down Expand Up @@ -618,7 +622,7 @@ def assert_period_array_equal(left, right, obj="PeriodArray") -> None:


def assert_datetime_array_equal(
left, right, obj="DatetimeArray", check_freq=True
left, right, obj="DatetimeArray", check_freq: bool = True
) -> None:
__tracebackhide__ = True
_check_isinstance(left, right, DatetimeArray)
Expand All @@ -630,7 +634,7 @@ def assert_datetime_array_equal(


def assert_timedelta_array_equal(
left, right, obj="TimedeltaArray", check_freq=True
left, right, obj="TimedeltaArray", check_freq: bool = True
) -> None:
__tracebackhide__ = True
_check_isinstance(left, right, TimedeltaArray)
Expand Down Expand Up @@ -685,7 +689,7 @@ def raise_assert_detail(
def assert_numpy_array_equal(
left,
right,
strict_nan=False,
strict_nan: bool = False,
check_dtype: bool | Literal["equiv"] = True,
err_msg=None,
check_same=None,
Expand Down Expand Up @@ -768,7 +772,7 @@ def assert_extension_array_equal(
check_dtype: bool | Literal["equiv"] = True,
index_values=None,
check_less_precise=no_default,
check_exact=False,
check_exact: bool = False,
rtol: float = 1.0e-5,
atol: float = 1.0e-8,
) -> None:
Expand Down Expand Up @@ -872,21 +876,21 @@ def assert_series_equal(
right,
check_dtype: bool | Literal["equiv"] = True,
check_index_type: bool | Literal["equiv"] = "equiv",
check_series_type=True,
check_series_type: bool = True,
check_less_precise: bool | int | NoDefault = no_default,
check_names=True,
check_exact=False,
check_datetimelike_compat=False,
check_categorical=True,
check_category_order=True,
check_freq=True,
check_flags=True,
rtol=1.0e-5,
atol=1.0e-8,
check_names: bool = True,
check_exact: bool = False,
check_datetimelike_compat: bool = False,
check_categorical: bool = True,
check_category_order: bool = True,
check_freq: bool = True,
check_flags: bool = True,
rtol: float = 1.0e-5,
atol: float = 1.0e-8,
obj="Series",
*,
check_index=True,
check_like=False,
check_index: bool = True,
check_like: bool = False,
) -> None:
"""
Check that left and right Series are equal.
Expand Down Expand Up @@ -1140,19 +1144,19 @@ def assert_frame_equal(
right,
check_dtype: bool | Literal["equiv"] = True,
check_index_type: bool | Literal["equiv"] = "equiv",
check_column_type="equiv",
check_frame_type=True,
check_column_type: bool | Literal["equiv"] = "equiv",
check_frame_type: bool = True,
check_less_precise=no_default,
check_names=True,
by_blocks=False,
check_exact=False,
check_datetimelike_compat=False,
check_categorical=True,
check_like=False,
check_freq=True,
check_flags=True,
rtol=1.0e-5,
atol=1.0e-8,
check_names: bool = True,
by_blocks: bool = False,
check_exact: bool = False,
check_datetimelike_compat: bool = False,
check_categorical: bool = True,
check_like: bool = False,
check_freq: bool = True,
check_flags: bool = True,
rtol: float = 1.0e-5,
atol: float = 1.0e-8,
obj="DataFrame",
) -> None:
"""
Expand Down
5 changes: 1 addition & 4 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,7 @@ def frame_or_series(request):
return request.param


# error: List item 0 has incompatible type "Type[Index]"; expected "Type[IndexOpsMixin]"
@pytest.fixture(
params=[Index, Series], ids=["index", "series"] # type: ignore[list-item]
)
@pytest.fixture(params=[Index, Series], ids=["index", "series"])
def index_or_series(request):
"""
Fixture to parametrize over Index and Series, made necessary by a mypy
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def __init__(self, values: pa.Array | pa.ChunkedArray) -> None:
self._dtype = ArrowDtype(self._data.type)

@classmethod
def _from_sequence(cls, scalars, *, dtype: Dtype | None = None, copy=False):
def _from_sequence(cls, scalars, *, dtype: Dtype | None = None, copy: bool = False):
"""
Construct a new ExtensionArray from a sequence of scalars.
"""
Expand All @@ -238,7 +238,7 @@ def _from_sequence(cls, scalars, *, dtype: Dtype | None = None, copy=False):

@classmethod
def _from_sequence_of_strings(
cls, strings, *, dtype: Dtype | None = None, copy=False
cls, strings, *, dtype: Dtype | None = None, copy: bool = False
):
"""
Construct a new ExtensionArray from a sequence of strings.
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class ExtensionArray:
# ------------------------------------------------------------------------

@classmethod
def _from_sequence(cls, scalars, *, dtype: Dtype | None = None, copy=False):
def _from_sequence(cls, scalars, *, dtype: Dtype | None = None, copy: bool = False):
"""
Construct a new ExtensionArray from a sequence of scalars.

Expand All @@ -270,7 +270,7 @@ def _from_sequence(cls, scalars, *, dtype: Dtype | None = None, copy=False):

@classmethod
def _from_sequence_of_strings(
cls, strings, *, dtype: Dtype | None = None, copy=False
cls, strings, *, dtype: Dtype | None = None, copy: bool = False
):
"""
Construct a new ExtensionArray from a sequence of strings.
Expand Down Expand Up @@ -1772,7 +1772,7 @@ class ExtensionScalarOpsMixin(ExtensionOpsMixin):
"""

@classmethod
def _create_method(cls, op, coerce_to_dtype=True, result_dtype=None):
def _create_method(cls, op, coerce_to_dtype: bool = True, result_dtype=None):
"""
A class method that returns a method that will correspond to an
operator for an ExtensionArray subclass, by dispatching to the
Expand Down
17 changes: 11 additions & 6 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,9 @@ def _constructor(self) -> type[Categorical]:
return Categorical

@classmethod
def _from_sequence(cls, scalars, *, dtype: Dtype | None = None, copy=False):
def _from_sequence(
cls, scalars, *, dtype: Dtype | None = None, copy: bool = False
) -> Categorical:
return Categorical(scalars, dtype=dtype, copy=copy)

@overload
Expand Down Expand Up @@ -783,7 +785,7 @@ def codes(self) -> np.ndarray:
v.flags.writeable = False
return v

def _set_categories(self, categories, fastpath=False):
def _set_categories(self, categories, fastpath: bool = False) -> None:
"""
Sets new categories inplace

Expand Down Expand Up @@ -951,7 +953,7 @@ def as_unordered(
return self.set_ordered(False, inplace=inplace)

def set_categories(
self, new_categories, ordered=None, rename=False, inplace=no_default
self, new_categories, ordered=None, rename: bool = False, inplace=no_default
):
"""
Set the categories to the specified new_categories.
Expand Down Expand Up @@ -1821,8 +1823,11 @@ def check_for_ordered(self, op) -> None:
"Categorical to an ordered one\n"
)

# error: Signature of "argsort" incompatible with supertype "ExtensionArray"
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
def argsort(self, ascending=True, kind="quicksort", **kwargs):
def argsort( # type: ignore[override]
self, ascending: bool = True, kind="quicksort", **kwargs
):
"""
Return the indices that would sort the Categorical.

Expand Down Expand Up @@ -2291,7 +2296,7 @@ def _reverse_indexer(self) -> dict[Hashable, npt.NDArray[np.intp]]:
# Reductions

@deprecate_kwarg(old_arg_name="numeric_only", new_arg_name="skipna")
def min(self, *, skipna=True, **kwargs):
def min(self, *, skipna: bool = True, **kwargs):
"""
The minimum value of the object.

Expand Down Expand Up @@ -2328,7 +2333,7 @@ def min(self, *, skipna=True, **kwargs):
return self._wrap_reduction_result(None, pointer)

@deprecate_kwarg(old_arg_name="numeric_only", new_arg_name="skipna")
def max(self, *, skipna=True, **kwargs):
def max(self, *, skipna: bool = True, **kwargs):
"""
The maximum value of the object.

Expand Down
4 changes: 3 additions & 1 deletion pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ class DatetimeLikeArrayMixin(OpsMixin, NDArrayBackedExtensionArray):
def _can_hold_na(self) -> bool:
return True

def __init__(self, data, dtype: Dtype | None = None, freq=None, copy=False) -> None:
def __init__(
self, data, dtype: Dtype | None = None, freq=None, copy: bool = False
) -> None:
raise AbstractMethodError(self)

@property
Expand Down
10 changes: 6 additions & 4 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,19 +333,21 @@ def _from_sequence_not_strict(

return result

# error: Signature of "_generate_range" incompatible with supertype
# "DatetimeLikeArrayMixin"
@classmethod
def _generate_range(
def _generate_range( # type: ignore[override]
cls,
start,
end,
periods,
freq,
tz=None,
normalize=False,
normalize: bool = False,
ambiguous="raise",
nonexistent="raise",
inclusive="both",
):
) -> DatetimeArray:

periods = dtl.validate_periods(periods)
if freq is None and any(x is None for x in [periods, start, end]):
Expand Down Expand Up @@ -2133,7 +2135,7 @@ def objects_to_datetime64ns(
data: np.ndarray,
dayfirst,
yearfirst,
utc=False,
utc: bool = False,
errors="raise",
require_iso8601: bool = False,
allow_object: bool = False,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ def __arrow_array__(self, type=None):
@Appender(
_interval_shared_docs["to_tuples"] % {"return_type": "ndarray", "examples": ""}
)
def to_tuples(self, na_tuple=True) -> np.ndarray:
def to_tuples(self, na_tuple: bool = True) -> np.ndarray:
tuples = com.asarray_tuplesafe(zip(self._left, self._right))
if not na_tuple:
# GH 18756
Expand Down
Loading