Skip to content

Commit f93f9f3

Browse files
committed
add some -> to pandas core
1 parent 27135a5 commit f93f9f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+127
-123
lines changed

pandas/core/array_algos/replace.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def compare_or_regex_search(
6767

6868
def _check_comparison_types(
6969
result: ArrayLike | bool, a: ArrayLike, b: Scalar | Pattern
70-
):
70+
) -> None:
7171
"""
7272
Raises an error if the two arrays (a,b) cannot be compared.
7373
Otherwise, returns the comparison result as expected.

pandas/core/array_algos/take.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def _get_take_nd_function(
337337

338338
if func is None:
339339

340-
def func(arr, indexer, out, fill_value=np.nan):
340+
def func(arr, indexer, out, fill_value=np.nan) -> None:
341341
indexer = ensure_platform_int(indexer)
342342
_take_nd_object(
343343
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):
349349
def _view_wrapper(f, arr_dtype=None, out_dtype=None, fill_wrap=None):
350350
def wrapper(
351351
arr: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=np.nan
352-
):
352+
) -> None:
353353
if arr_dtype is not None:
354354
arr = arr.view(arr_dtype)
355355
if out_dtype is not None:
@@ -364,7 +364,7 @@ def wrapper(
364364
def _convert_wrapper(f, conv_dtype):
365365
def wrapper(
366366
arr: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=np.nan
367-
):
367+
) -> None:
368368
if conv_dtype == object:
369369
# GH#39755 avoid casting dt64/td64 to integers
370370
arr = ensure_wrapped_if_datetimelike(arr)
@@ -506,7 +506,7 @@ def _take_nd_object(
506506
axis: int,
507507
fill_value,
508508
mask_info,
509-
):
509+
) -> None:
510510
if mask_info is not None:
511511
mask, needs_masking = mask_info
512512
else:

pandas/core/arrays/_mixins.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def _validate_shift_value(self, fill_value):
259259
# we can remove this and use validate_fill_value directly
260260
return self._validate_scalar(fill_value)
261261

262-
def __setitem__(self, key, value):
262+
def __setitem__(self, key, value) -> None:
263263
key = check_array_indexer(self, key)
264264
value = self._validate_setitem_value(value)
265265
self._ndarray[key] = value

pandas/core/arrays/arrow/_arrow_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from pandas.core.arrays.interval import VALID_CLOSED
1515

1616

17-
def fallback_performancewarning(version: str | None = None):
17+
def fallback_performancewarning(version: str | None = None) -> None:
1818
"""
1919
Raise a PerformanceWarning for falling back to ExtensionArray's
2020
non-pyarrow method

pandas/core/arrays/base.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1656,7 +1656,7 @@ def _create_arithmetic_method(cls, op):
16561656
raise AbstractMethodError(cls)
16571657

16581658
@classmethod
1659-
def _add_arithmetic_ops(cls):
1659+
def _add_arithmetic_ops(cls) -> None:
16601660
setattr(cls, "__add__", cls._create_arithmetic_method(operator.add))
16611661
setattr(cls, "__radd__", cls._create_arithmetic_method(roperator.radd))
16621662
setattr(cls, "__sub__", cls._create_arithmetic_method(operator.sub))
@@ -1681,7 +1681,7 @@ def _create_comparison_method(cls, op):
16811681
raise AbstractMethodError(cls)
16821682

16831683
@classmethod
1684-
def _add_comparison_ops(cls):
1684+
def _add_comparison_ops(cls) -> None:
16851685
setattr(cls, "__eq__", cls._create_comparison_method(operator.eq))
16861686
setattr(cls, "__ne__", cls._create_comparison_method(operator.ne))
16871687
setattr(cls, "__lt__", cls._create_comparison_method(operator.lt))
@@ -1694,7 +1694,7 @@ def _create_logical_method(cls, op):
16941694
raise AbstractMethodError(cls)
16951695

16961696
@classmethod
1697-
def _add_logical_ops(cls):
1697+
def _add_logical_ops(cls) -> None:
16981698
setattr(cls, "__and__", cls._create_logical_method(operator.and_))
16991699
setattr(cls, "__rand__", cls._create_logical_method(roperator.rand_))
17001700
setattr(cls, "__or__", cls._create_logical_method(operator.or_))

pandas/core/arrays/categorical.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ def categories(self):
738738
return self.dtype.categories
739739

