Skip to content

Commit f654176

Browse files
authored
TYP: more return annotations in core/ (#47618)
* TYP: more return annotations in core/ * from __future__ import annotations * more __future__
1 parent 028d0d6 commit f654176

Some content is hidden

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

59 files changed

+382
-189
lines changed

pandas/_testing/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ def getMixedTypeDict():
529529
return index, data
530530

531531

532-
def makeMixedDataFrame():
532+
def makeMixedDataFrame() -> DataFrame:
533533
return DataFrame(getMixedTypeDict()[1])
534534

535535

pandas/core/array_algos/replace.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def _check_comparison_types(
119119

120120
def replace_regex(
121121
values: ArrayLike, rx: re.Pattern, value, mask: npt.NDArray[np.bool_] | None
122-
):
122+
) -> None:
123123
"""
124124
Parameters
125125
----------

pandas/core/arrays/_mixins.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
NumpyValueArrayLike,
7171
)
7272

73+
from pandas import Series
74+
7375

7476
def ravel_compat(meth: F) -> F:
7577
"""
@@ -259,7 +261,7 @@ def _validate_shift_value(self, fill_value):
259261
# we can remove this and use validate_fill_value directly
260262
return self._validate_scalar(fill_value)
261263

262-
def __setitem__(self, key, value):
264+
def __setitem__(self, key, value) -> None:
263265
key = check_array_indexer(self, key)
264266
value = self._validate_setitem_value(value)
265267
self._ndarray[key] = value
@@ -433,7 +435,7 @@ def insert(
433435
# These are not part of the EA API, but we implement them because
434436
# pandas assumes they're there.
435437

436-
def value_counts(self, dropna: bool = True):
438+
def value_counts(self, dropna: bool = True) -> Series:
437439
"""
438440
Return a Series containing counts of unique values.
439441

pandas/core/arrays/arrow/_arrow_utils.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from pandas.core.arrays.interval import VALID_CLOSED
1414

1515

16-
def fallback_performancewarning(version: str | None = None):
16+
def fallback_performancewarning(version: str | None = None) -> None:
1717
"""
1818
Raise a PerformanceWarning for falling back to ExtensionArray's
1919
non-pyarrow method
@@ -24,7 +24,9 @@ def fallback_performancewarning(version: str | None = None):
2424
warnings.warn(msg, PerformanceWarning, stacklevel=find_stack_level())
2525

2626

27-
def pyarrow_array_to_numpy_and_mask(arr, dtype: np.dtype):
27+
def pyarrow_array_to_numpy_and_mask(
28+
arr, dtype: np.dtype
29+
) -> tuple[np.ndarray, np.ndarray]:
2830
"""
2931
Convert a primitive pyarrow.Array to a numpy array and boolean mask based
3032
on the buffers of the Array.
@@ -74,12 +76,12 @@ def __init__(self, freq) -> None:
7476
def freq(self):
7577
return self._freq
7678

77-
def __arrow_ext_serialize__(self):
79+
def __arrow_ext_serialize__(self) -> bytes:
7880
metadata = {"freq": self.freq}
7981
return json.dumps(metadata).encode()
8082

8183
@classmethod
82-
def __arrow_ext_deserialize__(cls, storage_type, serialized):
84+
def __arrow_ext_deserialize__(cls, storage_type, serialized) -> ArrowPeriodType:
8385
metadata = json.loads(serialized.decode())
8486
return ArrowPeriodType(metadata["freq"])
8587

@@ -122,7 +124,7 @@ def subtype(self):
122124
return self._subtype
123125

124126
@property
125-
def inclusive(self):
127+
def inclusive(self) -> str:
126128
return self._closed
127129

128130
@property
@@ -134,12 +136,12 @@ def closed(self):
134136
)
135137
return self._closed
136138

137-
def __arrow_ext_serialize__(self):
139+
def __arrow_ext_serialize__(self) -> bytes:
138140
metadata = {"subtype": str(self.subtype), "inclusive": self.inclusive}
139141
return json.dumps(metadata).encode()
140142

141143
@classmethod
142-
def __arrow_ext_deserialize__(cls, storage_type, serialized):
144+
def __arrow_ext_deserialize__(cls, storage_type, serialized) -> ArrowIntervalType:
143145
metadata = json.loads(serialized.decode())
144146
subtype = pyarrow.type_for_alias(metadata["subtype"])
145147
inclusive = metadata["inclusive"]

pandas/core/arrays/arrow/array.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ def take(
368368
indices: TakeIndexer,
369369
allow_fill: bool = False,
370370
fill_value: Any = None,
371-
):
371+
) -> ArrowExtensionArray:
372372
"""
373373
Take elements from an array.
374374

pandas/core/arrays/arrow/dtype.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def construct_array_type(cls):
7777
return ArrowExtensionArray
7878

7979
@classmethod
80-
def construct_from_string(cls, string: str):
80+
def construct_from_string(cls, string: str) -> ArrowDtype:
8181
"""
8282
Construct this type from a string.
8383

pandas/core/arrays/base.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def __ne__(self, other: Any) -> ArrayLike: # type: ignore[override]
460460
"""
461461
return ~(self == other)
462462

463-
def __init_subclass__(cls, **kwargs):
463+
def __init_subclass__(cls, **kwargs) -> None:
464464
factorize = getattr(cls, "factorize")
465465
if (
466466
"use_na_sentinel" not in inspect.signature(factorize).parameters
@@ -770,11 +770,11 @@ def argmax(self, skipna: bool = True) -> int:
770770
return nargminmax(self, "argmax")
771771

772772
def fillna(
773-
self,
773+
self: ExtensionArrayT,
774774
value: object | ArrayLike | None = None,
775775
method: FillnaOptions | None = None,
776776
limit: int | None = None,
777-
):
777+
) -> ExtensionArrayT:
778778
"""
779779
Fill NA/NaN values using the specified method.
780780
@@ -1139,7 +1139,9 @@ def factorize(
11391139

11401140
@Substitution(klass="ExtensionArray")
11411141
@Appender(_extension_array_shared_docs["repeat"])
1142-
def repeat(self, repeats: int | Sequence[int], axis: int | None = None):
1142+
def repeat(
1143+
self: ExtensionArrayT, repeats: int | Sequence[int], axis: int | None = None
1144+
) -> ExtensionArrayT:
11431145
nv.validate_repeat((), {"axis": axis})
11441146
ind = np.arange(len(self)).repeat(repeats)
11451147
return self.take(ind)

0 commit comments

Comments
 (0)