Skip to content

Commit 56f27d7

Browse files
authored
TYP: annotation of __init__ return type (PEP 484) (pandas/core) (#46279)
1 parent e12d4ec commit 56f27d7

28 files changed

+56
-56
lines changed

pandas/core/algorithms.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ def checked_add_with_arr(
10981098

10991099

11001100
class SelectN:
1101-
def __init__(self, obj, n: int, keep: str):
1101+
def __init__(self, obj, n: int, keep: str) -> None:
11021102
self.obj = obj
11031103
self.n = n
11041104
self.keep = keep
@@ -1218,7 +1218,7 @@ class SelectNFrame(SelectN):
12181218
nordered : DataFrame
12191219
"""
12201220

1221-
def __init__(self, obj: DataFrame, n: int, keep: str, columns: IndexLabel):
1221+
def __init__(self, obj: DataFrame, n: int, keep: str, columns: IndexLabel) -> None:
12221222
super().__init__(obj, n, keep)
12231223
if not is_list_like(columns) or isinstance(columns, tuple):
12241224
columns = [columns]

pandas/core/apply.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def __init__(
113113
result_type: str | None,
114114
args,
115115
kwargs,
116-
):
116+
) -> None:
117117
self.obj = obj
118118
self.raw = raw
119119
self.args = args or ()
@@ -1053,7 +1053,7 @@ def __init__(
10531053
convert_dtype: bool,
10541054
args,
10551055
kwargs,
1056-
):
1056+
) -> None:
10571057
self.convert_dtype = convert_dtype
10581058

10591059
super().__init__(
@@ -1157,7 +1157,7 @@ def __init__(
11571157
func: AggFuncType,
11581158
args,
11591159
kwargs,
1160-
):
1160+
) -> None:
11611161
kwargs = kwargs.copy()
11621162
self.axis = obj.obj._get_axis_number(kwargs.get("axis", 0))
11631163
super().__init__(
@@ -1186,7 +1186,7 @@ def __init__(
11861186
func: AggFuncType,
11871187
args,
11881188
kwargs,
1189-
):
1189+
) -> None:
11901190
super().__init__(
11911191
obj,
11921192
func,

pandas/core/describe.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class NDFrameDescriberAbstract(ABC):
106106
Whether to treat datetime dtypes as numeric.
107107
"""
108108

109-
def __init__(self, obj: DataFrame | Series, datetime_is_numeric: bool):
109+
def __init__(self, obj: DataFrame | Series, datetime_is_numeric: bool) -> None:
110110
self.obj = obj
111111
self.datetime_is_numeric = datetime_is_numeric
112112

@@ -156,7 +156,7 @@ def __init__(
156156
include: str | Sequence[str] | None,
157157
exclude: str | Sequence[str] | None,
158158
datetime_is_numeric: bool,
159-
):
159+
) -> None:
160160
self.include = include
161161
self.exclude = exclude
162162

pandas/core/dtypes/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ class Registry:
430430
These are tried in order.
431431
"""
432432

433-
def __init__(self):
433+
def __init__(self) -> None:
434434
self.dtypes: list[type_t[ExtensionDtype]] = []
435435

436436
def register(self, dtype: type_t[ExtensionDtype]) -> None:

pandas/core/dtypes/dtypes.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class CategoricalDtype(PandasExtensionDtype, ExtensionDtype):
181181
_metadata = ("categories", "ordered")
182182
_cache_dtypes: dict[str_type, PandasExtensionDtype] = {}
183183

184-
def __init__(self, categories=None, ordered: Ordered = False):
184+
def __init__(self, categories=None, ordered: Ordered = False) -> None:
185185
self._finalize(categories, ordered, fastpath=False)
186186

187187
@classmethod
@@ -672,7 +672,7 @@ class DatetimeTZDtype(PandasExtensionDtype):
672672
_match = re.compile(r"(datetime64|M8)\[(?P<unit>.+), (?P<tz>.+)\]")
673673
_cache_dtypes: dict[str_type, PandasExtensionDtype] = {}
674674

675-
def __init__(self, unit: str_type | DatetimeTZDtype = "ns", tz=None):
675+
def __init__(self, unit: str_type | DatetimeTZDtype = "ns", tz=None) -> None:
676676
if isinstance(unit, DatetimeTZDtype):
677677
# error: "str" has no attribute "tz"
678678
unit, tz = unit.unit, unit.tz # type: ignore[attr-defined]
@@ -1303,7 +1303,7 @@ class PandasDtype(ExtensionDtype):
13031303

13041304
_metadata = ("_dtype",)
13051305

1306-
def __init__(self, dtype: npt.DTypeLike | PandasDtype | None):
1306+
def __init__(self, dtype: npt.DTypeLike | PandasDtype | None) -> None:
13071307
if isinstance(dtype, PandasDtype):
13081308
# make constructor univalent
13091309
dtype = dtype.numpy_dtype

pandas/core/flags.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Flags:
4444

4545
_keys = {"allows_duplicate_labels"}
4646

47-
def __init__(self, obj, *, allows_duplicate_labels):
47+
def __init__(self, obj, *, allows_duplicate_labels) -> None:
4848
self._allows_duplicate_labels = allows_duplicate_labels
4949
self._obj = weakref.ref(obj)
5050

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ def __init__(
599599
columns: Axes | None = None,
600600
dtype: Dtype | None = None,
601601
copy: bool | None = None,
602-
):
602+
) -> None:
603603

604604
if data is None:
605605
data = {}

pandas/core/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def __init__(
243243
data: Manager,
244244
copy: bool_t = False,
245245
attrs: Mapping[Hashable, Any] | None = None,
246-
):
246+
) -> None:
247247
# copy kwarg is retained for mypy compat, is not used
248248

249249
object.__setattr__(self, "_is_copy", None)

pandas/core/groupby/groupby.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ class GroupByPlot(PandasObject):
533533
Class implementing the .plot attribute for groupby objects.
534534
"""
535535

536-
def __init__(self, groupby: GroupBy):
536+
def __init__(self, groupby: GroupBy) -> None:
537537
self._groupby = groupby
538538

539539
def __call__(self, *args, **kwargs):
@@ -854,7 +854,7 @@ def __init__(
854854
observed: bool = False,
855855
mutated: bool = False,
856856
dropna: bool = True,
857-
):
857+
) -> None:
858858

