Skip to content

TYP: more return annotations in core/ #47618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ def getMixedTypeDict():
return index, data


def makeMixedDataFrame():
def makeMixedDataFrame() -> DataFrame:
return DataFrame(getMixedTypeDict()[1])


Expand Down
2 changes: 1 addition & 1 deletion pandas/core/array_algos/replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def _check_comparison_types(

def replace_regex(
values: ArrayLike, rx: re.Pattern, value, mask: npt.NDArray[np.bool_] | None
):
) -> None:
"""
Parameters
----------
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/arrays/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
NumpyValueArrayLike,
)

from pandas import Series


def ravel_compat(meth: F) -> F:
"""
Expand Down Expand Up @@ -259,7 +261,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
Expand Down Expand Up @@ -433,7 +435,7 @@ def insert(
# These are not part of the EA API, but we implement them because
# pandas assumes they're there.

def value_counts(self, dropna: bool = True):
def value_counts(self, dropna: bool = True) -> Series:
"""
Return a Series containing counts of unique values.

Expand Down
16 changes: 9 additions & 7 deletions pandas/core/arrays/arrow/_arrow_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,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
Expand All @@ -24,7 +24,9 @@ def fallback_performancewarning(version: str | None = None):
warnings.warn(msg, PerformanceWarning, stacklevel=find_stack_level())


def pyarrow_array_to_numpy_and_mask(arr, dtype: np.dtype):
def pyarrow_array_to_numpy_and_mask(
arr, dtype: np.dtype
) -> tuple[np.ndarray, np.ndarray]:
"""
Convert a primitive pyarrow.Array to a numpy array and boolean mask based
on the buffers of the Array.
Expand Down Expand Up @@ -74,12 +76,12 @@ def __init__(self, freq) -> None:
def freq(self):
return self._freq

def __arrow_ext_serialize__(self):
def __arrow_ext_serialize__(self) -> bytes:
metadata = {"freq": self.freq}
return json.dumps(metadata).encode()

@classmethod
def __arrow_ext_deserialize__(cls, storage_type, serialized):
def __arrow_ext_deserialize__(cls, storage_type, serialized) -> ArrowPeriodType:
metadata = json.loads(serialized.decode())
return ArrowPeriodType(metadata["freq"])

Expand Down Expand Up @@ -122,7 +124,7 @@ def subtype(self):
return self._subtype

@property
def inclusive(self):
def inclusive(self) -> str:
return self._closed

@property
Expand All @@ -134,12 +136,12 @@ def closed(self):
)
return self._closed

def __arrow_ext_serialize__(self):
def __arrow_ext_serialize__(self) -> bytes:
metadata = {"subtype": str(self.subtype), "inclusive": self.inclusive}
return json.dumps(metadata).encode()

@classmethod
def __arrow_ext_deserialize__(cls, storage_type, serialized):
def __arrow_ext_deserialize__(cls, storage_type, serialized) -> ArrowIntervalType:
metadata = json.loads(serialized.decode())
subtype = pyarrow.type_for_alias(metadata["subtype"])
inclusive = metadata["inclusive"]
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def take(
indices: TakeIndexer,
allow_fill: bool = False,
fill_value: Any = None,
):
) -> ArrowExtensionArray:
"""
Take elements from an array.

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/arrow/dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def construct_array_type(cls):
return ArrowExtensionArray

@classmethod
def construct_from_string(cls, string: str):
def construct_from_string(cls, string: str) -> ArrowDtype:
"""
Construct this type from a string.

Expand Down
10 changes: 6 additions & 4 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def __ne__(self, other: Any) -> ArrayLike: # type: ignore[override]
"""
return ~(self == other)

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

def fillna(
self,
self: ExtensionArrayT,
value: object | ArrayLike | None = None,
method: FillnaOptions | None = None,
limit: int | None = None,
):
) -> ExtensionArrayT:
"""
Fill NA/NaN values using the specified method.

Expand Down Expand Up @@ -1139,7 +1139,9 @@ def factorize(

@Substitution(klass="ExtensionArray")
@Appender(_extension_array_shared_docs["repeat"])
def repeat(self, repeats: int | Sequence[int], axis: int | None = None):
def repeat(
self: ExtensionArrayT, repeats: int | Sequence[int], axis: int | None = None
) -> ExtensionArrayT:
nv.validate_repeat((), {"axis": axis})
ind = np.arange(len(self)).repeat(repeats)
return self.take(ind)
Expand Down
Loading