Skip to content

Commit

Permalink
TYP: annotation of __init__ return type (PEP 484) (pandas/core) (#46279)
Browse files Browse the repository at this point in the history
  • Loading branch information
nafarya authored Mar 16, 2022
1 parent e12d4ec commit 56f27d7
Show file tree
Hide file tree
Showing 28 changed files with 56 additions and 56 deletions.
4 changes: 2 additions & 2 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ def checked_add_with_arr(


class SelectN:
def __init__(self, obj, n: int, keep: str):
def __init__(self, obj, n: int, keep: str) -> None:
self.obj = obj
self.n = n
self.keep = keep
Expand Down Expand Up @@ -1218,7 +1218,7 @@ class SelectNFrame(SelectN):
nordered : DataFrame
"""

def __init__(self, obj: DataFrame, n: int, keep: str, columns: IndexLabel):
def __init__(self, obj: DataFrame, n: int, keep: str, columns: IndexLabel) -> None:
super().__init__(obj, n, keep)
if not is_list_like(columns) or isinstance(columns, tuple):
columns = [columns]
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __init__(
result_type: str | None,
args,
kwargs,
):
) -> None:
self.obj = obj
self.raw = raw
self.args = args or ()
Expand Down Expand Up @@ -1053,7 +1053,7 @@ def __init__(
convert_dtype: bool,
args,
kwargs,
):
) -> None:
self.convert_dtype = convert_dtype

super().__init__(
Expand Down Expand Up @@ -1157,7 +1157,7 @@ def __init__(
func: AggFuncType,
args,
kwargs,
):
) -> None:
kwargs = kwargs.copy()
self.axis = obj.obj._get_axis_number(kwargs.get("axis", 0))
super().__init__(
Expand Down Expand Up @@ -1186,7 +1186,7 @@ def __init__(
func: AggFuncType,
args,
kwargs,
):
) -> None:
super().__init__(
obj,
func,
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class NDFrameDescriberAbstract(ABC):
Whether to treat datetime dtypes as numeric.
"""

def __init__(self, obj: DataFrame | Series, datetime_is_numeric: bool):
def __init__(self, obj: DataFrame | Series, datetime_is_numeric: bool) -> None:
self.obj = obj
self.datetime_is_numeric = datetime_is_numeric

Expand Down Expand Up @@ -156,7 +156,7 @@ def __init__(
include: str | Sequence[str] | None,
exclude: str | Sequence[str] | None,
datetime_is_numeric: bool,
):
) -> None:
self.include = include
self.exclude = exclude

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/dtypes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ class Registry:
These are tried in order.
"""

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

def register(self, dtype: type_t[ExtensionDtype]) -> None:
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class CategoricalDtype(PandasExtensionDtype, ExtensionDtype):
_metadata = ("categories", "ordered")
_cache_dtypes: dict[str_type, PandasExtensionDtype] = {}

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

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

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

_metadata = ("_dtype",)

def __init__(self, dtype: npt.DTypeLike | PandasDtype | None):
def __init__(self, dtype: npt.DTypeLike | PandasDtype | None) -> None:
if isinstance(dtype, PandasDtype):
# make constructor univalent
dtype = dtype.numpy_dtype
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Flags:

_keys = {"allows_duplicate_labels"}

def __init__(self, obj, *, allows_duplicate_labels):
def __init__(self, obj, *, allows_duplicate_labels) -> None:
self._allows_duplicate_labels = allows_duplicate_labels
self._obj = weakref.ref(obj)

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ def __init__(
columns: Axes | None = None,
dtype: Dtype | None = None,
copy: bool | None = None,
):
) -> None:

if data is None:
data = {}
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def __init__(
data: Manager,
copy: bool_t = False,
attrs: Mapping[Hashable, Any] | None = None,
):
) -> None:
# copy kwarg is retained for mypy compat, is not used

object.__setattr__(self, "_is_copy", None)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ class GroupByPlot(PandasObject):
Class implementing the .plot attribute for groupby objects.
"""

def __init__(self, groupby: GroupBy):
def __init__(self, groupby: GroupBy) -> None:
self._groupby = groupby

def __call__(self, *args, **kwargs):
Expand Down Expand Up @@ -854,7 +854,7 @@ def __init__(
observed: bool = False,
mutated: bool = False,
dropna: bool = True,
):
) -> None:

self._selection = selection

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/groupby/grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def __init__(
axis: int = 0,
sort: bool = False,
dropna: bool = True,
):
) -> None:
self.key = key
self.level = level
self.freq = freq
Expand Down Expand Up @@ -475,7 +475,7 @@ def __init__(
observed: bool = False,
in_axis: bool = False,
dropna: bool = True,
):
) -> None:
self.level = level
self._orig_grouper = grouper
self.grouping_vector = _convert_grouper(index, grouper)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/groupby/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def _descending_count(self) -> np.ndarray:

@doc(GroupByIndexingMixin._positional_selector)
class GroupByPositionalSelector:
def __init__(self, groupby_object: groupby.GroupBy):
def __init__(self, groupby_object: groupby.GroupBy) -> None:
self.groupby_object = groupby_object

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

def __init__(self, groupby_object: groupby.GroupBy):
def __init__(self, groupby_object: groupby.GroupBy) -> None:
self.groupby_object = groupby_object

