Skip to content

Commit 0761dab

Browse files
committed
pandas-dev#25942 Added ArrayLike and Dtype to pandas._typing
1 parent de3a85c commit 0761dab

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

pandas/_typing.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
from pathlib import Path
2-
from typing import IO, AnyStr, Union
2+
from typing import IO, AnyStr, Type, Union
33

4+
import numpy as np
5+
6+
from pandas.core.dtypes.dtypes import ExtensionDtype
7+
from pandas.core.dtypes.generic import ABCExtensionArray
8+
9+
ArrayLike = Union[ABCExtensionArray, np.ndarray]
10+
Dtype = Union[str, np.dtype, ExtensionDtype, Type]
411
FilePathOrBuffer = Union[str, Path, IO[AnyStr]]

pandas/core/arrays/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
ABCExtensionArray, ABCIndexClass, ABCSeries)
2222
from pandas.core.dtypes.missing import isna
2323

24+
from pandas._typing import ArrayLike
2425
from pandas.core import ops
2526

2627
_not_implemented_message = "{} does not implement {}."
@@ -338,7 +339,7 @@ def astype(self, dtype, copy=True):
338339
"""
339340
return np.array(self, dtype=dtype, copy=copy)
340341

341-
def isna(self) -> Union[ABCExtensionArray, np.ndarray]:
342+
def isna(self) -> ArrayLike:
342343
"""
343344
A 1-D array indicating if each value is missing.
344345

pandas/core/arrays/sparse.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import numbers
55
import operator
66
import re
7-
from typing import Any, Callable, Type, Union
7+
from typing import Any, Callable
88
import warnings
99

1010
import numpy as np
@@ -30,6 +30,7 @@
3030
ABCIndexClass, ABCSeries, ABCSparseArray, ABCSparseSeries)
3131
from pandas.core.dtypes.missing import isna, na_value_for_dtype, notna
3232

33+
from pandas._typing import Dtype
3334
from pandas.core.accessor import PandasDelegate, delegate_names
3435
import pandas.core.algorithms as algos
3536
from pandas.core.arrays import ExtensionArray, ExtensionOpsMixin
@@ -79,7 +80,7 @@ class SparseDtype(ExtensionDtype):
7980

8081
def __init__(
8182
self,
82-
dtype: Union[str, np.dtype, ExtensionDtype, Type] = np.float64,
83+
dtype: Dtype = np.float64,
8384
fill_value: Any = None
8485
) -> None:
8586
from pandas.core.dtypes.missing import na_value_for_dtype

0 commit comments

Comments
 (0)