Skip to content
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

#25942 Added ArrayLike and Dtype to pandas._typing #25943

Merged
merged 5 commits into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions pandas/_typing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from pathlib import Path
from typing import IO, AnyStr, Union

import numpy as np

from pandas.core.dtypes.dtypes import ExtensionDtype
from pandas.core.dtypes.generic import ABCExtensionArray

ArrayLike = Union[ABCExtensionArray, np.ndarray]
Dtype = Union[str, np.dtype, ExtensionDtype]
FilePathOrBuffer = Union[str, Path, IO[AnyStr]]
3 changes: 2 additions & 1 deletion pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ABCExtensionArray, ABCIndexClass, ABCSeries)
from pandas.core.dtypes.missing import isna

from pandas._typing import ArrayLike
from pandas.core import ops

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

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

Expand Down
5 changes: 3 additions & 2 deletions pandas/core/arrays/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numbers
import operator
import re
from typing import Any, Callable, Type, Union
from typing import Any, Callable
import warnings

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

from pandas._typing import Dtype
from pandas.core.accessor import PandasDelegate, delegate_names
import pandas.core.algorithms as algos
from pandas.core.arrays import ExtensionArray, ExtensionOpsMixin
Expand Down Expand Up @@ -79,7 +80,7 @@ class SparseDtype(ExtensionDtype):

def __init__(
self,
dtype: Union[str, np.dtype, ExtensionDtype, Type] = np.float64,
dtype: Dtype = np.float64,
fill_value: Any = None
) -> None:
from pandas.core.dtypes.missing import na_value_for_dtype
Expand Down