def __call__(
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/groupby/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class WrappedCythonOp:
# back to the original dtype.
cast_blocklist = frozenset(["rank", "count", "size", "idxmin", "idxmax"])

def __init__(self, kind: str, how: str):
def __init__(self, kind: str, how: str) -> None:
self.kind = kind
self.how = how

Expand Down Expand Up @@ -687,7 +687,7 @@ def __init__(
mutated: bool = False,
indexer: npt.NDArray[np.intp] | None = None,
dropna: bool = True,
):
) -> None:
assert isinstance(axis, Index), axis

self.axis = axis
Expand Down Expand Up @@ -1091,7 +1091,7 @@ def __init__(
binlabels,
mutated: bool = False,
indexer=None,
):
) -> None:
self.bins = ensure_int64(bins)
self.binlabels = ensure_index(binlabels)
self.mutated = mutated
Expand Down Expand Up @@ -1237,7 +1237,7 @@ def __init__(
labels: npt.NDArray[np.intp],
ngroups: int,
axis: int = 0,
):
) -> None:
self.data = data
self.labels = ensure_platform_int(labels) # _should_ already be np.intp
self.ngroups = ngroups
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/indexers/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class BaseIndexer:

def __init__(
self, index_array: np.ndarray | None = None, window_size: int = 0, **kwargs
):
) -> None:
"""
Parameters
----------
Expand Down Expand Up @@ -139,7 +139,7 @@ def __init__(
index=None,
offset=None,
**kwargs,
):
) -> None:
super().__init__(index_array, window_size, **kwargs)
self.index = index
self.offset = offset
Expand Down Expand Up @@ -300,7 +300,7 @@ def __init__(
window_indexer: type[BaseIndexer] = BaseIndexer,
indexer_kwargs: dict | None = None,
**kwargs,
):
) -> None:
"""
Parameters
----------
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Properties(PandasDelegate, PandasObject, NoNewAttributesMixin):
"name",
}

def __init__(self, data: Series, orig):
def __init__(self, data: Series, orig) -> None:
if not isinstance(data, ABCSeries):
raise TypeError(
f"cannot convert an object of type {type(data)} to a datetimelike index"
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/internals/array_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def __init__(
arrays: list[np.ndarray | ExtensionArray],
axes: list[Index],
verify_integrity: bool = True,
):
) -> None:
raise NotImplementedError

def make_empty(self: T, axes=None) -> T:
Expand Down Expand Up @@ -710,7 +710,7 @@ def __init__(
arrays: list[np.ndarray | ExtensionArray],
axes: list[Index],
verify_integrity: bool = True,
):
) -> None:
# Note: we are storing the axes in "_axes" in the (row, columns) order
# which contrasts the order how it is stored in BlockManager
self._axes = axes
Expand Down Expand Up @@ -1182,7 +1182,7 @@ def __init__(
arrays: list[np.ndarray | ExtensionArray],
axes: list[Index],
verify_integrity: bool = True,
):
) -> None:
self._axes = axes
self.arrays = arrays

Expand Down Expand Up @@ -1347,7 +1347,7 @@ class NullArrayProxy:

ndim = 1

def __init__(self, n: int):
def __init__(self, n: int) -> None:
self.n = n

@property
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def _get_mgr_concatenation_plan(mgr: BlockManager):


class JoinUnit:
def __init__(self, block: Block):
def __init__(self, block: Block) -> None:
self.block = block

def __repr__(self) -> str:
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class BaseBlockManager(DataManager):
_known_consolidated: bool
_is_consolidated: bool

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

@classmethod
Expand Down Expand Up @@ -886,7 +886,7 @@ def __init__(
blocks: Sequence[Block],
axes: Sequence[Index],
verify_integrity: bool = True,
):
) -> None:

if verify_integrity:
# Assertion disabled for performance
Expand Down Expand Up @@ -1676,7 +1676,7 @@ def __init__(
axis: Index,
verify_integrity: bool = False,
fastpath=lib.no_default,
):
) -> None:
# Assertions disabled for performance
# assert isinstance(block, Block), type(block)
# assert isinstance(axis, Index), type(axis)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def set_use_bottleneck(v: bool = True) -> None:


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

Expand Down Expand Up @@ -104,7 +104,7 @@ def _f(*args, **kwargs):


class bottleneck_switch:
def __init__(self, name=None, **kwargs):
def __init__(self, name=None, **kwargs) -> None:
self.name = name
self.kwargs = kwargs

Expand Down
6 changes: 3 additions & 3 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def __init__(
*,
selection=None,
**kwargs,
):
) -> None:
self.groupby = groupby
self.keys = None
self.sort = True
Expand Down Expand Up @@ -1060,7 +1060,7 @@ class _GroupByMixin(PandasObject):
_attributes: list[str] # in practice the same as Resampler._attributes
_selection: IndexLabel | None = None

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

if parent is None:
Expand Down Expand Up @@ -1478,7 +1478,7 @@ def __init__(
origin: str | TimestampConvertibleTypes = "start_day",
offset: TimedeltaConvertibleTypes | None = None,
**kwargs,
):
) -> None:
# Check for correctness of the keyword arguments which would
# otherwise silently use the default if misspelled
if label not in {None, "left", "right"}:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/reshape/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def __init__(
verify_integrity: bool = False,
copy: bool = True,
sort=False,
):
) -> None:
if isinstance(objs, (ABCSeries, ABCDataFrame, str)):
raise TypeError(
"first argument must be an iterable of pandas "
Expand Down
Loading

0 comments on commit 56f27d7

Please sign in to comment.