Skip to content

TYPING: some type hints for core.dtypes.common #27564

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
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
28 changes: 14 additions & 14 deletions pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
""" common type operations """
from typing import Any, Union
from typing import Any, Callable, Union
import warnings

import numpy as np
Expand Down Expand Up @@ -141,7 +141,7 @@ def ensure_categorical(arr):
return arr


def ensure_int_or_float(arr: ArrayLike, copy=False) -> np.array:
def ensure_int_or_float(arr: ArrayLike, copy: bool = False) -> np.array:
"""
Ensure that an dtype array of some integer dtype
has an int64 dtype if possible.
Expand Down Expand Up @@ -206,12 +206,12 @@ def ensure_python_int(value: Union[int, np.integer]) -> int:
return new_value


def classes(*klasses):
def classes(*klasses) -> Callable:
""" evaluate if the tipo is a subclass of the klasses """
return lambda tipo: issubclass(tipo, klasses)


def classes_and_not_datetimelike(*klasses):
def classes_and_not_datetimelike(*klasses) -> Callable:
"""
evaluate if the tipo is a subclass of the klasses
and not a datetimelike
Expand Down Expand Up @@ -354,7 +354,7 @@ def is_scipy_sparse(arr):
return _is_scipy_sparse(arr)


def is_categorical(arr):
def is_categorical(arr) -> bool:
"""
Check whether an array-like is a Categorical instance.

Expand Down Expand Up @@ -675,7 +675,7 @@ def is_interval_dtype(arr_or_dtype):
return IntervalDtype.is_dtype(arr_or_dtype)


def is_categorical_dtype(arr_or_dtype):
def is_categorical_dtype(arr_or_dtype) -> bool:
"""
Check whether an array-like or dtype is of the Categorical dtype.

Expand Down Expand Up @@ -898,7 +898,7 @@ def is_dtype_equal(source, target):
return False


def is_any_int_dtype(arr_or_dtype):
def is_any_int_dtype(arr_or_dtype) -> bool:
"""Check whether the provided array or dtype is of an integer dtype.

In this function, timedelta64 instances are also considered "any-integer"
Expand Down Expand Up @@ -1160,7 +1160,7 @@ def is_int64_dtype(arr_or_dtype):
return _is_dtype_type(arr_or_dtype, classes(np.int64))


def is_datetime64_any_dtype(arr_or_dtype):
def is_datetime64_any_dtype(arr_or_dtype) -> bool:
"""
Check whether the provided array or dtype is of the datetime64 dtype.

Expand Down Expand Up @@ -1320,7 +1320,7 @@ def is_datetime_or_timedelta_dtype(arr_or_dtype):
return _is_dtype_type(arr_or_dtype, classes(np.datetime64, np.timedelta64))


def _is_unorderable_exception(e):
def _is_unorderable_exception(e: TypeError) -> bool:
"""
Check if the exception raised is an unorderable exception.

Expand Down Expand Up @@ -1616,7 +1616,7 @@ def is_float_dtype(arr_or_dtype):
return _is_dtype_type(arr_or_dtype, classes(np.floating))


def is_bool_dtype(arr_or_dtype):
def is_bool_dtype(arr_or_dtype) -> bool:
"""
Check whether the provided array or dtype is of a boolean dtype.

Expand Down Expand Up @@ -1789,7 +1789,7 @@ def is_extension_array_dtype(arr_or_dtype):
return isinstance(dtype, ExtensionDtype) or registry.find(dtype) is not None


def is_complex_dtype(arr_or_dtype):
def is_complex_dtype(arr_or_dtype) -> bool:
"""
Check whether the provided array or dtype is of a complex dtype.

Expand Down Expand Up @@ -1822,7 +1822,7 @@ def is_complex_dtype(arr_or_dtype):
return _is_dtype_type(arr_or_dtype, classes(np.complexfloating))


def _is_dtype(arr_or_dtype, condition):
def _is_dtype(arr_or_dtype, condition) -> bool:
"""
Return a boolean if the condition is satisfied for the arr_or_dtype.

Expand Down Expand Up @@ -1883,7 +1883,7 @@ def _get_dtype(arr_or_dtype):
return pandas_dtype(arr_or_dtype)


def _is_dtype_type(arr_or_dtype, condition):
def _is_dtype_type(arr_or_dtype, condition) -> bool:
"""
Return a boolean if the condition is satisfied for the arr_or_dtype.

Expand Down Expand Up @@ -1992,7 +1992,7 @@ def infer_dtype_from_object(dtype):
return infer_dtype_from_object(np.dtype(dtype))


def _validate_date_like_dtype(dtype):
def _validate_date_like_dtype(dtype) -> None:
"""
Check whether the dtype is a date-like dtype. Raises an error if invalid.

Expand Down