740740
@categories.setter
741-
def categories(self, categories):
741+
def categories(self, categories) -> None:
742742
new_dtype = CategoricalDtype(categories, ordered=self.ordered)
743743
if self.dtype.categories is not None and len(self.dtype.categories) != len(
744744
new_dtype.categories
@@ -776,7 +776,7 @@ def codes(self) -> np.ndarray:
776776
v.flags.writeable = False
777777
return v
778778

779-
def _set_categories(self, categories, fastpath=False):
779+
def _set_categories(self, categories, fastpath=False) -> None:
780780
"""
781781
Sets new categories inplace
782782
@@ -1700,7 +1700,7 @@ def _internal_get_values(self):
17001700
return self.categories.astype("object").take(self._codes, fill_value=np.nan)
17011701
return np.array(self)
17021702

1703-
def check_for_ordered(self, op):
1703+
def check_for_ordered(self, op) -> None:
17041704
"""assert that we are ordered"""
17051705
if not self.ordered:
17061706
raise TypeError(
@@ -1931,7 +1931,7 @@ def _codes(self) -> np.ndarray:
19311931
return self._ndarray
19321932

19331933
@_codes.setter
1934-
def _codes(self, value: np.ndarray):
1934+
def _codes(self, value: np.ndarray) -> None:
19351935
warn(
19361936
"Setting the codes on a Categorical is deprecated and will raise in "
19371937
"a future version. Create a new Categorical object instead",
@@ -1985,7 +1985,7 @@ def __contains__(self, key) -> bool:
19851985
# ------------------------------------------------------------------
19861986
# Rendering Methods
19871987

1988-
def _formatter(self, boxed: bool = False):
1988+
def _formatter(self, boxed: bool = False) -> None:
19891989
# Defer to CategoricalFormatter's formatter.
19901990
return None
19911991

@@ -2713,7 +2713,7 @@ def __init__(self, data) -> None:
27132713
self._freeze()
27142714

27152715
@staticmethod
2716-
def _validate(data):
2716+
def _validate(data) -> None:
27172717
if not is_categorical_dtype(data.dtype):
27182718
raise AttributeError("Can only use .cat accessor with a 'category' dtype")
27192719

pandas/core/arrays/datetimelike.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def __setitem__( # type: ignore[override]
410410

411411
self._maybe_clear_freq()
412412

413-
def _maybe_clear_freq(self):
413+
def _maybe_clear_freq(self) -> None:
414414
# inplace operations like __setitem__ may invalidate the freq of
415415
# DatetimeArray and TimedeltaArray
416416
pass
@@ -924,7 +924,7 @@ def freq(self):
924924
return self._freq
925925

926926
@freq.setter
927-
def freq(self, value):
927+
def freq(self, value) -> None:
928928
if value is not None:
929929
value = to_offset(value)
930930
self._validate_frequency(self, value)
@@ -976,7 +976,7 @@ def resolution(self) -> str:
976976
return self._resolution_obj.attrname # type: ignore[union-attr]
977977

978978
@classmethod
979-
def _validate_frequency(cls, index, freq, **kwargs):
979+
def _validate_frequency(cls, index, freq, **kwargs) -> None:
980980
"""
981981
Validate that a frequency is compatible with the values of a given
982982
Datetime Array/Index or Timedelta Array/Index

pandas/core/arrays/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ def _unbox_scalar(self, value, setitem: bool = False) -> np.datetime64:
520520
def _scalar_from_string(self, value) -> Timestamp | NaTType:
521521
return Timestamp(value, tz=self.tz)
522522

523-
def _check_compatible_with(self, other, setitem: bool = False):
523+
def _check_compatible_with(self, other, setitem: bool = False) -> None:
524524
if other is NaT:
525525
return
526526
self._assert_tzawareness_compat(other)

pandas/core/arrays/interval.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ def from_tuples(
598598

599599
return cls.from_arrays(left, right, inclusive, copy=False, dtype=dtype)
600600

601-
def _validate(self):
601+
def _validate(self) -> None:
602602
"""
603603
Verify that the IntervalArray is valid.
604604
@@ -692,7 +692,7 @@ def __getitem__(
692692
raise ValueError("multi-dimensional indexing not allowed")
693693
return self._shallow_copy(left, right)
694694

695-
def __setitem__(self, key, value):
695+
def __setitem__(self, key, value) -> None:
696696
value_left, value_right = self._validate_setitem_value(value)
697697
key = check_array_indexer(self, key)
698698

pandas/core/arrays/period.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def _unbox_scalar( # type: ignore[override]
336336
def _scalar_from_string(self, value: str) -> Period:
337337
return Period(value, freq=self.freq)
338338

339-
def _check_compatible_with(self, other, setitem: bool = False):
339+
def _check_compatible_with(self, other, setitem: bool = False) -> None:
340340
if other is NaT:
341341
return
342342
self._require_matching_freq(other)

pandas/core/arrays/sparse/accessor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class SparseAccessor(BaseAccessor, PandasDelegate):
3333
Accessor for SparseSparse from other sparse matrix data types.
3434
"""
3535

36-
def _validate(self, data):
36+
def _validate(self, data) -> None:
3737
if not isinstance(data.dtype, SparseDtype):
3838
raise AttributeError(self._validation_msg)
3939

@@ -222,7 +222,7 @@ class SparseFrameAccessor(BaseAccessor, PandasDelegate):
222222
.. versionadded:: 0.25.0
223223
"""
224224

225-
def _validate(self, data):
225+
def _validate(self, data) -> None:
226226
dtypes = data.dtypes
227227
if not all(isinstance(t, SparseDtype) for t in dtypes):
228228
raise AttributeError(self._validation_msg)

pandas/core/arrays/sparse/array.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ def __array__(self, dtype: NpDtype | None = None) -> np.ndarray:
605605
out[self.sp_index.indices] = self.sp_values
606606
return out
607607

608-
def __setitem__(self, key, value):
608+
def __setitem__(self, key, value) -> None:
609609
# I suppose we could allow setting of non-fill_value elements.
610610
# TODO(SparseArray.__setitem__): remove special cases in
611611
# ExtensionBlock.where
@@ -657,7 +657,7 @@ def fill_value(self):
657657
return self.dtype.fill_value
658658

659659
@fill_value.setter
660-
def fill_value(self, value):
660+
def fill_value(self, value) -> None:
661661
self._dtype = SparseDtype(self.dtype.subtype, value)
662662

663663
@property
@@ -1381,7 +1381,7 @@ def _where(self, mask, value):
13811381
# ------------------------------------------------------------------------
13821382
# IO
13831383
# ------------------------------------------------------------------------
1384-
def __setstate__(self, state):
1384+
def __setstate__(self, state) -> None:
13851385
"""Necessary for making this object picklable"""
13861386
if isinstance(state, tuple):
13871387
# Compat for pandas < 0.24.0
@@ -1795,7 +1795,7 @@ def __repr__(self) -> str:
17951795
pp_index = printing.pprint_thing(self.sp_index)
17961796
return f"{pp_str}\nFill: {pp_fill}\n{pp_index}"
17971797

1798-
def _formatter(self, boxed=False):
1798+
def _formatter(self, boxed=False) -> None:
17991799
# Defer to the formatter from the GenericArrayFormatter calling us.
18001800
# This will infer the correct formatter from the dtype of the values.
18011801
return None

pandas/core/arrays/sparse/dtype.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def fill_value(self):
148148
"""
149149
return self._fill_value
150150

151-
def _check_fill_value(self):
151+
def _check_fill_value(self) -> None:
152152
if not is_scalar(self._fill_value):
153153
raise ValueError(
154154
f"fill_value must be a scalar. Got {self._fill_value} instead"

pandas/core/arrays/sparse/scipy_sparse.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import scipy.sparse
2929

3030

31-
def _check_is_partition(parts: Iterable, whole: Iterable):
31+
def _check_is_partition(parts: Iterable, whole: Iterable) -> None:
3232
whole = set(whole)
3333
parts = [set(x) for x in parts]
3434
if set.intersection(*parts) != set():

pandas/core/arrays/string_.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def __init__(self, values, copy=False) -> None:
304304
self._validate()
305305
NDArrayBacked.__init__(self, self._ndarray, StringDtype(storage="python"))
306306

307-
def _validate(self):
307+
def _validate(self) -> None:
308308
"""Validate that we only store NA or strings."""
309309
if len(self._ndarray) and not lib.is_string_array(self._ndarray, skipna=True):
310310
raise ValueError("StringArray requires a sequence of strings or pandas.NA")
@@ -379,7 +379,7 @@ def _values_for_factorize(self):
379379
arr[mask] = -1
380380
return arr, -1
381381

382-
def __setitem__(self, key, value):
382+
def __setitem__(self, key, value) -> None:
383383
value = extract_array(value, extract_numpy=True)
384384
if isinstance(value, type(self)):
385385
# extract_array doesn't extract PandasArray subclasses

pandas/core/arrays/timedeltas.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def _format_native_types(
439439
# ----------------------------------------------------------------
440440
# Arithmetic Methods
441441

442-
def _add_offset(self, other):
442+
def _add_offset(self, other) -> None:
443443
assert not isinstance(other, Tick)
444444
raise TypeError(
445445
f"cannot add the type {type(other).__name__} to a {type(self).__name__}"

pandas/core/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,14 @@ class NoNewAttributesMixin:
154154
`object.__setattr__(self, key, value)`.
155155
"""
156156

157-
def _freeze(self):
157+
def _freeze(self) -> None:
158158
"""
159159
Prevents setting additional attributes.
160160
"""
161161
object.__setattr__(self, "__frozen", True)
162162

163163
# prevent adding any attribute via s.xxx.new_attribute = ...
164-
def __setattr__(self, key: str, value):
164+
def __setattr__(self, key: str, value) -> None:
165165
# _cache is used by a decorator
166166
# We need to check both 1.) cls.__dict__ and 2.) getattr(self, key)
167167
# because

pandas/core/common.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ def temp_setattr(obj, attr: str, value) -> Iterator[None]:
553553
setattr(obj, attr, old_value)
554554

555555

556-
def require_length_match(data, index: Index):
556+
def require_length_match(data, index: Index) -> None:
557557
"""
558558
Check the length of data matches the length of the index.
559559
"""
@@ -665,7 +665,9 @@ def resolve_numeric_only(numeric_only: bool | None | lib.NoDefault) -> bool:
665665
return result
666666

667667

668-
def deprecate_numeric_only_default(cls: type, name: str, deprecate_none: bool = False):
668+
def deprecate_numeric_only_default(
669+
cls: type, name: str, deprecate_none: bool = False
670+
) -> None:
669671
"""Emit FutureWarning message for deprecation of numeric_only.
670672
671673
See GH#46560 for details on the deprecation.

pandas/core/computation/eval.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def _check_engine(engine: str | None) -> str:
6767
return engine
6868

6969

70-
def _check_parser(parser: str):
70+
def _check_parser(parser: str) -> None:
7171
"""
7272
Make sure a valid parser is passed.
7373
@@ -86,7 +86,7 @@ def _check_parser(parser: str):
8686
)
8787

8888

89-
def _check_resolvers(resolvers):
89+
def _check_resolvers(resolvers) -> None:
9090
if resolvers is not None:
9191
for resolver in resolvers:
9292
if not hasattr(resolver, "__getitem__"):
@@ -97,7 +97,7 @@ def _check_resolvers(resolvers):
9797
)
9898

9999

100-
def _check_expression(expr):
100+
def _check_expression(expr) -> None:
101101
"""
102102
Make sure an expression is not an empty string
103103
@@ -144,7 +144,7 @@ def _convert_expression(expr) -> str:
144144
return s
145145

146146

147-
def _check_for_locals(expr: str, stack_level: int, parser: str):
147+
def _check_for_locals(expr: str, stack_level: int, parser: str) -> None:
148148

149149
at_top_of_stack = stack_level == 0
150150
not_pandas_parser = parser != "pandas"

pandas/core/computation/expressions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
_MIN_ELEMENTS = 1_000_000
3939

4040

41-
def set_use_numexpr(v=True):
41+
def set_use_numexpr(v=True) -> None:
4242
# set/unset to use numexpr
4343
global USE_NUMEXPR
4444
if NUMEXPR_INSTALLED:
@@ -51,7 +51,7 @@ def set_use_numexpr(v=True):
5151
_where = _where_numexpr if USE_NUMEXPR else _where_standard
5252

5353

54-
def set_numexpr_threads(n=None):
54+
def set_numexpr_threads(n=None) -> None:
5555
# if we are using numexpr, set the threads to n
5656
# otherwise reset
5757
if NUMEXPR_INSTALLED and USE_NUMEXPR:

0 commit comments

Comments
 (0)