|
1 | 1 | """ common type operations """
|
2 |
| -from typing import Any, Union |
| 2 | +from typing import Any, Callable, Union |
3 | 3 | import warnings
|
4 | 4 |
|
5 | 5 | import numpy as np
|
@@ -141,7 +141,7 @@ def ensure_categorical(arr):
|
141 | 141 | return arr
|
142 | 142 |
|
143 | 143 |
|
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: |
145 | 145 | """
|
146 | 146 | Ensure that an dtype array of some integer dtype
|
147 | 147 | has an int64 dtype if possible.
|
@@ -207,12 +207,12 @@ def ensure_python_int(value: Union[int, np.integer]) -> int:
|
207 | 207 | return new_value
|
208 | 208 |
|
209 | 209 |
|
210 |
| -def classes(*klasses): |
| 210 | +def classes(*klasses) -> Callable: |
211 | 211 | """ evaluate if the tipo is a subclass of the klasses """
|
212 | 212 | return lambda tipo: issubclass(tipo, klasses)
|
213 | 213 |
|
214 | 214 |
|
215 |
| -def classes_and_not_datetimelike(*klasses): |
| 215 | +def classes_and_not_datetimelike(*klasses) -> Callable: |
216 | 216 | """
|
217 | 217 | evaluate if the tipo is a subclass of the klasses
|
218 | 218 | and not a datetimelike
|
@@ -355,7 +355,7 @@ def is_scipy_sparse(arr):
|
355 | 355 | return _is_scipy_sparse(arr)
|
356 | 356 |
|
357 | 357 |
|
358 |
| -def is_categorical(arr): |
| 358 | +def is_categorical(arr) -> bool: |
359 | 359 | """
|
360 | 360 | Check whether an array-like is a Categorical instance.
|
361 | 361 |
|
@@ -676,7 +676,7 @@ def is_interval_dtype(arr_or_dtype):
|
676 | 676 | return IntervalDtype.is_dtype(arr_or_dtype)
|
677 | 677 |
|
678 | 678 |
|
679 |
| -def is_categorical_dtype(arr_or_dtype): |
| 679 | +def is_categorical_dtype(arr_or_dtype) -> bool: |
680 | 680 | """
|
681 | 681 | Check whether an array-like or dtype is of the Categorical dtype.
|
682 | 682 |
|
@@ -899,7 +899,7 @@ def is_dtype_equal(source, target):
|
899 | 899 | return False
|
900 | 900 |
|
901 | 901 |
|
902 |
| -def is_any_int_dtype(arr_or_dtype): |
| 902 | +def is_any_int_dtype(arr_or_dtype) -> bool: |
903 | 903 | """Check whether the provided array or dtype is of an integer dtype.
|
904 | 904 |
|
905 | 905 | In this function, timedelta64 instances are also considered "any-integer"
|
@@ -1161,7 +1161,7 @@ def is_int64_dtype(arr_or_dtype):
|
1161 | 1161 | return _is_dtype_type(arr_or_dtype, classes(np.int64))
|
1162 | 1162 |
|
1163 | 1163 |
|
1164 |
| -def is_datetime64_any_dtype(arr_or_dtype): |
| 1164 | +def is_datetime64_any_dtype(arr_or_dtype) -> bool: |
1165 | 1165 | """
|
1166 | 1166 | Check whether the provided array or dtype is of the datetime64 dtype.
|
1167 | 1167 |
|
@@ -1321,7 +1321,7 @@ def is_datetime_or_timedelta_dtype(arr_or_dtype):
|
1321 | 1321 | return _is_dtype_type(arr_or_dtype, classes(np.datetime64, np.timedelta64))
|
1322 | 1322 |
|
1323 | 1323 |
|
1324 |
| -def _is_unorderable_exception(e): |
| 1324 | +def _is_unorderable_exception(e: TypeError) -> bool: |
1325 | 1325 | """
|
1326 | 1326 | Check if the exception raised is an unorderable exception.
|
1327 | 1327 |
|
@@ -1617,7 +1617,7 @@ def is_float_dtype(arr_or_dtype):
|
1617 | 1617 | return _is_dtype_type(arr_or_dtype, classes(np.floating))
|
1618 | 1618 |
|
1619 | 1619 |
|
1620 |
| -def is_bool_dtype(arr_or_dtype): |
| 1620 | +def is_bool_dtype(arr_or_dtype) -> bool: |
1621 | 1621 | """
|
1622 | 1622 | Check whether the provided array or dtype is of a boolean dtype.
|
1623 | 1623 |
|
@@ -1790,7 +1790,7 @@ def is_extension_array_dtype(arr_or_dtype):
|
1790 | 1790 | return isinstance(dtype, ExtensionDtype) or registry.find(dtype) is not None
|
1791 | 1791 |
|
1792 | 1792 |
|
1793 |
| -def is_complex_dtype(arr_or_dtype): |
| 1793 | +def is_complex_dtype(arr_or_dtype) -> bool: |
1794 | 1794 | """
|
1795 | 1795 | Check whether the provided array or dtype is of a complex dtype.
|
1796 | 1796 |
|
@@ -1823,7 +1823,7 @@ def is_complex_dtype(arr_or_dtype):
|
1823 | 1823 | return _is_dtype_type(arr_or_dtype, classes(np.complexfloating))
|
1824 | 1824 |
|
1825 | 1825 |
|
1826 |
| -def _is_dtype(arr_or_dtype, condition): |
| 1826 | +def _is_dtype(arr_or_dtype, condition) -> bool: |
1827 | 1827 | """
|
1828 | 1828 | Return a boolean if the condition is satisfied for the arr_or_dtype.
|
1829 | 1829 |
|
@@ -1884,7 +1884,7 @@ def _get_dtype(arr_or_dtype):
|
1884 | 1884 | return pandas_dtype(arr_or_dtype)
|
1885 | 1885 |
|
1886 | 1886 |
|
1887 |
| -def _is_dtype_type(arr_or_dtype, condition): |
| 1887 | +def _is_dtype_type(arr_or_dtype, condition) -> bool: |
1888 | 1888 | """
|
1889 | 1889 | Return a boolean if the condition is satisfied for the arr_or_dtype.
|
1890 | 1890 |
|
@@ -1993,7 +1993,7 @@ def infer_dtype_from_object(dtype):
|
1993 | 1993 | return infer_dtype_from_object(np.dtype(dtype))
|
1994 | 1994 |
|
1995 | 1995 |
|
1996 |
| -def _validate_date_like_dtype(dtype): |
| 1996 | +def _validate_date_like_dtype(dtype) -> None: |
1997 | 1997 | """
|
1998 | 1998 | Check whether the dtype is a date-like dtype. Raises an error if invalid.
|
1999 | 1999 |
|
|
0 commit comments