859859
self._selection = selection
860860

pandas/core/groupby/grouper.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def __init__(
281281
axis: int = 0,
282282
sort: bool = False,
283283
dropna: bool = True,
284-
):
284+
) -> None:
285285
self.key = key
286286
self.level = level
287287
self.freq = freq
@@ -475,7 +475,7 @@ def __init__(
475475
observed: bool = False,
476476
in_axis: bool = False,
477477
dropna: bool = True,
478-
):
478+
) -> None:
479479
self.level = level
480480
self._orig_grouper = grouper
481481
self.grouping_vector = _convert_grouper(index, grouper)

pandas/core/groupby/indexing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def _descending_count(self) -> np.ndarray:
245245

246246
@doc(GroupByIndexingMixin._positional_selector)
247247
class GroupByPositionalSelector:
248-
def __init__(self, groupby_object: groupby.GroupBy):
248+
def __init__(self, groupby_object: groupby.GroupBy) -> None:
249249
self.groupby_object = groupby_object
250250

251251
def __getitem__(self, arg: PositionalIndexer | tuple) -> DataFrame | Series:
@@ -289,7 +289,7 @@ class GroupByNthSelector:
289289
Dynamically substituted for GroupBy.nth to enable both call and index
290290
"""
291291

292-
def __init__(self, groupby_object: groupby.GroupBy):
292+
def __init__(self, groupby_object: groupby.GroupBy) -> None:
293293
self.groupby_object = groupby_object
294294

295295
def __call__(

pandas/core/groupby/ops.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class WrappedCythonOp:
104104
# back to the original dtype.
105105
cast_blocklist = frozenset(["rank", "count", "size", "idxmin", "idxmax"])
106106

107-
def __init__(self, kind: str, how: str):
107+
def __init__(self, kind: str, how: str) -> None:
108108
self.kind = kind
109109
self.how = how
110110

@@ -687,7 +687,7 @@ def __init__(
687687
mutated: bool = False,
688688
indexer: npt.NDArray[np.intp] | None = None,
689689
dropna: bool = True,
690-
):
690+
) -> None:
691691
assert isinstance(axis, Index), axis
692692

693693
self.axis = axis
@@ -1091,7 +1091,7 @@ def __init__(
10911091
binlabels,
10921092
mutated: bool = False,
10931093
indexer=None,
1094-
):
1094+
) -> None:
10951095
self.bins = ensure_int64(bins)
10961096
self.binlabels = ensure_index(binlabels)
10971097
self.mutated = mutated
@@ -1237,7 +1237,7 @@ def __init__(
12371237
labels: npt.NDArray[np.intp],
12381238
ngroups: int,
12391239
axis: int = 0,
1240-
):
1240+
) -> None:
12411241
self.data = data
12421242
self.labels = ensure_platform_int(labels) # _should_ already be np.intp
12431243
self.ngroups = ngroups

pandas/core/indexers/objects.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class BaseIndexer:
4545

4646
def __init__(
4747
self, index_array: np.ndarray | None = None, window_size: int = 0, **kwargs
48-
):
48+
) -> None:
4949
"""
5050
Parameters
5151
----------
@@ -139,7 +139,7 @@ def __init__(
139139
index=None,
140140
offset=None,
141141
**kwargs,
142-
):
142+
) -> None:
143143
super().__init__(index_array, window_size, **kwargs)
144144
self.index = index
145145
self.offset = offset
@@ -300,7 +300,7 @@ def __init__(
300300
window_indexer: type[BaseIndexer] = BaseIndexer,
301301
indexer_kwargs: dict | None = None,
302302
**kwargs,
303-
):
303+
) -> None:
304304
"""
305305
Parameters
306306
----------

pandas/core/indexes/accessors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Properties(PandasDelegate, PandasObject, NoNewAttributesMixin):
4747
"name",
4848
}
4949

50-
def __init__(self, data: Series, orig):
50+
def __init__(self, data: Series, orig) -> None:
5151
if not isinstance(data, ABCSeries):
5252
raise TypeError(
5353
f"cannot convert an object of type {type(data)} to a datetimelike index"

pandas/core/internals/array_manager.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def __init__(
129129
arrays: list[np.ndarray | ExtensionArray],
130130
axes: list[Index],
131131
verify_integrity: bool = True,
132-
):
132+
) -> None:
133133
raise NotImplementedError
134134

135135
def make_empty(self: T, axes=None) -> T:
@@ -710,7 +710,7 @@ def __init__(
710710
arrays: list[np.ndarray | ExtensionArray],
711711
axes: list[Index],
712712
verify_integrity: bool = True,
713-
):
713+
) -> None:
714714
# Note: we are storing the axes in "_axes" in the (row, columns) order
715715
# which contrasts the order how it is stored in BlockManager
716716
self._axes = axes
@@ -1182,7 +1182,7 @@ def __init__(
11821182
arrays: list[np.ndarray | ExtensionArray],
11831183
axes: list[Index],
11841184
verify_integrity: bool = True,
1185-
):
1185+
) -> None:
11861186
self._axes = axes
11871187
self.arrays = arrays
11881188

@@ -1347,7 +1347,7 @@ class NullArrayProxy:
13471347

13481348
ndim = 1
13491349

1350-
def __init__(self, n: int):
1350+
def __init__(self, n: int) -> None:
13511351
self.n = n
13521352

13531353
@property

pandas/core/internals/concat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def _get_mgr_concatenation_plan(mgr: BlockManager):
382382

383383

384384
class JoinUnit:
385-
def __init__(self, block: Block):
385+
def __init__(self, block: Block) -> None:
386386
self.block = block
387387

388388
def __repr__(self) -> str:

pandas/core/internals/managers.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class BaseBlockManager(DataManager):
146146
_known_consolidated: bool
147147
_is_consolidated: bool
148148

149-
def __init__(self, blocks, axes, verify_integrity: bool = True):
149+
def __init__(self, blocks, axes, verify_integrity: bool = True) -> None:
150150
raise NotImplementedError
151151

152152
@classmethod
@@ -886,7 +886,7 @@ def __init__(
886886
blocks: Sequence[Block],
887887
axes: Sequence[Index],
888888
verify_integrity: bool = True,
889-
):
889+
) -> None:
890890

891891
if verify_integrity:
892892
# Assertion disabled for performance
@@ -1676,7 +1676,7 @@ def __init__(
16761676
axis: Index,
16771677
verify_integrity: bool = False,
16781678
fastpath=lib.no_default,
1679-
):
1679+
) -> None:
16801680
# Assertions disabled for performance
16811681
# assert isinstance(block, Block), type(block)
16821682
# assert isinstance(axis, Index), type(axis)

pandas/core/nanops.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def set_use_bottleneck(v: bool = True) -> None:
7272

7373

7474
class disallow:
75-
def __init__(self, *dtypes: Dtype):
75+
def __init__(self, *dtypes: Dtype) -> None:
7676
super().__init__()
7777
self.dtypes = tuple(pandas_dtype(dtype).type for dtype in dtypes)
7878

@@ -104,7 +104,7 @@ def _f(*args, **kwargs):
104104

105105

106106
class bottleneck_switch:
107-
def __init__(self, name=None, **kwargs):
107+
def __init__(self, name=None, **kwargs) -> None:
108108
self.name = name
109109
self.kwargs = kwargs
110110

pandas/core/resample.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def __init__(
151151
*,
152152
selection=None,
153153
**kwargs,
154-
):
154+
) -> None:
155155
self.groupby = groupby
156156
self.keys = None
157157
self.sort = True
@@ -1060,7 +1060,7 @@ class _GroupByMixin(PandasObject):
10601060
_attributes: list[str] # in practice the same as Resampler._attributes
10611061
_selection: IndexLabel | None = None
10621062

1063-
def __init__(self, obj, parent=None, groupby=None, **kwargs):
1063+
def __init__(self, obj, parent=None, groupby=None, **kwargs) -> None:
10641064
# reached via ._gotitem and _get_resampler_for_grouping
10651065

10661066
if parent is None:
@@ -1478,7 +1478,7 @@ def __init__(
14781478
origin: str | TimestampConvertibleTypes = "start_day",
14791479
offset: TimedeltaConvertibleTypes | None = None,
14801480
**kwargs,
1481-
):
1481+
) -> None:
14821482
# Check for correctness of the keyword arguments which would
14831483
# otherwise silently use the default if misspelled
14841484
if label not in {None, "left", "right"}:

pandas/core/reshape/concat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def __init__(
377377
verify_integrity: bool = False,
378378
copy: bool = True,
379379
sort=False,
380-
):
380+
) -> None:
381381
if isinstance(objs, (ABCSeries, ABCDataFrame, str)):
382382
raise TypeError(
383383
"first argument must be an iterable of pandas "

0 commit comments

Comments
 (0)