Skip to content

Commit c1fd9ab

Browse files
simonjayhawkinsjreback
authored andcommitted
TYPING: some type hints for core.dtypes.common (#27564)
1 parent 22a0025 commit c1fd9ab

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

pandas/core/dtypes/common.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
""" common type operations """
2-
from typing import Any, Union
2+
from typing import Any, Callable, Union
33
import warnings
44

55
import numpy as np
@@ -141,7 +141,7 @@ def ensure_categorical(arr):
141141
return arr
142142

143143

144-
def ensure_int_or_float(arr: ArrayLike, copy=False) -> np.array:
144+
def ensure_int_or_float(arr: ArrayLike, copy: bool = False) -> np.array:
145145
"""
146146
Ensure that an dtype array of some integer dtype
147147
has an int64 dtype if possible.
@@ -207,12 +207,12 @@ def ensure_python_int(value: Union[int, np.integer]) -> int:
207207
return new_value
208208

209209

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

214214

215-
def classes_and_not_datetimelike(*klasses):
215+
def classes_and_not_datetimelike(*klasses) -> Callable:
216216
"""
217217
evaluate if the tipo is a subclass of the klasses
218218
and not a datetimelike
@@ -355,7 +355,7 @@ def is_scipy_sparse(arr):
355355
return _is_scipy_sparse(arr)
356356

357357

358-
def is_categorical(arr):
358+
def is_categorical(arr) -> bool:
359359
"""
360360
Check whether an array-like is a Categorical instance.
361361
@@ -676,7 +676,7 @@ def is_interval_dtype(arr_or_dtype):
676676
return IntervalDtype.is_dtype(arr_or_dtype)
677677

678678

679-
def is_categorical_dtype(arr_or_dtype):
679+
def is_categorical_dtype(arr_or_dtype) -> bool:
680680
"""
681681
Check whether an array-like or dtype is of the Categorical dtype.
682682
@@ -899,7 +899,7 @@ def is_dtype_equal(source, target):
899899
return False
900900

901901

902-
def is_any_int_dtype(arr_or_dtype):
902+
def is_any_int_dtype(arr_or_dtype) -> bool:
903903
"""Check whether the provided array or dtype is of an integer dtype.
904904
905905
In this function, timedelta64 instances are also considered "any-integer"
@@ -1161,7 +1161,7 @@ def is_int64_dtype(arr_or_dtype):
11611161
return _is_dtype_type(arr_or_dtype, classes(np.int64))
11621162

11631163

1164-
def is_datetime64_any_dtype(arr_or_dtype):
1164+
def is_datetime64_any_dtype(arr_or_dtype) -> bool:
11651165
"""
11661166
Check whether the provided array or dtype is of the datetime64 dtype.
11671167
@@ -1321,7 +1321,7 @@ def is_datetime_or_timedelta_dtype(arr_or_dtype):
13211321
return _is_dtype_type(arr_or_dtype, classes(np.datetime64, np.timedelta64))
13221322

13231323

1324-
def _is_unorderable_exception(e):
1324+
def _is_unorderable_exception(e: TypeError) -> bool:
13251325
"""
13261326
Check if the exception raised is an unorderable exception.
13271327
@@ -1617,7 +1617,7 @@ def is_float_dtype(arr_or_dtype):
16171617
return _is_dtype_type(arr_or_dtype, classes(np.floating))
16181618

16191619

1620-
def is_bool_dtype(arr_or_dtype):
1620+
def is_bool_dtype(arr_or_dtype) -> bool:
16211621
"""
16221622
Check whether the provided array or dtype is of a boolean dtype.
16231623
@@ -1790,7 +1790,7 @@ def is_extension_array_dtype(arr_or_dtype):
17901790
return isinstance(dtype, ExtensionDtype) or registry.find(dtype) is not None
17911791

17921792

1793-
def is_complex_dtype(arr_or_dtype):
1793+
def is_complex_dtype(arr_or_dtype) -> bool:
17941794
"""
17951795
Check whether the provided array or dtype is of a complex dtype.
17961796
@@ -1823,7 +1823,7 @@ def is_complex_dtype(arr_or_dtype):
18231823
return _is_dtype_type(arr_or_dtype, classes(np.complexfloating))
18241824

18251825

1826-
def _is_dtype(arr_or_dtype, condition):
1826+
def _is_dtype(arr_or_dtype, condition) -> bool:
18271827
"""
18281828
Return a boolean if the condition is satisfied for the arr_or_dtype.
18291829
@@ -1884,7 +1884,7 @@ def _get_dtype(arr_or_dtype):
18841884
return pandas_dtype(arr_or_dtype)
18851885

18861886

1887-
def _is_dtype_type(arr_or_dtype, condition):
1887+
def _is_dtype_type(arr_or_dtype, condition) -> bool:
18881888
"""
18891889
Return a boolean if the condition is satisfied for the arr_or_dtype.
18901890
@@ -1993,7 +1993,7 @@ def infer_dtype_from_object(dtype):
19931993
return infer_dtype_from_object(np.dtype(dtype))
19941994

19951995

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

0 commit comments

Comments
 (0)