Skip to content

Commit 7cba64e

Browse files
authored
TYP: more simple return types from ruff (pandas-dev#56628)
TYP: more return types from ruff
1 parent 0643a18 commit 7cba64e

28 files changed

+55
-47
lines changed

pandas/core/apply.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ def generate_numba_apply_func(
827827
def apply_with_numba(self):
828828
pass
829829

830-
def validate_values_for_numba(self):
830+
def validate_values_for_numba(self) -> None:
831831
# Validate column dtyps all OK
832832
for colname, dtype in self.obj.dtypes.items():
833833
if not is_numeric_dtype(dtype):

pandas/core/array_algos/replace.py

Lines changed: 1 addition & 1 deletion
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/arrays/arrow/accessors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __init__(self, data, validation_msg: str) -> None:
3939
def _is_valid_pyarrow_dtype(self, pyarrow_dtype) -> bool:
4040
pass
4141

42-
def _validate(self, data):
42+
def _validate(self, data) -> None:
4343
dtype = data.dtype
4444
if not isinstance(dtype, ArrowDtype):
4545
# Raise AttributeError so that inspect can handle non-struct Series.

pandas/core/arrays/arrow/extension_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def to_pandas_dtype(self) -> IntervalDtype:
135135
"""
136136

137137

138-
def patch_pyarrow():
138+
def patch_pyarrow() -> None:
139139
# starting from pyarrow 14.0.1, it has its own mechanism
140140
if not pa_version_under14p1:
141141
return

pandas/core/arrays/categorical.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,7 +2164,9 @@ def __contains__(self, key) -> bool:
21642164
# ------------------------------------------------------------------
21652165
# Rendering Methods
21662166

2167-
def _formatter(self, boxed: bool = False):
2167+
# error: Return type "None" of "_formatter" incompatible with return
2168+
# type "Callable[[Any], str | None]" in supertype "ExtensionArray"
2169+
def _formatter(self, boxed: bool = False) -> None: # type: ignore[override]
21682170
# Returning None here will cause format_array to do inference.
21692171
return None
21702172

@@ -2890,7 +2892,7 @@ def __init__(self, data) -> None:
28902892
self._freeze()
28912893

28922894
@staticmethod
2893-
def _validate(data):
2895+
def _validate(data) -> None:
28942896
if not isinstance(data.dtype, CategoricalDtype):
28952897
raise AttributeError("Can only use .cat accessor with a 'category' dtype")
28962898

pandas/core/arrays/datetimelike.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,7 +2058,7 @@ def freq(self, value) -> None:
20582058
self._freq = value
20592059

20602060
@final
2061-
def _maybe_pin_freq(self, freq, validate_kwds: dict):
2061+
def _maybe_pin_freq(self, freq, validate_kwds: dict) -> None:
20622062
"""
20632063
Constructor helper to pin the appropriate `freq` attribute. Assumes
20642064
that self._freq is currently set to any freq inferred in
@@ -2092,7 +2092,7 @@ def _maybe_pin_freq(self, freq, validate_kwds: dict):
20922092

20932093
@final
20942094
@classmethod
2095-
def _validate_frequency(cls, index, freq: BaseOffset, **kwargs):
2095+
def _validate_frequency(cls, index, freq: BaseOffset, **kwargs) -> None:
20962096
"""
20972097
Validate that a frequency is compatible with the values of a given
20982098
Datetime Array/Index or Timedelta Array/Index

pandas/core/arrays/sparse/accessor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, data=None) -> None:
3030
self._parent = data
3131
self._validate(data)
3232

33-
def _validate(self, data):
33+
def _validate(self, data) -> None:
3434
raise NotImplementedError
3535

3636

@@ -50,7 +50,7 @@ class SparseAccessor(BaseAccessor, PandasDelegate):
5050
array([2, 2, 2])
5151
"""
5252

53-
def _validate(self, data):
53+
def _validate(self, data) -> None:
5454
if not isinstance(data.dtype, SparseDtype):
5555
raise AttributeError(self._validation_msg)
5656

@@ -243,7 +243,7 @@ class SparseFrameAccessor(BaseAccessor, PandasDelegate):
243243
0.5
244244
"""
245245

246-
def _validate(self, data):
246+
def _validate(self, data) -> None:
247247
dtypes = data.dtypes
248248
if not all(isinstance(t, SparseDtype) for t in dtypes):
249249
raise AttributeError(self._validation_msg)

pandas/core/arrays/sparse/array.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1830,7 +1830,9 @@ def __repr__(self) -> str:
18301830
pp_index = printing.pprint_thing(self.sp_index)
18311831
return f"{pp_str}\nFill: {pp_fill}\n{pp_index}"
18321832

1833-
def _formatter(self, boxed: bool = False):
1833+
# error: Return type "None" of "_formatter" incompatible with return
1834+
# type "Callable[[Any], str | None]" in supertype "ExtensionArray"
1835+
def _formatter(self, boxed: bool = False) -> None: # type: ignore[override]
18341836
# Defer to the formatter from the GenericArrayFormatter calling us.
18351837
# This will infer the correct formatter from the dtype of the values.
18361838
return None

pandas/core/arrays/sparse/scipy_sparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
)
2828

2929

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

pandas/core/arrays/string_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def __init__(self, values, copy: bool = False) -> None:
364364
self._validate()
365365
NDArrayBacked.__init__(self, self._ndarray, StringDtype(storage="python"))
366366

367-
def _validate(self):
367+
def _validate(self) -> None:
368368
"""Validate that we only store NA or strings."""
369369
if len(self._ndarray) and not lib.is_string_array(self._ndarray, skipna=True):
370370
raise ValueError("StringArray requires a sequence of strings or pandas.NA")

0 commit comments

Comments
 (0)