From 1a52157e96367bff15c4822593f8e62154a0dddf Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 24 Jul 2019 15:34:05 +0100 Subject: [PATCH] TYPING: some type hints for core.dtypes.common --- pandas/core/dtypes/common.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index f2571573bd1bc..5c1fe630ecaf5 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -1,5 +1,5 @@ """ common type operations """ -from typing import Any, Union +from typing import Any, Callable, Union import warnings import numpy as np @@ -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. @@ -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 @@ -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. @@ -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. @@ -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" @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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.