Skip to content

TYP: annotation of __init__ return type (PEP 484) (pandas/core/arrays) #46255

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 2 commits into from
Mar 8, 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
4 changes: 2 additions & 2 deletions pandas/core/arrays/_arrow_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def pyarrow_array_to_numpy_and_mask(arr, dtype: np.dtype):


class ArrowPeriodType(pyarrow.ExtensionType):
def __init__(self, freq):
def __init__(self, freq) -> None:
# attributes need to be set first before calling
# super init (as that calls serialize)
self._freq = freq
Expand Down Expand Up @@ -88,7 +88,7 @@ def to_pandas_dtype(self):


class ArrowIntervalType(pyarrow.ExtensionType):
def __init__(self, subtype, closed):
def __init__(self, subtype, closed) -> None:
# attributes need to be set first before calling
# super init (as that calls serialize)
assert closed in VALID_CLOSED
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ class ArrowExtensionArray(ExtensionArray):

_data: pa.ChunkedArray

def __init__(self, values: pa.ChunkedArray):
def __init__(self, values: pa.ChunkedArray) -> None:
self._data = values

def __arrow_array__(self, type=None):
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/arrays/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ class BooleanArray(BaseMaskedArray):
_TRUE_VALUES = {"True", "TRUE", "true", "1", "1.0"}
_FALSE_VALUES = {"False", "FALSE", "false", "0", "0.0"}

def __init__(self, values: np.ndarray, mask: np.ndarray, copy: bool = False):
def __init__(
self, values: np.ndarray, mask: np.ndarray, copy: bool = False
) -> None:
if not (isinstance(values, np.ndarray) and values.dtype == np.bool_):
raise TypeError(
"values should be boolean numpy array. Use "
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def __init__(
dtype: Dtype | None = None,
fastpath: bool = False,
copy: bool = True,
):
) -> None:

dtype = CategoricalDtype._from_values_or_dtype(
values, categories, ordered, dtype
Expand Down Expand Up @@ -2704,7 +2704,7 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
Categories (3, object): ['a', 'b', 'c']
"""

def __init__(self, data):
def __init__(self, data) -> None:
self._validate(data)
self._parent = data.values
self._index = data.index
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class DatetimeLikeArrayMixin(OpsMixin, NDArrayBackedExtensionArray):
def _can_hold_na(self) -> bool:
return True

def __init__(self, data, dtype: Dtype | None = None, freq=None, copy=False):
def __init__(self, data, dtype: Dtype | None = None, freq=None, copy=False) -> None:
raise AbstractMethodError(self)

@property
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ class DatetimeArray(dtl.TimelikeOps, dtl.DatelikeOps):
_dtype: np.dtype | DatetimeTZDtype
_freq = None

def __init__(self, values, dtype=DT64NS_DTYPE, freq=None, copy: bool = False):
def __init__(
self, values, dtype=DT64NS_DTYPE, freq=None, copy: bool = False
) -> None:
values = extract_array(values, extract_numpy=True)
if isinstance(values, IntegerArray):
values = values.to_numpy("int64", na_value=iNaT)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class BaseMaskedArray(OpsMixin, ExtensionArray):

def __init__(
self, values: np.ndarray, mask: npt.NDArray[np.bool_], copy: bool = False
):
) -> None:
# values is supposed to already be validated in the subclass
if not (isinstance(mask, np.ndarray) and mask.dtype == np.bool_):
raise TypeError(
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class NumericArray(BaseMaskedArray):

def __init__(
self, values: np.ndarray, mask: npt.NDArray[np.bool_], copy: bool = False
):
) -> None:
checker = self._dtype_cls._checker
if not (isinstance(values, np.ndarray) and checker(values.dtype)):
descr = (
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/numpy_.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class PandasArray(
# ------------------------------------------------------------------------
# Constructors

def __init__(self, values: np.ndarray | PandasArray, copy: bool = False):
def __init__(self, values: np.ndarray | PandasArray, copy: bool = False) -> None:
if isinstance(values, type(self)):
values = values._ndarray
if not isinstance(values, np.ndarray):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class PeriodArray(dtl.DatelikeOps):

def __init__(
self, values, dtype: Dtype | None = None, freq=None, copy: bool = False
):
) -> None:
freq = validate_dtype_freq(dtype, freq)

if freq is not None:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/sparse/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class BaseAccessor:
_validation_msg = "Can only use the '.sparse' accessor with Sparse data."

def __init__(self, data=None):
def __init__(self, data=None) -> None:
self._parent = data
self._validate(data)

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def __init__(
kind: SparseIndexKind = "integer",
dtype: Dtype | None = None,
copy: bool = False,
):
) -> None:

if fill_value is None and isinstance(dtype, SparseDtype):
fill_value = dtype.fill_value
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/sparse/dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class SparseDtype(ExtensionDtype):
# hash(nan) is (sometimes?) 0.
_metadata = ("_dtype", "_fill_value", "_is_na_fill_value")

def __init__(self, dtype: Dtype = np.float64, fill_value: Any = None):
def __init__(self, dtype: Dtype = np.float64, fill_value: Any = None) -> None:

if isinstance(dtype, type(self)):
if fill_value is None:
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/string_.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class StringDtype(ExtensionDtype):
na_value = libmissing.NA
_metadata = ("storage",)

def __init__(self, storage=None):
def __init__(self, storage=None) -> None:
if storage is None:
storage = get_option("mode.string_storage")
if storage not in {"python", "pyarrow"}:
Expand Down Expand Up @@ -317,7 +317,7 @@ class StringArray(BaseStringArray, PandasArray):
# undo the PandasArray hack
_typ = "extension"

def __init__(self, values, copy=False):
def __init__(self, values, copy=False) -> None:
values = extract_array(values)

super().__init__(values, copy=copy)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/string_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class ArrowStringArray(
Length: 4, dtype: string
"""

def __init__(self, values):
def __init__(self, values) -> None:
self._dtype = StringDtype(storage="pyarrow")
if isinstance(values, pa.Array):
self._data = pa.chunked_array([values])
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def dtype(self) -> np.dtype: # type: ignore[override]

def __init__(
self, values, dtype=TD64NS_DTYPE, freq=lib.no_default, copy: bool = False
):
) -> None:
values = extract_array(values, extract_numpy=True)
if isinstance(values, IntegerArray):
values = values.to_numpy("int64", na_value=tslibs.iNaT)
Expand Down