From f93f9f37a4ab8926f535094ba59595864c1d8ff0 Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Fri, 24 Jun 2022 20:06:27 +0200 Subject: [PATCH 1/2] add some -> to pandas core --- pandas/core/array_algos/replace.py | 2 +- pandas/core/array_algos/take.py | 8 ++++---- pandas/core/arrays/_mixins.py | 2 +- pandas/core/arrays/arrow/_arrow_utils.py | 2 +- pandas/core/arrays/base.py | 6 +++--- pandas/core/arrays/categorical.py | 12 ++++++------ pandas/core/arrays/datetimelike.py | 6 +++--- pandas/core/arrays/datetimes.py | 2 +- pandas/core/arrays/interval.py | 4 ++-- pandas/core/arrays/period.py | 2 +- pandas/core/arrays/sparse/accessor.py | 4 ++-- pandas/core/arrays/sparse/array.py | 8 ++++---- pandas/core/arrays/sparse/dtype.py | 2 +- pandas/core/arrays/sparse/scipy_sparse.py | 2 +- pandas/core/arrays/string_.py | 4 ++-- pandas/core/arrays/timedeltas.py | 2 +- pandas/core/base.py | 4 ++-- pandas/core/common.py | 6 ++++-- pandas/core/computation/eval.py | 8 ++++---- pandas/core/computation/expressions.py | 4 ++-- pandas/core/computation/ops.py | 8 ++++---- pandas/core/computation/pytables.py | 4 ++-- pandas/core/config_init.py | 18 +++++++++--------- pandas/core/dtypes/cast.py | 4 ++-- pandas/core/dtypes/dtypes.py | 4 ++-- pandas/core/dtypes/missing.py | 2 +- pandas/core/flags.py | 4 ++-- pandas/core/frame.py | 4 ++-- pandas/core/generic.py | 8 ++++---- pandas/core/groupby/grouper.py | 2 +- pandas/core/groupby/ops.py | 2 +- pandas/core/indexes/base.py | 14 +++++++------- pandas/core/indexes/extension.py | 2 +- pandas/core/indexes/multi.py | 2 +- pandas/core/indexes/range.py | 2 +- pandas/core/indexing.py | 22 ++++++++++++---------- pandas/core/internals/array_manager.py | 6 +++--- pandas/core/internals/blocks.py | 4 ++-- pandas/core/internals/concat.py | 2 +- pandas/core/internals/managers.py | 8 ++++---- pandas/core/internals/ops.py | 2 +- pandas/core/missing.py | 2 +- pandas/core/ops/array_ops.py | 2 +- pandas/core/ops/invalid.py | 2 +- pandas/core/ops/mask_ops.py | 2 +- pandas/core/ops/methods.py | 4 ++-- pandas/core/reshape/concat.py | 2 +- pandas/core/reshape/encoding.py | 2 +- pandas/core/reshape/reshape.py | 2 +- pandas/core/series.py | 4 ++-- pandas/core/window/ewm.py | 2 +- pandas/core/window/online.py | 2 +- pandas/core/window/rolling.py | 10 +++++----- 53 files changed, 127 insertions(+), 123 deletions(-) diff --git a/pandas/core/array_algos/replace.py b/pandas/core/array_algos/replace.py index 19a44dbfe6f6d..1192191512e10 100644 --- a/pandas/core/array_algos/replace.py +++ b/pandas/core/array_algos/replace.py @@ -67,7 +67,7 @@ def compare_or_regex_search( def _check_comparison_types( result: ArrayLike | bool, a: ArrayLike, b: Scalar | Pattern - ): + ) -> None: """ Raises an error if the two arrays (a,b) cannot be compared. Otherwise, returns the comparison result as expected. diff --git a/pandas/core/array_algos/take.py b/pandas/core/array_algos/take.py index 188725f003f1e..6f7d7d85c4f2c 100644 --- a/pandas/core/array_algos/take.py +++ b/pandas/core/array_algos/take.py @@ -337,7 +337,7 @@ def _get_take_nd_function( if func is None: - def func(arr, indexer, out, fill_value=np.nan): + def func(arr, indexer, out, fill_value=np.nan) -> None: indexer = ensure_platform_int(indexer) _take_nd_object( arr, indexer, out, axis=axis, fill_value=fill_value, mask_info=mask_info @@ -349,7 +349,7 @@ def func(arr, indexer, out, fill_value=np.nan): def _view_wrapper(f, arr_dtype=None, out_dtype=None, fill_wrap=None): def wrapper( arr: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=np.nan - ): + ) -> None: if arr_dtype is not None: arr = arr.view(arr_dtype) if out_dtype is not None: @@ -364,7 +364,7 @@ def wrapper( def _convert_wrapper(f, conv_dtype): def wrapper( arr: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=np.nan - ): + ) -> None: if conv_dtype == object: # GH#39755 avoid casting dt64/td64 to integers arr = ensure_wrapped_if_datetimelike(arr) @@ -506,7 +506,7 @@ def _take_nd_object( axis: int, fill_value, mask_info, -): +) -> None: if mask_info is not None: mask, needs_masking = mask_info else: diff --git a/pandas/core/arrays/_mixins.py b/pandas/core/arrays/_mixins.py index b15e0624963ea..45bd1c583f4d5 100644 --- a/pandas/core/arrays/_mixins.py +++ b/pandas/core/arrays/_mixins.py @@ -259,7 +259,7 @@ def _validate_shift_value(self, fill_value): # we can remove this and use validate_fill_value directly return self._validate_scalar(fill_value) - def __setitem__(self, key, value): + def __setitem__(self, key, value) -> None: key = check_array_indexer(self, key) value = self._validate_setitem_value(value) self._ndarray[key] = value diff --git a/pandas/core/arrays/arrow/_arrow_utils.py b/pandas/core/arrays/arrow/_arrow_utils.py index e0f242e2ced5d..ac7e31339e37b 100644 --- a/pandas/core/arrays/arrow/_arrow_utils.py +++ b/pandas/core/arrays/arrow/_arrow_utils.py @@ -14,7 +14,7 @@ from pandas.core.arrays.interval import VALID_CLOSED -def fallback_performancewarning(version: str | None = None): +def fallback_performancewarning(version: str | None = None) -> None: """ Raise a PerformanceWarning for falling back to ExtensionArray's non-pyarrow method diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index eb3c6d6d26101..1484e656e8082 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -1656,7 +1656,7 @@ def _create_arithmetic_method(cls, op): raise AbstractMethodError(cls) @classmethod - def _add_arithmetic_ops(cls): + def _add_arithmetic_ops(cls) -> None: setattr(cls, "__add__", cls._create_arithmetic_method(operator.add)) setattr(cls, "__radd__", cls._create_arithmetic_method(roperator.radd)) setattr(cls, "__sub__", cls._create_arithmetic_method(operator.sub)) @@ -1681,7 +1681,7 @@ def _create_comparison_method(cls, op): raise AbstractMethodError(cls) @classmethod - def _add_comparison_ops(cls): + def _add_comparison_ops(cls) -> None: setattr(cls, "__eq__", cls._create_comparison_method(operator.eq)) setattr(cls, "__ne__", cls._create_comparison_method(operator.ne)) setattr(cls, "__lt__", cls._create_comparison_method(operator.lt)) @@ -1694,7 +1694,7 @@ def _create_logical_method(cls, op): raise AbstractMethodError(cls) @classmethod - def _add_logical_ops(cls): + def _add_logical_ops(cls) -> None: setattr(cls, "__and__", cls._create_logical_method(operator.and_)) setattr(cls, "__rand__", cls._create_logical_method(roperator.rand_)) setattr(cls, "__or__", cls._create_logical_method(operator.or_)) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 70699c45e0c36..ddc70889ba607 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -738,7 +738,7 @@ def categories(self): return self.dtype.categories @categories.setter - def categories(self, categories): + def categories(self, categories) -> None: new_dtype = CategoricalDtype(categories, ordered=self.ordered) if self.dtype.categories is not None and len(self.dtype.categories) != len( new_dtype.categories @@ -776,7 +776,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=False) -> None: """ Sets new categories inplace @@ -1700,7 +1700,7 @@ def _internal_get_values(self): return self.categories.astype("object").take(self._codes, fill_value=np.nan) return np.array(self) - def check_for_ordered(self, op): + def check_for_ordered(self, op) -> None: """assert that we are ordered""" if not self.ordered: raise TypeError( @@ -1931,7 +1931,7 @@ def _codes(self) -> np.ndarray: return self._ndarray @_codes.setter - def _codes(self, value: np.ndarray): + def _codes(self, value: np.ndarray) -> None: warn( "Setting the codes on a Categorical is deprecated and will raise in " "a future version. Create a new Categorical object instead", @@ -1985,7 +1985,7 @@ def __contains__(self, key) -> bool: # ------------------------------------------------------------------ # Rendering Methods - def _formatter(self, boxed: bool = False): + def _formatter(self, boxed: bool = False) -> None: # Defer to CategoricalFormatter's formatter. return None @@ -2713,7 +2713,7 @@ def __init__(self, data) -> None: self._freeze() @staticmethod - def _validate(data): + def _validate(data) -> None: if not is_categorical_dtype(data.dtype): raise AttributeError("Can only use .cat accessor with a 'category' dtype") diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index f7de291f83d03..ee2d5b5560843 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -410,7 +410,7 @@ def __setitem__( # type: ignore[override] self._maybe_clear_freq() - def _maybe_clear_freq(self): + def _maybe_clear_freq(self) -> None: # inplace operations like __setitem__ may invalidate the freq of # DatetimeArray and TimedeltaArray pass @@ -924,7 +924,7 @@ def freq(self): return self._freq @freq.setter - def freq(self, value): + def freq(self, value) -> None: if value is not None: value = to_offset(value) self._validate_frequency(self, value) @@ -976,7 +976,7 @@ def resolution(self) -> str: return self._resolution_obj.attrname # type: ignore[union-attr] @classmethod - def _validate_frequency(cls, index, freq, **kwargs): + def _validate_frequency(cls, index, freq, **kwargs) -> None: """ Validate that a frequency is compatible with the values of a given Datetime Array/Index or Timedelta Array/Index diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 5f060542526d3..80ae7bbedd4ff 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -520,7 +520,7 @@ def _unbox_scalar(self, value, setitem: bool = False) -> np.datetime64: def _scalar_from_string(self, value) -> Timestamp | NaTType: return Timestamp(value, tz=self.tz) - def _check_compatible_with(self, other, setitem: bool = False): + def _check_compatible_with(self, other, setitem: bool = False) -> None: if other is NaT: return self._assert_tzawareness_compat(other) diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index 1015a54826ac8..0e1a294b282e4 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -598,7 +598,7 @@ def from_tuples( return cls.from_arrays(left, right, inclusive, copy=False, dtype=dtype) - def _validate(self): + def _validate(self) -> None: """ Verify that the IntervalArray is valid. @@ -692,7 +692,7 @@ def __getitem__( raise ValueError("multi-dimensional indexing not allowed") return self._shallow_copy(left, right) - def __setitem__(self, key, value): + def __setitem__(self, key, value) -> None: value_left, value_right = self._validate_setitem_value(value) key = check_array_indexer(self, key) diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index 291810c5db2f9..09ec01ddbb26a 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -336,7 +336,7 @@ def _unbox_scalar( # type: ignore[override] def _scalar_from_string(self, value: str) -> Period: return Period(value, freq=self.freq) - def _check_compatible_with(self, other, setitem: bool = False): + def _check_compatible_with(self, other, setitem: bool = False) -> None: if other is NaT: return self._require_matching_freq(other) diff --git a/pandas/core/arrays/sparse/accessor.py b/pandas/core/arrays/sparse/accessor.py index 41af7d4ccd506..0fb8b4413b1d2 100644 --- a/pandas/core/arrays/sparse/accessor.py +++ b/pandas/core/arrays/sparse/accessor.py @@ -33,7 +33,7 @@ class SparseAccessor(BaseAccessor, PandasDelegate): Accessor for SparseSparse from other sparse matrix data types. """ - def _validate(self, data): + def _validate(self, data) -> None: if not isinstance(data.dtype, SparseDtype): raise AttributeError(self._validation_msg) @@ -222,7 +222,7 @@ class SparseFrameAccessor(BaseAccessor, PandasDelegate): .. versionadded:: 0.25.0 """ - def _validate(self, data): + def _validate(self, data) -> None: dtypes = data.dtypes if not all(isinstance(t, SparseDtype) for t in dtypes): raise AttributeError(self._validation_msg) diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index 0c34229fb5080..c51864bce2236 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -605,7 +605,7 @@ def __array__(self, dtype: NpDtype | None = None) -> np.ndarray: out[self.sp_index.indices] = self.sp_values return out - def __setitem__(self, key, value): + def __setitem__(self, key, value) -> None: # I suppose we could allow setting of non-fill_value elements. # TODO(SparseArray.__setitem__): remove special cases in # ExtensionBlock.where @@ -657,7 +657,7 @@ def fill_value(self): return self.dtype.fill_value @fill_value.setter - def fill_value(self, value): + def fill_value(self, value) -> None: self._dtype = SparseDtype(self.dtype.subtype, value) @property @@ -1381,7 +1381,7 @@ def _where(self, mask, value): # ------------------------------------------------------------------------ # IO # ------------------------------------------------------------------------ - def __setstate__(self, state): + def __setstate__(self, state) -> None: """Necessary for making this object picklable""" if isinstance(state, tuple): # Compat for pandas < 0.24.0 @@ -1795,7 +1795,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=False) -> None: # 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/sparse/dtype.py b/pandas/core/arrays/sparse/dtype.py index b6bb5faeebdee..652c9f3020759 100644 --- a/pandas/core/arrays/sparse/dtype.py +++ b/pandas/core/arrays/sparse/dtype.py @@ -148,7 +148,7 @@ def fill_value(self): """ return self._fill_value - def _check_fill_value(self): + def _check_fill_value(self) -> None: if not is_scalar(self._fill_value): raise ValueError( f"fill_value must be a scalar. Got {self._fill_value} instead" diff --git a/pandas/core/arrays/sparse/scipy_sparse.py b/pandas/core/arrays/sparse/scipy_sparse.py index 88e1778d4c854..efe5ffb416a2e 100644 --- a/pandas/core/arrays/sparse/scipy_sparse.py +++ b/pandas/core/arrays/sparse/scipy_sparse.py @@ -28,7 +28,7 @@ import scipy.sparse -def _check_is_partition(parts: Iterable, whole: Iterable): +def _check_is_partition(parts: Iterable, whole: Iterable) -> None: whole = set(whole) parts = [set(x) for x in parts] if set.intersection(*parts) != set(): diff --git a/pandas/core/arrays/string_.py b/pandas/core/arrays/string_.py index 45683d83a1303..8880ea6ef5935 100644 --- a/pandas/core/arrays/string_.py +++ b/pandas/core/arrays/string_.py @@ -304,7 +304,7 @@ def __init__(self, values, copy=False) -> None: self._validate() NDArrayBacked.__init__(self, self._ndarray, StringDtype(storage="python")) - def _validate(self): + def _validate(self) -> None: """Validate that we only store NA or strings.""" if len(self._ndarray) and not lib.is_string_array(self._ndarray, skipna=True): raise ValueError("StringArray requires a sequence of strings or pandas.NA") @@ -379,7 +379,7 @@ def _values_for_factorize(self): arr[mask] = -1 return arr, -1 - def __setitem__(self, key, value): + def __setitem__(self, key, value) -> None: value = extract_array(value, extract_numpy=True) if isinstance(value, type(self)): # extract_array doesn't extract PandasArray subclasses diff --git a/pandas/core/arrays/timedeltas.py b/pandas/core/arrays/timedeltas.py index e08518a54fe6b..5902aecf263f3 100644 --- a/pandas/core/arrays/timedeltas.py +++ b/pandas/core/arrays/timedeltas.py @@ -439,7 +439,7 @@ def _format_native_types( # ---------------------------------------------------------------- # Arithmetic Methods - def _add_offset(self, other): + def _add_offset(self, other) -> None: assert not isinstance(other, Tick) raise TypeError( f"cannot add the type {type(other).__name__} to a {type(self).__name__}" diff --git a/pandas/core/base.py b/pandas/core/base.py index b4c2c81ee666f..a4931c7505cf8 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -154,14 +154,14 @@ class NoNewAttributesMixin: `object.__setattr__(self, key, value)`. """ - def _freeze(self): + def _freeze(self) -> None: """ Prevents setting additional attributes. """ object.__setattr__(self, "__frozen", True) # prevent adding any attribute via s.xxx.new_attribute = ... - def __setattr__(self, key: str, value): + def __setattr__(self, key: str, value) -> None: # _cache is used by a decorator # We need to check both 1.) cls.__dict__ and 2.) getattr(self, key) # because diff --git a/pandas/core/common.py b/pandas/core/common.py index 707201153e44a..980e7a79414ba 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -553,7 +553,7 @@ def temp_setattr(obj, attr: str, value) -> Iterator[None]: setattr(obj, attr, old_value) -def require_length_match(data, index: Index): +def require_length_match(data, index: Index) -> None: """ Check the length of data matches the length of the index. """ @@ -665,7 +665,9 @@ def resolve_numeric_only(numeric_only: bool | None | lib.NoDefault) -> bool: return result -def deprecate_numeric_only_default(cls: type, name: str, deprecate_none: bool = False): +def deprecate_numeric_only_default( + cls: type, name: str, deprecate_none: bool = False +) -> None: """Emit FutureWarning message for deprecation of numeric_only. See GH#46560 for details on the deprecation. diff --git a/pandas/core/computation/eval.py b/pandas/core/computation/eval.py index d82cc37b90ad4..9e3f2849a6b40 100644 --- a/pandas/core/computation/eval.py +++ b/pandas/core/computation/eval.py @@ -67,7 +67,7 @@ def _check_engine(engine: str | None) -> str: return engine -def _check_parser(parser: str): +def _check_parser(parser: str) -> None: """ Make sure a valid parser is passed. @@ -86,7 +86,7 @@ def _check_parser(parser: str): ) -def _check_resolvers(resolvers): +def _check_resolvers(resolvers) -> None: if resolvers is not None: for resolver in resolvers: if not hasattr(resolver, "__getitem__"): @@ -97,7 +97,7 @@ def _check_resolvers(resolvers): ) -def _check_expression(expr): +def _check_expression(expr) -> None: """ Make sure an expression is not an empty string @@ -144,7 +144,7 @@ def _convert_expression(expr) -> str: return s -def _check_for_locals(expr: str, stack_level: int, parser: str): +def _check_for_locals(expr: str, stack_level: int, parser: str) -> None: at_top_of_stack = stack_level == 0 not_pandas_parser = parser != "pandas" diff --git a/pandas/core/computation/expressions.py b/pandas/core/computation/expressions.py index 9e180f11c4211..e82bec47c6ac5 100644 --- a/pandas/core/computation/expressions.py +++ b/pandas/core/computation/expressions.py @@ -38,7 +38,7 @@ _MIN_ELEMENTS = 1_000_000 -def set_use_numexpr(v=True): +def set_use_numexpr(v=True) -> None: # set/unset to use numexpr global USE_NUMEXPR if NUMEXPR_INSTALLED: @@ -51,7 +51,7 @@ def set_use_numexpr(v=True): _where = _where_numexpr if USE_NUMEXPR else _where_standard -def set_numexpr_threads(n=None): +def set_numexpr_threads(n=None) -> None: # if we are using numexpr, set the threads to n # otherwise reset if NUMEXPR_INSTALLED and USE_NUMEXPR: diff --git a/pandas/core/computation/ops.py b/pandas/core/computation/ops.py index 3a556b57ea5a5..4215cc927ebf3 100644 --- a/pandas/core/computation/ops.py +++ b/pandas/core/computation/ops.py @@ -107,7 +107,7 @@ def _resolve_name(self): ) return res - def update(self, value): + def update(self, value) -> None: """ search order for local (i.e., @variable) variables: @@ -162,7 +162,7 @@ def value(self): return self._value @value.setter - def value(self, new_value): + def value(self, new_value) -> None: self._value = new_value @property @@ -321,7 +321,7 @@ def _not_in(x, y): _binary_ops_dict.update(d) -def _cast_inplace(terms, acceptable_dtypes, dtype): +def _cast_inplace(terms, acceptable_dtypes, dtype) -> None: """ Cast an expression inplace. @@ -480,7 +480,7 @@ def stringify(value): v = v.tz_convert("UTC") self.lhs.update(v) - def _disallow_scalar_only_bool_ops(self): + def _disallow_scalar_only_bool_ops(self) -> None: rhs = self.rhs lhs = self.lhs diff --git a/pandas/core/computation/pytables.py b/pandas/core/computation/pytables.py index 29af322ba0b42..7601f607b7311 100644 --- a/pandas/core/computation/pytables.py +++ b/pandas/core/computation/pytables.py @@ -107,7 +107,7 @@ def __init__(self, op: str, lhs, rhs, queryables: dict[str, Any], encoding) -> N self.encoding = encoding self.condition = None - def _disallow_scalar_only_bool_ops(self): + def _disallow_scalar_only_bool_ops(self) -> None: pass def prune(self, klass): @@ -256,7 +256,7 @@ def stringify(value): else: raise TypeError(f"Cannot compare {v} of type {type(v)} to {kind} column") - def convert_values(self): + def convert_values(self) -> None: pass diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index 47cf64ba24022..6413a09f30ffd 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -37,7 +37,7 @@ """ -def use_bottleneck_cb(key): +def use_bottleneck_cb(key) -> None: from pandas.core import nanops nanops.set_use_bottleneck(cf.get_option(key)) @@ -51,7 +51,7 @@ def use_bottleneck_cb(key): """ -def use_numexpr_cb(key): +def use_numexpr_cb(key) -> None: from pandas.core.computation import expressions expressions.set_use_numexpr(cf.get_option(key)) @@ -65,7 +65,7 @@ def use_numexpr_cb(key): """ -def use_numba_cb(key): +def use_numba_cb(key) -> None: from pandas.core.util import numba_ numba_.set_use_numba(cf.get_option(key)) @@ -329,7 +329,7 @@ def use_numba_cb(key): """ -def table_schema_cb(key): +def table_schema_cb(key) -> None: from pandas.io.formats.printing import enable_data_resource_formatter enable_data_resource_formatter(cf.get_option(key)) @@ -362,7 +362,7 @@ def is_terminal() -> bool: validator=is_one_of_factory([None, is_callable]), ) - def _deprecate_column_space(key): + def _deprecate_column_space(key) -> None: warnings.warn( "column_space is deprecated and will be removed " "in a future version. Use df.to_string(col_space=...) " @@ -387,7 +387,7 @@ def _deprecate_column_space(key): ) cf.register_option("max_categories", 8, pc_max_categories_doc, validator=is_int) - def _deprecate_negative_int_max_colwidth(key): + def _deprecate_negative_int_max_colwidth(key) -> None: value = cf.get_option(key) if value is not None and value < 0: warnings.warn( @@ -500,7 +500,7 @@ def _deprecate_negative_int_max_colwidth(key): # or we'll hit circular deps. -def use_inf_as_na_cb(key): +def use_inf_as_na_cb(key) -> None: from pandas.core.dtypes.missing import _use_inf_as_na _use_inf_as_na(key) @@ -720,7 +720,7 @@ def use_inf_as_na_cb(key): """ -def register_plotting_backend_cb(key): +def register_plotting_backend_cb(key) -> None: if key == "matplotlib": # We defer matplotlib validation, since it's the default return @@ -746,7 +746,7 @@ def register_plotting_backend_cb(key): """ -def register_converter_cb(key): +def register_converter_cb(key) -> None: from pandas.plotting import ( deregister_matplotlib_converters, register_matplotlib_converters, diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index d356a858a82fb..d0b7d10ce1dda 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -231,7 +231,7 @@ def _maybe_unbox_datetimelike(value: Scalar, dtype: DtypeObj) -> Scalar: return value -def _disallow_mismatched_datetimelike(value, dtype: DtypeObj): +def _disallow_mismatched_datetimelike(value, dtype: DtypeObj) -> None: """ numpy allows np.array(dt64values, dtype="timedelta64[ns]") and vice-versa, but we do not want to allow this, so we need to @@ -978,7 +978,7 @@ def maybe_upcast( return upcast_values, fill_value # type: ignore[return-value] -def invalidate_string_dtypes(dtype_set: set[DtypeObj]): +def invalidate_string_dtypes(dtype_set: set[DtypeObj]) -> None: """ Change string like dtypes to object for ``DataFrame.select_dtypes()``. diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index 32594854f49ae..348f6ef131864 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -970,7 +970,7 @@ def __eq__(self, other: Any) -> bool: def __ne__(self, other: Any) -> bool: return not self.__eq__(other) - def __setstate__(self, state): + def __setstate__(self, state) -> None: # for pickle compat. __getstate__ is defined in the # PandasExtensionDtype superclass and uses the public properties to # pickle -> need to set the settable private ones here (see GH26067) @@ -1249,7 +1249,7 @@ def __eq__(self, other: Any) -> bool: return is_dtype_equal(self.subtype, other.subtype) - def __setstate__(self, state): + def __setstate__(self, state) -> None: # for pickle compat. __get_state__ is defined in the # PandasExtensionDtype superclass and uses the public properties to # pickle -> need to set the settable private ones here (see GH26067) diff --git a/pandas/core/dtypes/missing.py b/pandas/core/dtypes/missing.py index 37b42ad66c027..0def7faefa095 100644 --- a/pandas/core/dtypes/missing.py +++ b/pandas/core/dtypes/missing.py @@ -233,7 +233,7 @@ def _isna(obj, inf_as_na: bool = False): return False -def _use_inf_as_na(key): +def _use_inf_as_na(key) -> None: """ Option change callback for na/inf behaviour. diff --git a/pandas/core/flags.py b/pandas/core/flags.py index 001cd3d41177a..cc779d98716c8 100644 --- a/pandas/core/flags.py +++ b/pandas/core/flags.py @@ -81,7 +81,7 @@ def allows_duplicate_labels(self) -> bool: return self._allows_duplicate_labels @allows_duplicate_labels.setter - def allows_duplicate_labels(self, value: bool): + def allows_duplicate_labels(self, value: bool) -> None: value = bool(value) obj = self._obj() if obj is None: @@ -99,7 +99,7 @@ def __getitem__(self, key): return getattr(self, key) - def __setitem__(self, key, value): + def __setitem__(self, key, value) -> None: if key not in self._keys: raise ValueError(f"Unknown flag {key}. Must be one of {self._keys}") setattr(self, key, value) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index b4a278185b01b..5431a819fc825 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3831,7 +3831,7 @@ def __setitem__(self, key, value): # set column self._set_item(key, value) - def _setitem_slice(self, key: slice, value): + def _setitem_slice(self, key: slice, value) -> None: # NB: we can't just use self.loc[key] = value because that # operates on labels and we need to operate positional for # backwards-compat, xref GH#31469 @@ -3923,7 +3923,7 @@ def igetitem(obj, i: int): finally: self.columns = orig_columns - def _setitem_frame(self, key, value): + def _setitem_frame(self, key, value) -> None: # support boolean setting with DataFrame input, e.g. # df[df > df2] = 0 if isinstance(key, np.ndarray): diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 589ea6e67d926..53a6ce8f0aeea 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2014,7 +2014,7 @@ def __getstate__(self) -> dict[str, Any]: } @final - def __setstate__(self, state): + def __setstate__(self, state) -> None: if isinstance(state, BlockManager): self._mgr = state elif isinstance(state, dict): @@ -3887,7 +3887,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=False) -> None: """ Parameters @@ -3999,7 +3999,7 @@ def __delitem__(self, key) -> None: # Unsorted @final - def _check_inplace_and_allows_duplicate_labels(self, inplace): + def _check_inplace_and_allows_duplicate_labels(self, inplace) -> None: if inplace and not self.flags.allows_duplicate_labels: raise ValueError( "Cannot specify 'inplace=True' when " @@ -5679,7 +5679,7 @@ def _protect_consolidate(self, f): def _consolidate_inplace(self) -> None: """Consolidate data in place and return None""" - def f(): + def f() -> None: self._mgr = self._mgr.consolidate() self._protect_consolidate(f) diff --git a/pandas/core/groupby/grouper.py b/pandas/core/groupby/grouper.py index 05ef155ecbcda..9e7c5e4d15a8c 100644 --- a/pandas/core/groupby/grouper.py +++ b/pandas/core/groupby/grouper.py @@ -942,7 +942,7 @@ def _convert_grouper(axis: Index, grouper): return grouper -def _check_deprecated_resample_kwargs(kwargs, origin): +def _check_deprecated_resample_kwargs(kwargs, origin) -> None: """ Check for use of deprecated parameters in ``resample`` and related functions. diff --git a/pandas/core/groupby/ops.py b/pandas/core/groupby/ops.py index d056b4b03d904..410f046ff6767 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -222,7 +222,7 @@ def _get_cython_vals(self, values: np.ndarray) -> np.ndarray: return values # TODO: general case implementation overridable by EAs. - def _disallow_invalid_ops(self, dtype: DtypeObj, is_numeric: bool = False): + def _disallow_invalid_ops(self, dtype: DtypeObj, is_numeric: bool = False) -> None: """ Check if we can do this operation with our cython functions. diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 0393c9d07cc74..8af5c1a381a69 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -661,7 +661,7 @@ def _dtype_to_subclass(cls, dtype: DtypeObj): """ @property - def asi8(self): + def asi8(self) -> None: """ Integer representation of the values. @@ -1726,7 +1726,7 @@ def name(self): return self._name @name.setter - def name(self, value: Hashable): + def name(self, value: Hashable) -> None: if self._no_setting_name: # Used in MultiIndex.levels to avoid silently ignoring name updates. raise RuntimeError( @@ -3192,7 +3192,7 @@ def _get_reconciled_name_object(self, other): return self @final - def _validate_sort_keyword(self, sort): + def _validate_sort_keyword(self, sort) -> None: if sort not in [None, False]: raise ValueError( "The 'sort' keyword only takes the values of " @@ -3200,7 +3200,7 @@ def _validate_sort_keyword(self, sort): ) @final - def _deprecate_dti_setop(self, other: Index, setop: str_t): + def _deprecate_dti_setop(self, other: Index, setop: str_t) -> None: """ Deprecate setop behavior between timezone-aware DatetimeIndexes with mismatched timezones. @@ -5929,7 +5929,7 @@ def get_value(self, series: Series, key): return self._get_values_for_loc(series, loc, key) - def _check_indexing_error(self, key): + def _check_indexing_error(self, key) -> None: if not is_scalar(key): # if key is not a scalar, directly raise an error (the code below # would convert to numpy arrays and raise later any way) - GH29926 @@ -5957,7 +5957,7 @@ def _get_values_for_loc(self, series: Series, loc, key): return series.iloc[loc] @final - def set_value(self, arr, key, value): + def set_value(self, arr, key, value) -> None: """ Fast lookup of value from 1-dimensional ndarray. @@ -6590,7 +6590,7 @@ def _maybe_cast_listlike_indexer(self, target) -> Index: return ensure_index(target) @final - def _validate_indexer(self, form: str_t, key, kind: str_t): + def _validate_indexer(self, form: str_t, key, kind: str_t) -> None: """ If we are positional indexer, validate that we have appropriate typed bounds must be an integer. diff --git a/pandas/core/indexes/extension.py b/pandas/core/indexes/extension.py index 28a0b43d5b02b..120c2b0eda11a 100644 --- a/pandas/core/indexes/extension.py +++ b/pandas/core/indexes/extension.py @@ -74,7 +74,7 @@ def fget(self): return Index(result, name=self.name) return result - def fset(self, value): + def fset(self, value) -> None: setattr(self._data, name, value) fget.__name__ = name diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 0a8df9d64d512..94f0f96bccb9f 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1423,7 +1423,7 @@ def format( def _get_names(self) -> FrozenList: return FrozenList(self._names) - def _set_names(self, names, *, level=None, validate: bool = True): + def _set_names(self, names, *, level=None, validate: bool = True) -> None: """ Set new names on index. Each name has to be a hashable type. diff --git a/pandas/core/indexes/range.py b/pandas/core/indexes/range.py index fdb1ee754a7e6..bc2b150bd3683 100644 --- a/pandas/core/indexes/range.py +++ b/pandas/core/indexes/range.py @@ -217,7 +217,7 @@ def _format_attrs(self): attrs.append(("name", ibase.default_pprint(self.name))) return attrs - def _format_data(self, name=None): + def _format_data(self, name=None) -> None: # we are formatting thru the attributes return None diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 5a97e1d5a04ea..4d0e4bfc6fff4 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -754,7 +754,7 @@ def _maybe_mask_setitem_value(self, indexer, value): return indexer, value @final - def _ensure_listlike_indexer(self, key, axis=None, value=None): + def _ensure_listlike_indexer(self, key, axis=None, value=None) -> None: """ Ensure that a list-like of column labels are all present by adding them if they do not already exist. @@ -790,7 +790,7 @@ def _ensure_listlike_indexer(self, key, axis=None, value=None): self.obj._mgr = self.obj._mgr.reindex_axis(keys, axis=0, only_slice=True) @final - def __setitem__(self, key, value): + def __setitem__(self, key, value) -> None: check_deprecated_indexers(key) if isinstance(key, tuple): key = tuple(list(x) if is_iterator(x) else x for x in key) @@ -1092,7 +1092,7 @@ class _LocIndexer(_LocationIndexer): # Key Checks @doc(_LocationIndexer._validate_key) - def _validate_key(self, key, axis: int): + def _validate_key(self, key, axis: int) -> None: # valid for a collection of labels (we check their presence later) # slice of labels (where start-end in labels) # slice of integers (only if in the labels) @@ -1428,7 +1428,7 @@ class _iLocIndexer(_LocationIndexer): # ------------------------------------------------------------------- # Key Checks - def _validate_key(self, key, axis: int): + def _validate_key(self, key, axis: int) -> None: if com.is_bool_indexer(key): if hasattr(key, "index") and isinstance(key.index, Index): if key.index.inferred_type == "integer": @@ -1638,7 +1638,7 @@ def _get_setitem_indexer(self, key): # ------------------------------------------------------------------- - def _setitem_with_indexer(self, indexer, value, name="iloc"): + def _setitem_with_indexer(self, indexer, value, name="iloc") -> None: """ _setitem_with_indexer is for setting values on a Series/DataFrame using positional indexers. @@ -1868,7 +1868,7 @@ def _setitem_with_indexer_split_path(self, indexer, value, name: str): for loc in ilocs: self._setitem_single_column(loc, value, pi) - def _setitem_with_indexer_2d_value(self, indexer, value): + def _setitem_with_indexer_2d_value(self, indexer, value) -> None: # We get here with np.ndim(value) == 2, excluding DataFrame, # which goes through _setitem_with_indexer_frame_value pi = indexer[0] @@ -1886,7 +1886,9 @@ def _setitem_with_indexer_2d_value(self, indexer, value): # setting with a list, re-coerces self._setitem_single_column(loc, value[:, i].tolist(), pi) - def _setitem_with_indexer_frame_value(self, indexer, value: DataFrame, name: str): + def _setitem_with_indexer_frame_value( + self, indexer, value: DataFrame, name: str + ) -> None: ilocs = self._ensure_iterable_column_indexer(indexer[1]) sub_indexer = list(indexer) @@ -1935,7 +1937,7 @@ def _setitem_with_indexer_frame_value(self, indexer, value: DataFrame, name: str self._setitem_single_column(loc, val, pi) - def _setitem_single_column(self, loc: int, value, plane_indexer): + def _setitem_single_column(self, loc: int, value, plane_indexer) -> None: """ Parameters @@ -2009,7 +2011,7 @@ def _setitem_single_column(self, loc: int, value, plane_indexer): # TODO: what if we got here indirectly via loc? return - def _setitem_single_block(self, indexer, value, name: str): + def _setitem_single_block(self, indexer, value, name: str) -> None: """ _setitem_with_indexer for the case when we have a single Block. """ @@ -2335,7 +2337,7 @@ def __getitem__(self, key): key = self._convert_key(key) return self.obj._get_value(*key, takeable=self._takeable) - def __setitem__(self, key, value): + def __setitem__(self, key, value) -> None: if isinstance(key, tuple): key = tuple(com.apply_if_callable(x, self.obj) for x in key) else: diff --git a/pandas/core/internals/array_manager.py b/pandas/core/internals/array_manager.py index ee6c183898079..8463c5bc2bf65 100644 --- a/pandas/core/internals/array_manager.py +++ b/pandas/core/internals/array_manager.py @@ -176,7 +176,7 @@ def get_dtypes(self): def __getstate__(self): return self.arrays, self._axes - def __setstate__(self, state): + def __setstate__(self, state) -> None: self.arrays = state[0] self._axes = state[1] @@ -812,7 +812,7 @@ def column_arrays(self) -> list[ArrayLike]: def iset( self, loc: int | slice | np.ndarray, value: ArrayLike, inplace: bool = False - ): + ) -> None: """ Set new column(s). @@ -1331,7 +1331,7 @@ def _get_data_subset(self, predicate: Callable) -> SingleArrayManager: else: return self.make_empty() - def set_values(self, values: ArrayLike): + def set_values(self, values: ArrayLike) -> None: """ Set (replace) the values of the SingleArrayManager in place. diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 49efecec7472e..7941835bc6a6a 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -215,7 +215,7 @@ def mgr_locs(self) -> BlockPlacement: return self._mgr_locs @mgr_locs.setter - def mgr_locs(self, new_mgr_locs: BlockPlacement): + def mgr_locs(self, new_mgr_locs: BlockPlacement) -> None: self._mgr_locs = new_mgr_locs @final @@ -2156,7 +2156,7 @@ def new_block(values, placement, *, ndim: int) -> Block: return klass(values, ndim=ndim, placement=placement) -def check_ndim(values, placement: BlockPlacement, ndim: int): +def check_ndim(values, placement: BlockPlacement, ndim: int) -> None: """ ndim inference and validation. diff --git a/pandas/core/internals/concat.py b/pandas/core/internals/concat.py index 4a352d614e1d9..e99a710941d19 100644 --- a/pandas/core/internals/concat.py +++ b/pandas/core/internals/concat.py @@ -359,7 +359,7 @@ def _get_mgr_concatenation_plan(mgr: BlockManager, indexers: dict[int, np.ndarra class JoinUnit: - def __init__(self, block: Block, shape: Shape, indexers=None): + def __init__(self, block: Block, shape: Shape, indexers=None) -> None: # Passing shape explicitly is required for cases when block is None. # Note: block is None implies indexers is None, but not vice-versa if indexers is None: diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 7cccc9833de6b..c4bd3453e0a9a 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -1773,7 +1773,7 @@ def unpickle_block(values, mgr_locs, ndim: int) -> Block: self._post_setstate() - def _post_setstate(self): + def _post_setstate(self) -> None: pass @cache_readonly @@ -1781,12 +1781,12 @@ def _block(self) -> Block: return self.blocks[0] @property - def _blknos(self): + def _blknos(self) -> None: """compat with BlockManager""" return None @property - def _blklocs(self): + def _blklocs(self) -> None: """compat with BlockManager""" return None @@ -1870,7 +1870,7 @@ def fast_xs(self, loc): """ raise NotImplementedError("Use series._values[loc] instead") - def set_values(self, values: ArrayLike): + def set_values(self, values: ArrayLike) -> None: """ Set the values of the single block in place. diff --git a/pandas/core/internals/ops.py b/pandas/core/internals/ops.py index 1160d3b2a8e3a..24fc51a96d9df 100644 --- a/pandas/core/internals/ops.py +++ b/pandas/core/internals/ops.py @@ -86,7 +86,7 @@ def operate_blockwise( return new_mgr -def _reset_block_mgr_locs(nbs: list[Block], locs): +def _reset_block_mgr_locs(nbs: list[Block], locs) -> None: """ Reset mgr_locs to correspond to our original DataFrame. """ diff --git a/pandas/core/missing.py b/pandas/core/missing.py index 57b0a95f803b1..9eac047f003d0 100644 --- a/pandas/core/missing.py +++ b/pandas/core/missing.py @@ -376,7 +376,7 @@ def _interpolate_1d( bounds_error: bool = False, order: int | None = None, **kwargs, -): +) -> None: """ Logic for the 1-d interpolation. The input indices and yvalues will each be 1-d arrays of the same length. diff --git a/pandas/core/ops/array_ops.py b/pandas/core/ops/array_ops.py index 2caaadbc05cff..d90a9a42e6454 100644 --- a/pandas/core/ops/array_ops.py +++ b/pandas/core/ops/array_ops.py @@ -509,7 +509,7 @@ def maybe_prepare_scalar_for_op(obj, shape: Shape): } -def _bool_arith_check(op, a, b): +def _bool_arith_check(op, a, b) -> None: """ In contrast to numpy, pandas raises an error for certain operations with booleans. diff --git a/pandas/core/ops/invalid.py b/pandas/core/ops/invalid.py index cc4a1f11edd2b..4d9cf3ceac4de 100644 --- a/pandas/core/ops/invalid.py +++ b/pandas/core/ops/invalid.py @@ -48,7 +48,7 @@ def make_invalid_op(name: str): invalid_op : function """ - def invalid_op(self, other=None): + def invalid_op(self, other=None) -> None: typ = type(self).__name__ raise TypeError(f"cannot perform {name} with this index type: {typ}") diff --git a/pandas/core/ops/mask_ops.py b/pandas/core/ops/mask_ops.py index 57bacba0d4bee..adc1f63c568bf 100644 --- a/pandas/core/ops/mask_ops.py +++ b/pandas/core/ops/mask_ops.py @@ -184,6 +184,6 @@ def kleene_and( return result, mask -def raise_for_nan(value, method: str): +def raise_for_nan(value, method: str) -> None: if lib.is_float(value) and np.isnan(value): raise ValueError(f"Cannot perform logical '{method}' with floating NaN") diff --git a/pandas/core/ops/methods.py b/pandas/core/ops/methods.py index df22919ed19f1..cfb1649c14734 100644 --- a/pandas/core/ops/methods.py +++ b/pandas/core/ops/methods.py @@ -43,7 +43,7 @@ def _get_method_wrappers(cls): return arith_flex, comp_flex -def add_flex_arithmetic_methods(cls): +def add_flex_arithmetic_methods(cls) -> None: """ Adds the full suite of flex arithmetic methods (``pow``, ``mul``, ``add``) to the class. @@ -117,6 +117,6 @@ def _create_methods(cls, arith_method, comp_method): return new_methods -def _add_methods(cls, new_methods): +def _add_methods(cls, new_methods) -> None: for name, method in new_methods.items(): setattr(cls, name, method) diff --git a/pandas/core/reshape/concat.py b/pandas/core/reshape/concat.py index 523cd56db3e0a..a7cd0479b4d32 100644 --- a/pandas/core/reshape/concat.py +++ b/pandas/core/reshape/concat.py @@ -697,7 +697,7 @@ def _get_concat_axis(self) -> Index: return concat_axis - def _maybe_check_integrity(self, concat_index: Index): + def _maybe_check_integrity(self, concat_index: Index) -> None: if self.verify_integrity: if not concat_index.is_unique: overlap = concat_index[concat_index.duplicated()].unique() diff --git a/pandas/core/reshape/encoding.py b/pandas/core/reshape/encoding.py index f0500ec142955..c0a43d4766fa0 100644 --- a/pandas/core/reshape/encoding.py +++ b/pandas/core/reshape/encoding.py @@ -143,7 +143,7 @@ def get_dummies( data_to_encode = data[columns] # validate prefixes and separator to avoid silently dropping cols - def check_len(item, name): + def check_len(item, name) -> None: if is_list_like(item): if not len(item) == data_to_encode.shape[1]: diff --git a/pandas/core/reshape/reshape.py b/pandas/core/reshape/reshape.py index b4e944861f1bc..e083de96f892f 100644 --- a/pandas/core/reshape/reshape.py +++ b/pandas/core/reshape/reshape.py @@ -162,7 +162,7 @@ def _make_sorted_values(self, values: np.ndarray) -> np.ndarray: sorted_values = algos.take_nd(values, indexer, axis=0) return sorted_values - def _make_selectors(self): + def _make_selectors(self) -> None: new_levels = self.new_index_levels # make the mask diff --git a/pandas/core/series.py b/pandas/core/series.py index 6ebee74810305..7e8e19c40c9ae 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1165,7 +1165,7 @@ def _set_with_engine(self, key, value) -> None: # this is equivalent to self._values[key] = value self._mgr.setitem_inplace(loc, value) - def _set_with(self, key, value): + def _set_with(self, key, value) -> None: # We got here via exception-handling off of InvalidIndexError, so # key should always be listlike at this point. assert not isinstance(key, tuple) @@ -1203,7 +1203,7 @@ def _set_values(self, key, value) -> None: self._mgr = self._mgr.setitem(indexer=key, value=value) self._maybe_update_cacher() - def _set_value(self, label, value, takeable: bool = False): + def _set_value(self, label, value, takeable: bool = False) -> None: """ Quickly set single value at passed label. diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index a153761f377b3..e955e4e228476 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -948,7 +948,7 @@ def __init__( else: raise ValueError("'numba' is the only supported engine") - def reset(self): + def reset(self) -> None: """ Reset the state captured by `update` calls. """ diff --git a/pandas/core/window/online.py b/pandas/core/window/online.py index 2ef06732f9800..bb973f05687e2 100644 --- a/pandas/core/window/online.py +++ b/pandas/core/window/online.py @@ -112,6 +112,6 @@ def run_ewm(self, weighted_avg, deltas, min_periods, ewm_func): self.last_ewm = result[-1] return result - def reset(self): + def reset(self) -> None: self.old_wt = np.ones(self.shape[self.axis - 1]) self.last_ewm = None diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index b45f43adbe952..45170c26fb148 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -1154,7 +1154,7 @@ class Window(BaseWindow): "method", ] - def _validate(self): + def _validate(self) -> None: super()._validate() if not isinstance(self.win_type, str): @@ -1817,7 +1817,7 @@ class Rolling(RollingAndExpandingMixin): "method", ] - def _validate(self): + def _validate(self) -> None: super()._validate() # we allow rolling on a datetimelike index @@ -1862,7 +1862,7 @@ def _validate(self): elif not is_integer(self.window) or self.window < 0: raise ValueError("window must be an integer 0 or greater") - def _validate_datetimelike_monotonic(self): + def _validate_datetimelike_monotonic(self) -> None: """ Validate self._on is monotonic (increasing or decreasing) and has no NaT values for frequency windows. @@ -1872,7 +1872,7 @@ def _validate_datetimelike_monotonic(self): if not (self._on.is_monotonic_increasing or self._on.is_monotonic_decreasing): self._raise_monotonic_error("values must be monotonic") - def _raise_monotonic_error(self, msg: str): + def _raise_monotonic_error(self, msg: str) -> None: on = self.on if on is None: if self.axis == 0: @@ -2865,7 +2865,7 @@ def _get_window_indexer(self) -> GroupbyIndexer: ) return window_indexer - def _validate_datetimelike_monotonic(self): + def _validate_datetimelike_monotonic(self) -> None: """ Validate that each group in self._on is monotonic """ From 91308daf5643256bfe8cc3b36a8bf9bbe0a8ab59 Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Mon, 27 Jun 2022 19:47:01 +0200 Subject: [PATCH 2/2] type return of Index.asi8 to be compatible with overridden method --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 8af5c1a381a69..f05c216bf6494 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -661,7 +661,7 @@ def _dtype_to_subclass(cls, dtype: DtypeObj): """ @property - def asi8(self) -> None: + def asi8(self) -> npt.NDArray[np.int64] | None: """ Integer representation of the values.