diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 31f317636bd69..cef3d6aea5d27 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/pandas/_testing/__init__.py b/pandas/_testing/__init__.py index c15e597558221..92c9c28058714 100644 --- a/pandas/_testing/__init__.py +++ b/pandas/_testing/__init__.py @@ -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. @@ -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, @@ -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. diff --git a/pandas/_testing/_io.py b/pandas/_testing/_io.py index d1acdff8d2fd7..ba94746b0ae6d 100644 --- a/pandas/_testing/_io.py +++ b/pandas/_testing/_io.py @@ -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, diff --git a/pandas/_testing/_random.py b/pandas/_testing/_random.py index 880fffea21bd1..81f3b33d266ee 100644 --- a/pandas/_testing/_random.py +++ b/pandas/_testing/_random.py @@ -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. """ diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index 3858670850074..f05bcc74e6c5d 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -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. @@ -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) @@ -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) @@ -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, @@ -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: @@ -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. @@ -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: """ diff --git a/pandas/conftest.py b/pandas/conftest.py index 8c66f8c39933a..14d156acdf4de 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -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 diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index cfae5b4cae681..9ac77a7d48604 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -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. """ @@ -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. diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index ef7c676be6797..85e85ee6bf070 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -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. @@ -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. @@ -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 diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 085c4563599fc..2acf1ac71970f 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -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 @@ -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 @@ -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. @@ -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. @@ -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. @@ -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. diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index 26bcfb7439bca..831ec98aeeec5 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -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 diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index a3641a06c1964..9f46c1e9210af 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -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]): @@ -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, diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index 446285da719af..12a53ae0a39dd 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -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 diff --git a/pandas/core/arrays/masked.py b/pandas/core/arrays/masked.py index d67a5e215886b..a944dc88a2e77 100644 --- a/pandas/core/arrays/masked.py +++ b/pandas/core/arrays/masked.py @@ -1060,7 +1060,7 @@ def _wrap_reduction_result(self, name: str, result, skipna, **kwargs): return self._maybe_mask_result(result, mask) return result - def sum(self, *, skipna=True, min_count=0, axis: int | None = 0, **kwargs): + def sum(self, *, skipna: bool = True, min_count=0, axis: int | None = 0, **kwargs): nv.validate_sum((), kwargs) # TODO: do this in validate_sum? @@ -1081,7 +1081,7 @@ def sum(self, *, skipna=True, min_count=0, axis: int | None = 0, **kwargs): "sum", result, skipna=skipna, axis=axis, **kwargs ) - def prod(self, *, skipna=True, min_count=0, axis: int | None = 0, **kwargs): + def prod(self, *, skipna: bool = True, min_count=0, axis: int | None = 0, **kwargs): nv.validate_prod((), kwargs) result = masked_reductions.prod( self._data, @@ -1094,7 +1094,7 @@ def prod(self, *, skipna=True, min_count=0, axis: int | None = 0, **kwargs): "prod", result, skipna=skipna, axis=axis, **kwargs ) - def mean(self, *, skipna=True, axis: int | None = 0, **kwargs): + def mean(self, *, skipna: bool = True, axis: int | None = 0, **kwargs): nv.validate_mean((), kwargs) result = masked_reductions.mean( self._data, @@ -1106,7 +1106,9 @@ def mean(self, *, skipna=True, axis: int | None = 0, **kwargs): "mean", result, skipna=skipna, axis=axis, **kwargs ) - def var(self, *, skipna=True, axis: int | None = 0, ddof: int = 1, **kwargs): + def var( + self, *, skipna: bool = True, axis: int | None = 0, ddof: int = 1, **kwargs + ): nv.validate_stat_ddof_func((), kwargs, fname="var") result = masked_reductions.var( self._data, @@ -1119,7 +1121,7 @@ def var(self, *, skipna=True, axis: int | None = 0, ddof: int = 1, **kwargs): "var", result, skipna=skipna, axis=axis, **kwargs ) - def min(self, *, skipna=True, axis: int | None = 0, **kwargs): + def min(self, *, skipna: bool = True, axis: int | None = 0, **kwargs): nv.validate_min((), kwargs) return masked_reductions.min( self._data, @@ -1128,7 +1130,7 @@ def min(self, *, skipna=True, axis: int | None = 0, **kwargs): axis=axis, ) - def max(self, *, skipna=True, axis: int | None = 0, **kwargs): + def max(self, *, skipna: bool = True, axis: int | None = 0, **kwargs): nv.validate_max((), kwargs) return masked_reductions.max( self._data, diff --git a/pandas/core/arrays/sparse/accessor.py b/pandas/core/arrays/sparse/accessor.py index 80713a6fca323..e106fea90b0e2 100644 --- a/pandas/core/arrays/sparse/accessor.py +++ b/pandas/core/arrays/sparse/accessor.py @@ -58,7 +58,7 @@ def _delegate_method(self, name, *args, **kwargs): raise ValueError @classmethod - def from_coo(cls, A, dense_index=False) -> Series: + def from_coo(cls, A, dense_index: bool = False) -> Series: """ Create a Series with sparse values from a scipy.sparse.coo_matrix. @@ -107,7 +107,7 @@ def from_coo(cls, A, dense_index=False) -> Series: return result - def to_coo(self, row_levels=(0,), column_levels=(1,), sort_labels=False): + def to_coo(self, row_levels=(0,), column_levels=(1,), sort_labels: bool = False): """ Create a scipy.sparse.coo_matrix from a Series with MultiIndex. diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index 13818ef7c5d17..a63b5ff152a6c 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -1872,7 +1872,7 @@ def __repr__(self) -> str: pp_index = printing.pprint_thing(self.sp_index) return f"{pp_str}\nFill: {pp_fill}\n{pp_index}" - def _formatter(self, boxed=False): + def _formatter(self, boxed: bool = False): # Defer to the formatter from the GenericArrayFormatter calling us. # This will infer the correct formatter from the dtype of the values. return None diff --git a/pandas/core/arrays/string_.py b/pandas/core/arrays/string_.py index 0e2df9f7cf728..959b2bed5d7f5 100644 --- a/pandas/core/arrays/string_.py +++ b/pandas/core/arrays/string_.py @@ -302,7 +302,7 @@ class StringArray(BaseStringArray, PandasArray): # undo the PandasArray hack _typ = "extension" - def __init__(self, values, copy=False) -> None: + def __init__(self, values, copy: bool = False) -> None: values = extract_array(values) super().__init__(values, copy=copy) @@ -327,7 +327,7 @@ def _validate(self): lib.convert_nans_to_NA(self._ndarray) @classmethod - def _from_sequence(cls, scalars, *, dtype: Dtype | None = None, copy=False): + def _from_sequence(cls, scalars, *, dtype: Dtype | None = None, copy: bool = False): if dtype and not (isinstance(dtype, str) and dtype == "string"): dtype = pandas_dtype(dtype) assert isinstance(dtype, StringDtype) and dtype.storage == "python" @@ -354,7 +354,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 ): return cls._from_sequence(strings, dtype=dtype, copy=copy) diff --git a/pandas/core/arrays/string_arrow.py b/pandas/core/arrays/string_arrow.py index ed71e263ae51c..cfa61abcaa2a7 100644 --- a/pandas/core/arrays/string_arrow.py +++ b/pandas/core/arrays/string_arrow.py @@ -309,7 +309,9 @@ def _str_map( # -> We don't know the result type. E.g. `.get` can return anything. return lib.map_infer_mask(arr, f, mask.view("uint8")) - def _str_contains(self, pat, case=True, flags=0, na=np.nan, regex: bool = True): + def _str_contains( + self, pat, case: bool = True, flags=0, na=np.nan, regex: bool = True + ): if flags: fallback_performancewarning() return super()._str_contains(pat, case, flags, na, regex) diff --git a/pandas/core/base.py b/pandas/core/base.py index 8f3b31caf8986..8e19c75640c1d 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -702,7 +702,7 @@ def min(self, axis=None, skipna: bool = True, *args, **kwargs): return nanops.nanmin(self._values, skipna=skipna) @doc(argmax, op="min", oppose="max", value="smallest") - def argmin(self, axis=None, skipna=True, *args, **kwargs) -> int: + def argmin(self, axis=None, skipna: bool = True, *args, **kwargs) -> int: delegate = self._values nv.validate_minmax_axis(axis) skipna = nv.validate_argmin_with_skipna(skipna, args, kwargs) @@ -779,7 +779,7 @@ def _reduce( name: str, *, axis=0, - skipna=True, + skipna: bool = True, numeric_only=None, filter_type=None, **kwds, diff --git a/pandas/core/computation/eval.py b/pandas/core/computation/eval.py index 0a9bb6a4bb6fa..bcd39eab88590 100644 --- a/pandas/core/computation/eval.py +++ b/pandas/core/computation/eval.py @@ -178,7 +178,7 @@ def eval( resolvers=(), level=0, target=None, - inplace=False, + inplace: bool = False, ): """ Evaluate a Python expression as a string using various backends. diff --git a/pandas/core/computation/expressions.py b/pandas/core/computation/expressions.py index 6c3d2cee593a0..5c7f5fc521e19 100644 --- a/pandas/core/computation/expressions.py +++ b/pandas/core/computation/expressions.py @@ -40,7 +40,7 @@ _MIN_ELEMENTS = 1_000_000 -def set_use_numexpr(v=True) -> None: +def set_use_numexpr(v: bool = True) -> None: # set/unset to use numexpr global USE_NUMEXPR if NUMEXPR_INSTALLED: @@ -243,7 +243,7 @@ def evaluate(op, a, b, use_numexpr: bool = True): return _evaluate_standard(op, op_str, a, b) -def where(cond, a, b, use_numexpr=True): +def where(cond, a, b, use_numexpr: bool = True): """ Evaluate the where condition cond on a and b. diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 22ccd1d763769..8b3ca54e38786 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8728,11 +8728,11 @@ def pivot_table( columns=None, aggfunc="mean", fill_value=None, - margins=False, - dropna=True, + margins: bool = False, + dropna: bool = True, margins_name="All", - observed=False, - sort=True, + observed: bool = False, + sort: bool = True, ) -> DataFrame: from pandas.core.reshape.pivot import pivot_table diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 358f81d7e3e07..7e3d5034ef68d 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1321,7 +1321,7 @@ class name return None @final - def _set_axis_name(self, name, axis=0, inplace=False): + def _set_axis_name(self, name, axis=0, inplace: bool_t = False): """ Set the name(s) of the axis. @@ -4137,7 +4137,7 @@ def _check_is_chained_assignment_possible(self) -> bool_t: return False @final - def _check_setitem_copy(self, t="setting", force=False): + def _check_setitem_copy(self, t="setting", force: bool_t = False): """ Parameters @@ -4768,7 +4768,7 @@ def sort_values( self: NDFrameT, *, axis: Axis = ..., - ascending=..., + ascending: bool_t | Sequence[bool_t] = ..., inplace: Literal[False] = ..., kind: str = ..., na_position: str = ..., @@ -4782,7 +4782,7 @@ def sort_values( self, *, axis: Axis = ..., - ascending=..., + ascending: bool_t | Sequence[bool_t] = ..., inplace: Literal[True], kind: str = ..., na_position: str = ..., @@ -4796,7 +4796,7 @@ def sort_values( self: NDFrameT, *, axis: Axis = ..., - ascending=..., + ascending: bool_t | Sequence[bool_t] = ..., inplace: bool_t = ..., kind: str = ..., na_position: str = ..., @@ -4809,7 +4809,7 @@ def sort_values( def sort_values( self: NDFrameT, axis: Axis = 0, - ascending=True, + ascending: bool_t | Sequence[bool_t] = True, inplace: bool_t = False, kind: str = "quicksort", na_position: str = "last", @@ -9643,7 +9643,7 @@ def _where( self, cond, other=lib.no_default, - inplace=False, + inplace: bool_t = False, axis=None, level=None, ): @@ -11641,7 +11641,9 @@ def _add_numeric_operations(cls) -> None: examples=_any_examples, empty_value=False, ) - def any(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs): + def any( + self, axis=0, bool_only=None, skipna: bool_t = True, level=None, **kwargs + ): return NDFrame.any(self, axis, bool_only, skipna, level, **kwargs) setattr(cls, "any", any) @@ -11656,7 +11658,9 @@ def any(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs): examples=_all_examples, empty_value=True, ) - def all(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs): + def all( + self, axis=0, bool_only=None, skipna: bool_t = True, level=None, **kwargs + ): return NDFrame.all(self, axis, bool_only, skipna, level, **kwargs) setattr(cls, "all", all) @@ -11671,7 +11675,7 @@ def all(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs): see_also="", examples="", ) - def mad(self, axis=None, skipna=True, level=None): + def mad(self, axis=None, skipna: bool_t = True, level=None): return NDFrame.mad(self, axis, skipna, level) setattr(cls, "mad", mad) @@ -11690,7 +11694,7 @@ def mad(self, axis=None, skipna=True, level=None): def sem( self, axis=None, - skipna=True, + skipna: bool_t = True, level=None, ddof=1, numeric_only=None, @@ -11713,7 +11717,7 @@ def sem( def var( self, axis=None, - skipna=True, + skipna: bool_t = True, level=None, ddof=1, numeric_only=None, @@ -11737,7 +11741,7 @@ def var( def std( self, axis=None, - skipna=True, + skipna: bool_t = True, level=None, ddof=1, numeric_only=None, @@ -11756,7 +11760,7 @@ def std( accum_func_name="min", examples=_cummin_examples, ) - def cummin(self, axis=None, skipna=True, *args, **kwargs): + def cummin(self, axis=None, skipna: bool_t = True, *args, **kwargs): return NDFrame.cummin(self, axis, skipna, *args, **kwargs) setattr(cls, "cummin", cummin) @@ -11770,7 +11774,7 @@ def cummin(self, axis=None, skipna=True, *args, **kwargs): accum_func_name="max", examples=_cummax_examples, ) - def cummax(self, axis=None, skipna=True, *args, **kwargs): + def cummax(self, axis=None, skipna: bool_t = True, *args, **kwargs): return NDFrame.cummax(self, axis, skipna, *args, **kwargs) setattr(cls, "cummax", cummax) @@ -11784,7 +11788,7 @@ def cummax(self, axis=None, skipna=True, *args, **kwargs): accum_func_name="sum", examples=_cumsum_examples, ) - def cumsum(self, axis=None, skipna=True, *args, **kwargs): + def cumsum(self, axis=None, skipna: bool_t = True, *args, **kwargs): return NDFrame.cumsum(self, axis, skipna, *args, **kwargs) setattr(cls, "cumsum", cumsum) @@ -11798,12 +11802,13 @@ def cumsum(self, axis=None, skipna=True, *args, **kwargs): accum_func_name="prod", examples=_cumprod_examples, ) - def cumprod(self, axis=None, skipna=True, *args, **kwargs): + def cumprod(self, axis=None, skipna: bool_t = True, *args, **kwargs): return NDFrame.cumprod(self, axis, skipna, *args, **kwargs) setattr(cls, "cumprod", cumprod) - @doc( + # error: Untyped decorator makes function "sum" untyped + @doc( # type: ignore[misc] _num_doc, desc="Return the sum of the values over the requested axis.\n\n" "This is equivalent to the method ``numpy.sum``.", @@ -11817,7 +11822,7 @@ def cumprod(self, axis=None, skipna=True, *args, **kwargs): def sum( self, axis=None, - skipna=True, + skipna: bool_t = True, level=None, numeric_only=None, min_count=0, @@ -11842,7 +11847,7 @@ def sum( def prod( self, axis=None, - skipna=True, + skipna: bool_t = True, level=None, numeric_only=None, min_count=0, @@ -11868,7 +11873,7 @@ def prod( def mean( self, axis: int | None | lib.NoDefault = lib.no_default, - skipna=True, + skipna: bool_t = True, level=None, numeric_only=None, **kwargs, @@ -11890,7 +11895,7 @@ def mean( def skew( self, axis: int | None | lib.NoDefault = lib.no_default, - skipna=True, + skipna: bool_t = True, level=None, numeric_only=None, **kwargs, @@ -11915,7 +11920,7 @@ def skew( def kurt( self, axis: Axis | None | lib.NoDefault = lib.no_default, - skipna=True, + skipna: bool_t = True, level=None, numeric_only=None, **kwargs, @@ -11938,7 +11943,7 @@ def kurt( def median( self, axis: int | None | lib.NoDefault = lib.no_default, - skipna=True, + skipna: bool_t = True, level=None, numeric_only=None, **kwargs, @@ -11962,7 +11967,7 @@ def median( def max( self, axis: int | None | lib.NoDefault = lib.no_default, - skipna=True, + skipna: bool_t = True, level=None, numeric_only=None, **kwargs, @@ -11986,7 +11991,7 @@ def max( def min( self, axis: int | None | lib.NoDefault = lib.no_default, - skipna=True, + skipna: bool_t = True, level=None, numeric_only=None, **kwargs, diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 3383b0480bf2b..7185db8d21cfc 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -1484,7 +1484,7 @@ def _transform_item_by_item(self, obj: DataFrame, wrapper) -> DataFrame: result.columns = columns return result - def filter(self, func, dropna=True, *args, **kwargs): + def filter(self, func, dropna: bool = True, *args, **kwargs): """ Filter elements from groups that don't satisfy a criterion. diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 6d9ef3c484971..49761ebd6c06e 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -1636,7 +1636,9 @@ def _python_apply_general( ) @final - def _python_agg_general(self, func, *args, raise_on_typeerror=False, **kwargs): + def _python_agg_general( + self, func, *args, raise_on_typeerror: bool = False, **kwargs + ): func = com.is_builtin_func(func) f = lambda x: func(x, *args, **kwargs) @@ -3676,7 +3678,7 @@ def cumsum(self, axis=0, *args, **kwargs) -> NDFrameT: @final @Substitution(name="groupby") @Appender(_common_see_also) - def cummin(self, axis=0, numeric_only=False, **kwargs) -> NDFrameT: + def cummin(self, axis=0, numeric_only: bool = False, **kwargs) -> NDFrameT: """ Cumulative min for each group. @@ -3700,7 +3702,7 @@ def cummin(self, axis=0, numeric_only=False, **kwargs) -> NDFrameT: @final @Substitution(name="groupby") @Appender(_common_see_also) - def cummax(self, axis=0, numeric_only=False, **kwargs) -> NDFrameT: + def cummax(self, axis=0, numeric_only: bool = False, **kwargs) -> NDFrameT: """ Cumulative max for each group. diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 52150eafd7783..be89b3b97d9a7 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -431,7 +431,13 @@ def _engine_type( # Constructors def __new__( - cls, data=None, dtype=None, copy=False, name=None, tupleize_cols=True, **kwargs + cls, + data=None, + dtype=None, + copy: bool = False, + name=None, + tupleize_cols: bool = True, + **kwargs, ) -> Index: if kwargs: @@ -1852,8 +1858,26 @@ def _set_names(self, values, *, level=None) -> None: names = property(fset=_set_names, fget=_get_names) + @overload + def set_names( + self: _IndexT, names, *, level=..., inplace: Literal[False] = ... + ) -> _IndexT: + ... + + @overload + def set_names(self, names, *, level=..., inplace: Literal[True]) -> None: + ... + + @overload + def set_names( + self: _IndexT, names, *, level=..., inplace: bool = ... + ) -> _IndexT | None: + ... + @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "names"]) - def set_names(self, names, level=None, inplace: bool = False): + def set_names( + self: _IndexT, names, level=None, inplace: bool = False + ) -> _IndexT | None: """ Set Index or MultiIndex name. @@ -1962,8 +1986,9 @@ def set_names(self, names, level=None, inplace: bool = False): idx._set_names(names, level=level) if not inplace: return idx + return None - def rename(self, name, inplace=False): + def rename(self, name, inplace: bool = False): """ Alter Index or MultiIndex name. @@ -2058,7 +2083,9 @@ def _get_level_number(self, level) -> int: self._validate_index_level(level) return 0 - def sortlevel(self, level=None, ascending=True, sort_remaining=None): + def sortlevel( + self, level=None, ascending: bool | list[bool] = True, sort_remaining=None + ): """ For internal compatibility with the Index API. @@ -3444,7 +3471,7 @@ def _wrap_setop_result(self, other: Index, result) -> Index: return result @final - def intersection(self, other, sort=False): + def intersection(self, other, sort: bool = False): """ Form the intersection of two Index objects. @@ -3522,7 +3549,7 @@ def intersection(self, other, sort=False): result = self._intersection(other, sort=sort) return self._wrap_intersection_result(other, result) - def _intersection(self, other: Index, sort=False): + def _intersection(self, other: Index, sort: bool = False): """ intersection specialized to the case with matching dtypes. """ @@ -7179,7 +7206,7 @@ def _maybe_disable_logical_methods(self, opname: str_t) -> None: make_invalid_op(opname)(self) @Appender(IndexOpsMixin.argmin.__doc__) - def argmin(self, axis=None, skipna=True, *args, **kwargs) -> int: + def argmin(self, axis=None, skipna: bool = True, *args, **kwargs) -> int: nv.validate_argmin(args, kwargs) nv.validate_minmax_axis(axis) @@ -7191,7 +7218,7 @@ def argmin(self, axis=None, skipna=True, *args, **kwargs) -> int: return super().argmin(skipna=skipna) @Appender(IndexOpsMixin.argmax.__doc__) - def argmax(self, axis=None, skipna=True, *args, **kwargs) -> int: + def argmax(self, axis=None, skipna: bool = True, *args, **kwargs) -> int: nv.validate_argmax(args, kwargs) nv.validate_minmax_axis(axis) @@ -7203,7 +7230,7 @@ def argmax(self, axis=None, skipna=True, *args, **kwargs) -> int: return super().argmax(skipna=skipna) @doc(IndexOpsMixin.min) - def min(self, axis=None, skipna=True, *args, **kwargs): + def min(self, axis=None, skipna: bool = True, *args, **kwargs): nv.validate_min(args, kwargs) nv.validate_minmax_axis(axis) @@ -7229,7 +7256,7 @@ def min(self, axis=None, skipna=True, *args, **kwargs): return super().min(skipna=skipna) @doc(IndexOpsMixin.max) - def max(self, axis=None, skipna=True, *args, **kwargs): + def max(self, axis=None, skipna: bool = True, *args, **kwargs): nv.validate_max(args, kwargs) nv.validate_minmax_axis(axis) diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 6867ef936d45e..f4077449a7907 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -457,7 +457,7 @@ def _range_union(self, other, sort): res_i8 = left.union(right, sort=sort) return self._wrap_range_setop(other, res_i8) - def _intersection(self, other: Index, sort=False) -> Index: + def _intersection(self, other: Index, sort: bool = False) -> Index: """ intersection specialized to the case with matching dtypes and both non-empty. """ @@ -695,7 +695,7 @@ def insert(self, loc: int, item): # NDArray-Like Methods @Appender(_index_shared_docs["take"] % _index_doc_kwargs) - def take(self, indices, axis=0, allow_fill=True, fill_value=None, **kwargs): + def take(self, indices, axis=0, allow_fill: bool = True, fill_value=None, **kwargs): nv.validate_take((), kwargs) indices = np.asarray(indices, dtype=np.intp) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index dd63ea94d5211..24aa45825e122 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -15,6 +15,7 @@ Sequence, Tuple, cast, + overload, ) import warnings @@ -308,7 +309,7 @@ def __new__( sortorder=None, names=None, dtype=None, - copy=False, + copy: bool = False, name=None, verify_integrity: bool = True, ) -> MultiIndex: @@ -435,7 +436,12 @@ def _verify_integrity(self, codes: list | None = None, levels: list | None = Non return new_codes @classmethod - def from_arrays(cls, arrays, sortorder=None, names=lib.no_default) -> MultiIndex: + def from_arrays( + cls, + arrays, + sortorder=None, + names: Sequence[Hashable] | Hashable | lib.NoDefault = lib.no_default, + ) -> MultiIndex: """ Convert arrays to MultiIndex. @@ -506,7 +512,7 @@ def from_tuples( cls, tuples: Iterable[tuple[Hashable, ...]], sortorder: int | None = None, - names: Sequence[Hashable] | Hashable | None = None, + names: Sequence[Hashable] | Hashable = None, ) -> MultiIndex: """ Convert list of tuples to MultiIndex. @@ -586,7 +592,7 @@ def from_product( cls, iterables: Sequence[Iterable[Hashable]], sortorder: int | None = None, - names: Sequence[Hashable] | lib.NoDefault = lib.no_default, + names: Sequence[Hashable] | Hashable | lib.NoDefault = lib.no_default, ) -> MultiIndex: """ Make a MultiIndex from the cartesian product of multiple iterables. @@ -1153,13 +1159,14 @@ def _view(self) -> MultiIndex: # -------------------------------------------------------------------- - def copy( + # error: Signature of "copy" incompatible with supertype "Index" + def copy( # type: ignore[override] self, names=None, dtype=None, levels=None, codes=None, - deep=False, + deep: bool = False, name=None, ): """ @@ -2446,7 +2453,7 @@ def cats(level_codes): ] def sortlevel( - self, level=0, ascending: bool = True, sort_remaining: bool = True + self, level=0, ascending: bool | list[bool] = True, sort_remaining: bool = True ) -> tuple[MultiIndex, npt.NDArray[np.intp]]: """ Sort MultiIndex at the requested level. @@ -3695,9 +3702,8 @@ def _get_reconciled_name_object(self, other) -> MultiIndex: """ names = self._maybe_match_names(other) if self.names != names: - # Incompatible return value type (got "Optional[MultiIndex]", expected - # "MultiIndex") - return self.rename(names) # type: ignore[return-value] + # error: Cannot determine type of "rename" + return self.rename(names) # type: ignore[has-type] return self def _maybe_match_names(self, other): @@ -3858,11 +3864,30 @@ def isin(self, values, level=None) -> npt.NDArray[np.bool_]: return np.zeros(len(levs), dtype=np.bool_) return levs.isin(values) + @overload + def set_names( + self, names, *, level=..., inplace: Literal[False] = ... + ) -> MultiIndex: + ... + + @overload + def set_names(self, names, *, level=..., inplace: Literal[True]) -> None: + ... + + @overload + def set_names(self, names, *, level=..., inplace: bool = ...) -> MultiIndex | None: + ... + + # error: Signature of "set_names" incompatible with supertype "Index" @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "names"]) - def set_names(self, names, level=None, inplace: bool = False) -> MultiIndex | None: + def set_names( # type: ignore[override] + self, names, level=None, inplace: bool = False + ) -> MultiIndex | None: return super().set_names(names=names, level=level, inplace=inplace) - rename = set_names + # error: Incompatible types in assignment (expression has type overloaded function, + # base class "Index" defined the type as "Callable[[Index, Any, bool], Any]") + rename = set_names # type: ignore[assignment] @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) def drop_duplicates(self, keep: str | bool = "first") -> MultiIndex: diff --git a/pandas/core/indexes/numeric.py b/pandas/core/indexes/numeric.py index d114fe47fa0f1..6dc100dde67a0 100644 --- a/pandas/core/indexes/numeric.py +++ b/pandas/core/indexes/numeric.py @@ -123,7 +123,7 @@ def inferred_type(self) -> str: }[self.dtype.kind] def __new__( - cls, data=None, dtype: Dtype | None = None, copy=False, name=None + cls, data=None, dtype: Dtype | None = None, copy: bool = False, name=None ) -> NumericIndex: name = maybe_extract_name(name, data, cls) diff --git a/pandas/core/indexes/range.py b/pandas/core/indexes/range.py index 9f49c7456d9ce..27b62776c3001 100644 --- a/pandas/core/indexes/range.py +++ b/pandas/core/indexes/range.py @@ -582,7 +582,7 @@ def sort_values( # -------------------------------------------------------------------- # Set Operations - def _intersection(self, other: Index, sort=False): + def _intersection(self, other: Index, sort: bool = False): # caller is responsible for checking self and other are both non-empty if not isinstance(other, RangeIndex): diff --git a/pandas/core/indexes/timedeltas.py b/pandas/core/indexes/timedeltas.py index 12a8f2c0d5a9d..f41e82897c208 100644 --- a/pandas/core/indexes/timedeltas.py +++ b/pandas/core/indexes/timedeltas.py @@ -122,7 +122,7 @@ def __new__( freq=lib.no_default, closed=None, dtype=TD64NS_DTYPE, - copy=False, + copy: bool = False, name=None, ): name = maybe_extract_name(name, data, cls) diff --git a/pandas/core/interchange/from_dataframe.py b/pandas/core/interchange/from_dataframe.py index 4602819b4834a..449a1cc3fb5fa 100644 --- a/pandas/core/interchange/from_dataframe.py +++ b/pandas/core/interchange/from_dataframe.py @@ -28,7 +28,7 @@ } -def from_dataframe(df, allow_copy=True) -> pd.DataFrame: +def from_dataframe(df, allow_copy: bool = True) -> pd.DataFrame: """ Build a ``pd.DataFrame`` from any DataFrame supporting the interchange protocol. @@ -53,7 +53,7 @@ def from_dataframe(df, allow_copy=True) -> pd.DataFrame: return _from_dataframe(df.__dataframe__(allow_copy=allow_copy)) -def _from_dataframe(df: DataFrameXchg, allow_copy=True): +def _from_dataframe(df: DataFrameXchg, allow_copy: bool = True): """ Build a ``pd.DataFrame`` from the DataFrame interchange object. diff --git a/pandas/core/internals/array_manager.py b/pandas/core/internals/array_manager.py index 53f8486074ef9..45318a0bcd7f2 100644 --- a/pandas/core/internals/array_manager.py +++ b/pandas/core/internals/array_manager.py @@ -268,7 +268,9 @@ def apply( # expected "List[Union[ndarray, ExtensionArray]]" return type(self)(result_arrays, new_axes) # type: ignore[arg-type] - def apply_with_block(self: T, f, align_keys=None, swap_axis=True, **kwargs) -> T: + def apply_with_block( + self: T, f, align_keys=None, swap_axis: bool = True, **kwargs + ) -> T: # switch axis to follow BlockManager logic if swap_axis and "axis" in kwargs and self.ndim == 2: kwargs["axis"] = 1 if kwargs["axis"] == 0 else 0 @@ -500,7 +502,7 @@ def get_numeric_data(self: T, copy: bool = False) -> T: or getattr(arr.dtype, "_is_numeric", False) ) - def copy(self: T, deep=True) -> T: + def copy(self: T, deep: bool | Literal["all"] | None = True) -> T: """ Make deep or shallow copy of ArrayManager @@ -669,7 +671,7 @@ def take( new_axis=new_labels, indexer=indexer, axis=axis, allow_dups=True ) - def _make_na_array(self, fill_value=None, use_na_proxy=False): + def _make_na_array(self, fill_value=None, use_na_proxy: bool = False): if use_na_proxy: assert fill_value is None return NullArrayProxy(self.shape_proper[0]) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 072acba071fe8..824e645977e2c 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -28,6 +28,7 @@ ArrayLike, DtypeObj, F, + FillnaOptions, IgnoreRaise, Shape, npt, @@ -1611,8 +1612,15 @@ def get_values(self, dtype: DtypeObj | None = None) -> np.ndarray: def values_for_json(self) -> np.ndarray: return np.asarray(self.values) - def interpolate( - self, method="pad", axis=0, inplace=False, limit=None, fill_value=None, **kwargs + # error: Signature of "interpolate" incompatible with supertype "Block" + def interpolate( # type: ignore[override] + self, + method: FillnaOptions = "pad", + axis: int = 0, + inplace: bool = False, + limit: int | None = None, + fill_value=None, + **kwargs, ): values = self.values if values.ndim == 2 and axis == 0: diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 61037a46f4f92..9b78d443c11de 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -610,7 +610,7 @@ def _combine( def nblocks(self) -> int: return len(self.blocks) - def copy(self: T, deep=True) -> T: + def copy(self: T, deep: bool | None | Literal["all"] = True) -> T: """ Make deep or shallow copy of BlockManager diff --git a/pandas/core/missing.py b/pandas/core/missing.py index 997a7dbc9ceb8..ac44d6e80adc1 100644 --- a/pandas/core/missing.py +++ b/pandas/core/missing.py @@ -466,7 +466,14 @@ def _interpolate_1d( def _interpolate_scipy_wrapper( - x, y, new_x, method, fill_value=None, bounds_error=False, order=None, **kwargs + x, + y, + new_x, + method, + fill_value=None, + bounds_error: bool = False, + order=None, + **kwargs, ): """ Passed off to scipy.interpolate.interp1d. method is scipy's kind. @@ -535,7 +542,7 @@ def _interpolate_scipy_wrapper( return new_y -def _from_derivatives(xi, yi, x, order=None, der=0, extrapolate=False): +def _from_derivatives(xi, yi, x, order=None, der=0, extrapolate: bool = False): """ Convenience function for interpolate.BPoly.from_derivatives. diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index 6658b25d09e6d..8566d901e0b03 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -720,7 +720,7 @@ def nanmean( @bottleneck_switch() -def nanmedian(values, *, axis=None, skipna=True, mask=None): +def nanmedian(values, *, axis=None, skipna: bool = True, mask=None): """ Parameters ---------- @@ -869,7 +869,7 @@ def _get_counts_nanvar( @bottleneck_switch(ddof=1) -def nanstd(values, *, axis=None, skipna=True, ddof=1, mask=None): +def nanstd(values, *, axis=None, skipna: bool = True, ddof=1, mask=None): """ Compute the standard deviation along given axis while ignoring NaNs @@ -909,7 +909,7 @@ def nanstd(values, *, axis=None, skipna=True, ddof=1, mask=None): @disallow("M8", "m8") @bottleneck_switch(ddof=1) -def nanvar(values, *, axis=None, skipna=True, ddof=1, mask=None): +def nanvar(values, *, axis=None, skipna: bool = True, ddof=1, mask=None): """ Compute the variance along given axis while ignoring NaNs diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 85731bbde6d40..2f4b0416007da 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -896,7 +896,7 @@ def interpolate( method="linear", axis=0, limit=None, - inplace=False, + inplace: bool = False, limit_direction="forward", limit_area=None, downcast=None, diff --git a/pandas/core/reshape/concat.py b/pandas/core/reshape/concat.py index 3d9e4f0c69c62..33f164efdd0c7 100644 --- a/pandas/core/reshape/concat.py +++ b/pandas/core/reshape/concat.py @@ -398,7 +398,7 @@ def __init__( ignore_index: bool = False, verify_integrity: bool = False, copy: bool = True, - sort=False, + sort: bool = False, ) -> None: if isinstance(objs, (ABCSeries, ABCDataFrame, str)): raise TypeError( diff --git a/pandas/core/reshape/pivot.py b/pandas/core/reshape/pivot.py index b14c49e735355..a55a84735699d 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -557,7 +557,7 @@ def crosstab( margins: bool = False, margins_name: str = "All", dropna: bool = True, - normalize=False, + normalize: bool = False, ) -> DataFrame: """ Compute a simple cross tabulation of two (or more) factors. @@ -695,6 +695,8 @@ def crosstab( df["__dummy__"] = values kwargs = {"aggfunc": aggfunc} + # error: Argument 7 to "pivot_table" of "DataFrame" has incompatible type + # "**Dict[str, object]"; expected "bool" table = df.pivot_table( "__dummy__", index=unique_rownames, @@ -702,7 +704,7 @@ def crosstab( margins=margins, margins_name=margins_name, dropna=dropna, - **kwargs, + **kwargs, # type: ignore[arg-type] ) # Post-process diff --git a/pandas/core/reshape/reshape.py b/pandas/core/reshape/reshape.py index 0270a5dd75952..ca1e3bf7fa1a5 100644 --- a/pandas/core/reshape/reshape.py +++ b/pandas/core/reshape/reshape.py @@ -615,7 +615,7 @@ def factorize(index): return frame._constructor_sliced(new_values, index=new_index) -def stack_multiple(frame, level, dropna=True): +def stack_multiple(frame, level, dropna: bool = True): # If all passed levels match up to column names, no # ambiguity about what to do if all(lev in frame.columns.names for lev in level): diff --git a/pandas/core/series.py b/pandas/core/series.py index fc97a8f04e0cc..f2f929418718e 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1636,9 +1636,9 @@ def to_string( float_format: str | None = None, header: bool = True, index: bool = True, - length=False, - dtype=False, - name=False, + length: bool = False, + dtype: bool = False, + name: bool = False, max_rows: int | None = None, min_rows: int | None = None, ) -> str | None: @@ -1949,7 +1949,7 @@ def to_frame(self, name: Hashable = lib.no_default) -> DataFrame: df = self._constructor_expanddim(mgr) return df.__finalize__(self, method="to_frame") - def _set_name(self, name, inplace=False) -> Series: + def _set_name(self, name, inplace: bool = False) -> Series: """ Set the Series name. @@ -2268,7 +2268,7 @@ def drop_duplicates( @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) def drop_duplicates( - self, keep: Literal["first", "last", False] = "first", inplace=False + self, keep: Literal["first", "last", False] = "first", inplace: bool = False ) -> Series | None: """ Return Series with duplicate values removed. @@ -4780,7 +4780,7 @@ def _reduce( name: str, *, axis=0, - skipna=True, + skipna: bool = True, numeric_only=None, filter_type=None, **kwds, diff --git a/pandas/core/sorting.py b/pandas/core/sorting.py index 16facfc915e40..29aa0761f89c9 100644 --- a/pandas/core/sorting.py +++ b/pandas/core/sorting.py @@ -52,7 +52,7 @@ def get_indexer_indexer( target: Index, level: Level | list[Level] | None, - ascending: Sequence[bool] | bool, + ascending: list[bool] | bool, kind: SortKind, na_position: NaPosition, sort_remaining: bool, diff --git a/pandas/core/strings/accessor.py b/pandas/core/strings/accessor.py index 46628eb3e17dd..ab5439188cd0e 100644 --- a/pandas/core/strings/accessor.py +++ b/pandas/core/strings/accessor.py @@ -260,7 +260,7 @@ def _wrap_result( name=None, expand: bool | None = None, fill_value=np.nan, - returns_string=True, + returns_string: bool = True, returns_bool: bool = False, ): from pandas import ( @@ -855,7 +855,7 @@ def split( self, pat: str | re.Pattern | None = None, n=-1, - expand=False, + expand: bool = False, *, regex: bool | None = None, ): @@ -883,7 +883,7 @@ def split( ) @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "pat"]) @forbid_nonstring_types(["bytes"]) - def rsplit(self, pat=None, n=-1, expand=False): + def rsplit(self, pat=None, n=-1, expand: bool = False): result = self._data.array._str_rsplit(pat, n=n) return self._wrap_result(result, expand=expand, returns_string=expand) @@ -979,7 +979,7 @@ def rsplit(self, pat=None, n=-1, expand=False): } ) @forbid_nonstring_types(["bytes"]) - def partition(self, sep=" ", expand=True): + def partition(self, sep=" ", expand: bool = True): result = self._data.array._str_partition(sep, expand) return self._wrap_result(result, expand=expand, returns_string=expand) @@ -993,7 +993,7 @@ def partition(self, sep=" ", expand=True): } ) @forbid_nonstring_types(["bytes"]) - def rpartition(self, sep=" ", expand=True): + def rpartition(self, sep=" ", expand: bool = True): result = self._data.array._str_rpartition(sep, expand) return self._wrap_result(result, expand=expand, returns_string=expand) @@ -1127,7 +1127,7 @@ def join(self, sep): return self._wrap_result(result) @forbid_nonstring_types(["bytes"]) - def contains(self, pat, case=True, flags=0, na=None, regex=True): + def contains(self, pat, case: bool = True, flags=0, na=None, regex: bool = True): r""" Test if pattern or regex is contained within a string of a Series or Index. @@ -1263,7 +1263,7 @@ def contains(self, pat, case=True, flags=0, na=None, regex=True): return self._wrap_result(result, fill_value=na, returns_string=False) @forbid_nonstring_types(["bytes"]) - def match(self, pat, case=True, flags=0, na=None): + def match(self, pat, case: bool = True, flags=0, na=None): """ Determine if each string starts with a match of a regular expression. @@ -1295,7 +1295,7 @@ def match(self, pat, case=True, flags=0, na=None): return self._wrap_result(result, fill_value=na, returns_string=False) @forbid_nonstring_types(["bytes"]) - def fullmatch(self, pat, case=True, flags=0, na=None): + def fullmatch(self, pat, case: bool = True, flags=0, na=None): """ Determine if each string entirely matches a regular expression. diff --git a/pandas/core/strings/base.py b/pandas/core/strings/base.py index ef0c3f8c2321d..ae9a480ef73be 100644 --- a/pandas/core/strings/base.py +++ b/pandas/core/strings/base.py @@ -44,7 +44,9 @@ def _str_pad(self, width, side="left", fillchar=" "): pass @abc.abstractmethod - def _str_contains(self, pat, case=True, flags=0, na=None, regex=True): + def _str_contains( + self, pat, case: bool = True, flags=0, na=None, regex: bool = True + ): pass @abc.abstractmethod @@ -236,7 +238,7 @@ def _str_removesuffix(self, suffix: str) -> Series: pass @abc.abstractmethod - def _str_split(self, pat=None, n=-1, expand=False): + def _str_split(self, pat=None, n=-1, expand: bool = False): pass @abc.abstractmethod diff --git a/pandas/core/strings/object_array.py b/pandas/core/strings/object_array.py index 407357d2c79e3..26843146b3633 100644 --- a/pandas/core/strings/object_array.py +++ b/pandas/core/strings/object_array.py @@ -114,7 +114,9 @@ def _str_pad(self, width, side="left", fillchar=" "): raise ValueError("Invalid side") return self._str_map(f) - def _str_contains(self, pat, case=True, flags=0, na=np.nan, regex: bool = True): + def _str_contains( + self, pat, case: bool = True, flags=0, na=np.nan, regex: bool = True + ): if regex: if not case: flags |= re.IGNORECASE @@ -310,7 +312,7 @@ def _str_split( self, pat: str | re.Pattern | None = None, n=-1, - expand=False, + expand: bool = False, regex: bool | None = None, ): if pat is None: diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index 78e12c96ceee8..565d2f2897514 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -1306,7 +1306,7 @@ def calc_with_mask(carg, mask): return None -def to_time(arg, format=None, infer_time_format=False, errors="raise"): +def to_time(arg, format=None, infer_time_format: bool = False, errors="raise"): # GH#34145 warnings.warn( "`to_time` has been moved, should be imported from pandas.core.tools.times. " diff --git a/pandas/core/tools/times.py b/pandas/core/tools/times.py index 87667921bf75a..bb100fab0ba8d 100644 --- a/pandas/core/tools/times.py +++ b/pandas/core/tools/times.py @@ -16,7 +16,7 @@ from pandas.core.dtypes.missing import notna -def to_time(arg, format=None, infer_time_format=False, errors="raise"): +def to_time(arg, format=None, infer_time_format: bool = False, errors="raise"): """ Parse time strings to time objects using fixed strptime formats ("%H:%M", "%H%M", "%I:%M%p", "%I%M%p", "%H:%M:%S", "%H%M%S", "%I:%M:%S%p", diff --git a/pandas/core/window/common.py b/pandas/core/window/common.py index 29b7558f40353..e67cf45cec8a1 100644 --- a/pandas/core/window/common.py +++ b/pandas/core/window/common.py @@ -18,7 +18,7 @@ from pandas.core.indexes.api import MultiIndex -def flex_binary_moment(arg1, arg2, f, pairwise=False): +def flex_binary_moment(arg1, arg2, f, pairwise: bool = False): if isinstance(arg1, ABCSeries) and isinstance(arg2, ABCSeries): X, Y = prep_binary(arg1, arg2) diff --git a/pandas/io/parquet.py b/pandas/io/parquet.py index d0ec419c3b392..b4abd6aea6b20 100644 --- a/pandas/io/parquet.py +++ b/pandas/io/parquet.py @@ -210,7 +210,7 @@ def read( self, path, columns=None, - use_nullable_dtypes=False, + use_nullable_dtypes: bool = False, storage_options: StorageOptions = None, **kwargs, ) -> DataFrame: diff --git a/pandas/io/parsers/base_parser.py b/pandas/io/parsers/base_parser.py index 89bf903fea8dd..f90a0549a4320 100644 --- a/pandas/io/parsers/base_parser.py +++ b/pandas/io/parsers/base_parser.py @@ -679,7 +679,7 @@ def _set(x) -> int: return noconvert_columns - def _infer_types(self, values, na_values, try_num_bool=True): + def _infer_types(self, values, na_values, try_num_bool: bool = True): """ Infer types of values, possibly casting @@ -1055,7 +1055,10 @@ def _get_empty_meta( def _make_date_converter( - date_parser=None, dayfirst=False, infer_datetime_format=False, cache_dates=True + date_parser=None, + dayfirst: bool = False, + infer_datetime_format: bool = False, + cache_dates: bool = True, ): def converter(*date_cols): if date_parser is None: diff --git a/pandas/io/parsers/readers.py b/pandas/io/parsers/readers.py index 249831a7dc579..20122d69748aa 100644 --- a/pandas/io/parsers/readers.py +++ b/pandas/io/parsers/readers.py @@ -640,7 +640,7 @@ def read_csv( na_filter: bool = ..., verbose: bool = ..., skip_blank_lines: bool = ..., - parse_dates=..., + parse_dates: bool | Sequence[Hashable] | None = ..., infer_datetime_format: bool = ..., keep_date_col: bool = ..., date_parser=..., @@ -700,7 +700,7 @@ def read_csv( na_filter: bool = ..., verbose: bool = ..., skip_blank_lines: bool = ..., - parse_dates=..., + parse_dates: bool | Sequence[Hashable] | None = ..., infer_datetime_format: bool = ..., keep_date_col: bool = ..., date_parser=..., @@ -760,7 +760,7 @@ def read_csv( na_filter: bool = ..., verbose: bool = ..., skip_blank_lines: bool = ..., - parse_dates=..., + parse_dates: bool | Sequence[Hashable] | None = ..., infer_datetime_format: bool = ..., keep_date_col: bool = ..., date_parser=..., @@ -820,7 +820,7 @@ def read_csv( na_filter: bool = ..., verbose: bool = ..., skip_blank_lines: bool = ..., - parse_dates=..., + parse_dates: bool | Sequence[Hashable] | None = ..., infer_datetime_format: bool = ..., keep_date_col: bool = ..., date_parser=..., @@ -893,7 +893,7 @@ def read_csv( verbose: bool = False, skip_blank_lines: bool = True, # Datetime Handling - parse_dates=None, + parse_dates: bool | Sequence[Hashable] | None = None, infer_datetime_format: bool = False, keep_date_col: bool = False, date_parser=None, @@ -979,7 +979,7 @@ def read_table( na_filter: bool = ..., verbose: bool = ..., skip_blank_lines: bool = ..., - parse_dates=..., + parse_dates: bool | Sequence[Hashable] = ..., infer_datetime_format: bool = ..., keep_date_col: bool = ..., date_parser=..., @@ -1002,7 +1002,7 @@ def read_table( error_bad_lines: bool | None = ..., warn_bad_lines: bool | None = ..., on_bad_lines=..., - delim_whitespace=..., + delim_whitespace: bool = ..., low_memory=..., memory_map: bool = ..., float_precision: str | None = ..., @@ -1039,7 +1039,7 @@ def read_table( na_filter: bool = ..., verbose: bool = ..., skip_blank_lines: bool = ..., - parse_dates=..., + parse_dates: bool | Sequence[Hashable] = ..., infer_datetime_format: bool = ..., keep_date_col: bool = ..., date_parser=..., @@ -1062,7 +1062,7 @@ def read_table( error_bad_lines: bool | None = ..., warn_bad_lines: bool | None = ..., on_bad_lines=..., - delim_whitespace=..., + delim_whitespace: bool = ..., low_memory=..., memory_map: bool = ..., float_precision: str | None = ..., @@ -1099,7 +1099,7 @@ def read_table( na_filter: bool = ..., verbose: bool = ..., skip_blank_lines: bool = ..., - parse_dates=..., + parse_dates: bool | Sequence[Hashable] = ..., infer_datetime_format: bool = ..., keep_date_col: bool = ..., date_parser=..., @@ -1122,7 +1122,7 @@ def read_table( error_bad_lines: bool | None = ..., warn_bad_lines: bool | None = ..., on_bad_lines=..., - delim_whitespace=..., + delim_whitespace: bool = ..., low_memory=..., memory_map: bool = ..., float_precision: str | None = ..., @@ -1159,7 +1159,7 @@ def read_table( na_filter: bool = ..., verbose: bool = ..., skip_blank_lines: bool = ..., - parse_dates=..., + parse_dates: bool | Sequence[Hashable] = ..., infer_datetime_format: bool = ..., keep_date_col: bool = ..., date_parser=..., @@ -1182,7 +1182,7 @@ def read_table( error_bad_lines: bool | None = ..., warn_bad_lines: bool | None = ..., on_bad_lines=..., - delim_whitespace=..., + delim_whitespace: bool = ..., low_memory=..., memory_map: bool = ..., float_precision: str | None = ..., @@ -1232,7 +1232,7 @@ def read_table( verbose: bool = False, skip_blank_lines: bool = True, # Datetime Handling - parse_dates=False, + parse_dates: bool | Sequence[Hashable] = False, infer_datetime_format: bool = False, keep_date_col: bool = False, date_parser=None, @@ -1261,7 +1261,7 @@ def read_table( # See _refine_defaults_read comment for why we do this. on_bad_lines=None, # Internal - delim_whitespace=False, + delim_whitespace: bool = False, low_memory=_c_parser_defaults["low_memory"], memory_map: bool = False, float_precision: str | None = None, @@ -1876,7 +1876,7 @@ def TextParser(*args, **kwds) -> TextFileReader: return TextFileReader(*args, **kwds) -def _clean_na_values(na_values, keep_default_na=True): +def _clean_na_values(na_values, keep_default_na: bool = True): na_fvalues: set | dict if na_values is None: if keep_default_na: diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 9ac1bd3ed6491..f3f3778c1fcbe 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -809,7 +809,7 @@ def select( start=None, stop=None, columns=None, - iterator=False, + iterator: bool = False, chunksize=None, auto_close: bool = False, ): @@ -957,7 +957,7 @@ def select_as_multiple( columns=None, start=None, stop=None, - iterator=False, + iterator: bool = False, chunksize=None, auto_close: bool = False, ): @@ -1076,8 +1076,8 @@ def put( key: str, value: DataFrame | Series, format=None, - index=True, - append=False, + index: bool = True, + append: bool = False, complib=None, complevel: int | None = None, min_itemsize: int | dict[str, int] | None = None, @@ -1206,8 +1206,8 @@ def append( value: DataFrame | Series, format=None, axes=None, - index=True, - append=True, + index: bool | list[str] = True, + append: bool = True, complib=None, complevel: int | None = None, columns=None, @@ -1295,7 +1295,7 @@ def append_to_multiple( selector, data_columns=None, axes=None, - dropna=False, + dropna: bool = False, **kwargs, ) -> None: """ @@ -1536,7 +1536,7 @@ def copy( complib=None, complevel: int | None = None, fletcher32: bool = False, - overwrite=True, + overwrite: bool = True, ) -> HDFStore: """ Copy the existing store to a new file, updating in place. @@ -1742,15 +1742,15 @@ def _write_to_group( value: DataFrame | Series, format, axes=None, - index=True, - append=False, + index: bool | list[str] = True, + append: bool = False, complib=None, complevel: int | None = None, fletcher32=None, min_itemsize: int | dict[str, int] | None = None, chunksize=None, expectedrows=None, - dropna=False, + dropna: bool = False, nan_rep=None, data_columns=None, encoding=None, @@ -4324,7 +4324,7 @@ def write( # type: ignore[override] dropna: bool = False, nan_rep=None, data_columns=None, - track_times=True, + track_times: bool = True, ) -> None: if not append and self.is_exists: self._handle.remove_node(self.group, "table") diff --git a/pandas/io/sql.py b/pandas/io/sql.py index f19743d564b71..4bc2de32a20d5 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -1290,7 +1290,7 @@ def insert_records( con, frame, name, - index=True, + index: bool | str | list[str] | None = True, schema=None, chunksize=None, method=None, @@ -1314,7 +1314,7 @@ def insert_records( con, frame, name, - index=True, + index: bool | str | list[str] | None = True, schema=None, chunksize=None, method=None, @@ -1471,7 +1471,7 @@ def _query_iterator( chunksize: int, columns, index_col=None, - coerce_float=True, + coerce_float: bool = True, parse_dates=None, dtype: DtypeArg | None = None, ): @@ -1590,7 +1590,7 @@ def prep_table( frame, name, if_exists="fail", - index=True, + index: bool | str | list[str] | None = True, index_label=None, schema=None, dtype: DtypeArg | None = None, diff --git a/pandas/io/stata.py b/pandas/io/stata.py index f51b46e1c4783..6baf5f0da8612 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -414,7 +414,9 @@ def _datetime_to_stata_elapsed_vec(dates: Series, fmt: str) -> Series: NS_PER_DAY = 24 * 3600 * 1000 * 1000 * 1000 US_PER_DAY = NS_PER_DAY / 1000 - def parse_dates_safe(dates, delta=False, year=False, days=False): + def parse_dates_safe( + dates, delta: bool = False, year: bool = False, days: bool = False + ): d = {} if is_datetime64_dtype(dates.dtype): if delta: diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 4120afd559da0..3c9d82bf46d11 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1485,7 +1485,7 @@ def kde(self, bw_method=None, ind=None, **kwargs) -> PlotAccessor: density = kde - def area(self, x=None, y=None, stacked=True, **kwargs) -> PlotAccessor: + def area(self, x=None, y=None, stacked: bool = True, **kwargs) -> PlotAccessor: """ Draw a stacked area plot. diff --git a/pandas/plotting/_matplotlib/boxplot.py b/pandas/plotting/_matplotlib/boxplot.py index cd34f2264f44f..ae61a9743ca1d 100644 --- a/pandas/plotting/_matplotlib/boxplot.py +++ b/pandas/plotting/_matplotlib/boxplot.py @@ -234,8 +234,8 @@ def _grouped_plot_by_column( data, columns=None, by=None, - numeric_only=True, - grid=False, + numeric_only: bool = True, + grid: bool = False, figsize=None, ax=None, layout=None, diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index 62a9a5946c5c8..a02e81935f696 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -417,7 +417,7 @@ def _validate_color_args(self): "other or pass 'style' without a color symbol" ) - def _iter_data(self, data=None, keep_index=False, fillna=None): + def _iter_data(self, data=None, keep_index: bool = False, fillna=None): if data is None: data = self.data if fillna is not None: @@ -911,7 +911,7 @@ def _get_index_name(self) -> str | None: return name @classmethod - def _get_ax_layer(cls, ax, primary=True): + def _get_ax_layer(cls, ax, primary: bool = True): """get left (primary) or right (secondary) axes""" if primary: return getattr(ax, "left_ax", ax) @@ -1087,7 +1087,9 @@ def match_labels(data, e): return err - def _get_errorbars(self, label=None, index=None, xerr=True, yerr=True): + def _get_errorbars( + self, label=None, index=None, xerr: bool = True, yerr: bool = True + ): errors = {} for kw, flag in zip(["xerr", "yerr"], [xerr, yerr]): @@ -1645,7 +1647,7 @@ def _args_adjust(self) -> None: # error: Signature of "_plot" incompatible with supertype "MPLPlot" @classmethod def _plot( # type: ignore[override] - cls, ax: Axes, x, y, w, start=0, log=False, **kwds + cls, ax: Axes, x, y, w, start=0, log: bool = False, **kwds ): return ax.bar(x, y, w, bottom=start, log=log, **kwds) @@ -1771,7 +1773,7 @@ def _start_base(self): # error: Signature of "_plot" incompatible with supertype "MPLPlot" @classmethod def _plot( # type: ignore[override] - cls, ax: Axes, x, y, w, start=0, log=False, **kwds + cls, ax: Axes, x, y, w, start=0, log: bool = False, **kwds ): return ax.barh(x, y, w, left=start, log=log, **kwds) diff --git a/pandas/plotting/_matplotlib/hist.py b/pandas/plotting/_matplotlib/hist.py index 2106e05a817ce..1bebea357ad68 100644 --- a/pandas/plotting/_matplotlib/hist.py +++ b/pandas/plotting/_matplotlib/hist.py @@ -252,10 +252,10 @@ def _grouped_plot( data, column=None, by=None, - numeric_only=True, + numeric_only: bool = True, figsize=None, - sharex=True, - sharey=True, + sharex: bool = True, + sharey: bool = True, layout=None, rot=0, ax=None, @@ -298,15 +298,15 @@ def _grouped_hist( bins=50, figsize=None, layout=None, - sharex=False, - sharey=False, + sharex: bool = False, + sharey: bool = False, rot=90, - grid=True, + grid: bool = True, xlabelsize=None, xrot=None, ylabelsize=None, yrot=None, - legend=False, + legend: bool = False, **kwargs, ): """ diff --git a/pandas/tseries/holiday.py b/pandas/tseries/holiday.py index 158db45996f4d..a8e55c4c2522f 100644 --- a/pandas/tseries/holiday.py +++ b/pandas/tseries/holiday.py @@ -242,7 +242,7 @@ def __repr__(self) -> str: repr = f"Holiday: {self.name} ({info})" return repr - def dates(self, start_date, end_date, return_name=False): + def dates(self, start_date, end_date, return_name: bool = False): """ Calculate holidays observed between start date and end date @@ -420,7 +420,7 @@ def rule_from_name(self, name): return None - def holidays(self, start=None, end=None, return_name=False): + def holidays(self, start=None, end=None, return_name: bool = False): """ Returns a curve with holidays between start_date and end_date @@ -506,7 +506,7 @@ def merge_class(base, other): other_holidays.update(base_holidays) return list(other_holidays.values()) - def merge(self, other, inplace=False): + def merge(self, other, inplace: bool = False): """ Merge holiday calendars together. The caller's class rules take precedence. The merge will be done diff --git a/pandas/util/_validators.py b/pandas/util/_validators.py index 2b5be2d48f382..30314bf2529c5 100644 --- a/pandas/util/_validators.py +++ b/pandas/util/_validators.py @@ -225,7 +225,7 @@ def validate_args_and_kwargs( def validate_bool_kwarg( - value: BoolishNoneT, arg_name, none_allowed=True, int_allowed=False + value: BoolishNoneT, arg_name, none_allowed: bool = True, int_allowed: bool = False ) -> BoolishNoneT: """ Ensure that argument passed in arg_name can be interpreted as boolean. diff --git a/pyright_reportGeneralTypeIssues.json b/pyright_reportGeneralTypeIssues.json index 4a82c579262e3..940364e580d12 100644 --- a/pyright_reportGeneralTypeIssues.json +++ b/pyright_reportGeneralTypeIssues.json @@ -31,6 +31,7 @@ "pandas/core/arrays/interval.py", "pandas/core/arrays/masked.py", "pandas/core/arrays/period.py", + "pandas/core/arrays/sparse/accessor.py", "pandas/core/arrays/sparse/array.py", "pandas/core/arrays/sparse/dtype.py", "pandas/core/arrays/string_.py", @@ -108,6 +109,8 @@ "pandas/io/sql.py", "pandas/io/stata.py", "pandas/io/xml.py", + "pandas/plotting/_matplotlib/boxplot.py", "pandas/tseries/frequencies.py", + "pandas/tseries/holiday.py", ], }