Skip to content

Commit 3b795d9

Browse files
TYP: annotation of __init__ return type (PEP 484) (pandas/core/arrays) (#46255)
1 parent 41d248e commit 3b795d9

16 files changed

+23
-19
lines changed

pandas/core/arrays/_arrow_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def pyarrow_array_to_numpy_and_mask(arr, dtype: np.dtype):
4848

4949

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

8989

9090
class ArrowIntervalType(pyarrow.ExtensionType):
91-
def __init__(self, subtype, closed):
91+
def __init__(self, subtype, closed) -> None:
9292
# attributes need to be set first before calling
9393
# super init (as that calls serialize)
9494
assert closed in VALID_CLOSED

pandas/core/arrays/_mixins.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ class ArrowExtensionArray(ExtensionArray):
532532

533533
_data: pa.ChunkedArray
534534

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

538538
def __arrow_array__(self, type=None):

pandas/core/arrays/boolean.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,9 @@ class BooleanArray(BaseMaskedArray):
297297
_TRUE_VALUES = {"True", "TRUE", "true", "1", "1.0"}
298298
_FALSE_VALUES = {"False", "FALSE", "false", "0", "0.0"}
299299

300-
def __init__(self, values: np.ndarray, mask: np.ndarray, copy: bool = False):
300+
def __init__(
301+
self, values: np.ndarray, mask: np.ndarray, copy: bool = False
302+
) -> None:
301303
if not (isinstance(values, np.ndarray) and values.dtype == np.bool_):
302304
raise TypeError(
303305
"values should be boolean numpy array. Use "

pandas/core/arrays/categorical.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def __init__(
367367
dtype: Dtype | None = None,
368368
fastpath: bool = False,
369369
copy: bool = True,
370-
):
370+
) -> None:
371371

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

2707-
def __init__(self, data):
2707+
def __init__(self, data) -> None:
27082708
self._validate(data)
27092709
self._parent = data.values
27102710
self._index = data.index

pandas/core/arrays/datetimelike.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class DatetimeLikeArrayMixin(OpsMixin, NDArrayBackedExtensionArray):
169169
def _can_hold_na(self) -> bool:
170170
return True
171171

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

175175
@property

pandas/core/arrays/datetimes.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ class DatetimeArray(dtl.TimelikeOps, dtl.DatelikeOps):
254254
_dtype: np.dtype | DatetimeTZDtype
255255
_freq = None
256256

257-
def __init__(self, values, dtype=DT64NS_DTYPE, freq=None, copy: bool = False):
257+
def __init__(
258+
self, values, dtype=DT64NS_DTYPE, freq=None, copy: bool = False
259+
) -> None:
258260
values = extract_array(values, extract_numpy=True)
259261
if isinstance(values, IntegerArray):
260262
values = values.to_numpy("int64", na_value=iNaT)

pandas/core/arrays/masked.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class BaseMaskedArray(OpsMixin, ExtensionArray):
107107

108108
def __init__(
109109
self, values: np.ndarray, mask: npt.NDArray[np.bool_], copy: bool = False
110-
):
110+
) -> None:
111111
# values is supposed to already be validated in the subclass
112112
if not (isinstance(mask, np.ndarray) and mask.dtype == np.bool_):
113113
raise TypeError(

pandas/core/arrays/numeric.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class NumericArray(BaseMaskedArray):
222222

223223
def __init__(
224224
self, values: np.ndarray, mask: npt.NDArray[np.bool_], copy: bool = False
225-
):
225+
) -> None:
226226
checker = self._dtype_cls._checker
227227
if not (isinstance(values, np.ndarray) and checker(values.dtype)):
228228
descr = (

pandas/core/arrays/numpy_.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class PandasArray(
6666
# ------------------------------------------------------------------------
6767
# Constructors
6868

69-
def __init__(self, values: np.ndarray | PandasArray, copy: bool = False):
69+
def __init__(self, values: np.ndarray | PandasArray, copy: bool = False) -> None:
7070
if isinstance(values, type(self)):
7171
values = values._ndarray
7272
if not isinstance(values, np.ndarray):

pandas/core/arrays/period.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class PeriodArray(dtl.DatelikeOps):
201201

202202
def __init__(
203203
self, values, dtype: Dtype | None = None, freq=None, copy: bool = False
204-
):
204+
) -> None:
205205
freq = validate_dtype_freq(dtype, freq)
206206

207207
if freq is not None:

pandas/core/arrays/sparse/accessor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
class BaseAccessor:
1818
_validation_msg = "Can only use the '.sparse' accessor with Sparse data."
1919

20-
def __init__(self, data=None):
20+
def __init__(self, data=None) -> None:
2121
self._parent = data
2222
self._validate(data)
2323

pandas/core/arrays/sparse/array.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def __init__(
373373
kind: SparseIndexKind = "integer",
374374
dtype: Dtype | None = None,
375375
copy: bool = False,
376-
):
376+
) -> None:
377377

378378
if fill_value is None and isinstance(dtype, SparseDtype):
379379
fill_value = dtype.fill_value

pandas/core/arrays/sparse/dtype.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class SparseDtype(ExtensionDtype):
8181
# hash(nan) is (sometimes?) 0.
8282
_metadata = ("_dtype", "_fill_value", "_is_na_fill_value")
8383

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

8686
if isinstance(dtype, type(self)):
8787
if fill_value is None:

pandas/core/arrays/string_.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class StringDtype(ExtensionDtype):
9797
na_value = libmissing.NA
9898
_metadata = ("storage",)
9999

100-
def __init__(self, storage=None):
100+
def __init__(self, storage=None) -> None:
101101
if storage is None:
102102
storage = get_option("mode.string_storage")
103103
if storage not in {"python", "pyarrow"}:
@@ -317,7 +317,7 @@ class StringArray(BaseStringArray, PandasArray):
317317
# undo the PandasArray hack
318318
_typ = "extension"
319319

320-
def __init__(self, values, copy=False):
320+
def __init__(self, values, copy=False) -> None:
321321
values = extract_array(values)
322322

323323
super().__init__(values, copy=copy)

pandas/core/arrays/string_arrow.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class ArrowStringArray(
141141
Length: 4, dtype: string
142142
"""
143143

144-
def __init__(self, values):
144+
def __init__(self, values) -> None:
145145
self._dtype = StringDtype(storage="pyarrow")
146146
if isinstance(values, pa.Array):
147147
self._data = pa.chunked_array([values])

pandas/core/arrays/timedeltas.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def dtype(self) -> np.dtype: # type: ignore[override]
182182

183183
def __init__(
184184
self, values, dtype=TD64NS_DTYPE, freq=lib.no_default, copy: bool = False
185-
):
185+
) -> None:
186186
values = extract_array(values, extract_numpy=True)
187187
if isinstance(values, IntegerArray):
188188
values = values.to_numpy("int64", na_value=tslibs.iNaT)

0 commit comments

Comments
 (0)