From ab8239988841ba82810e338ff3d287a82c3e95f6 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 27 Jan 2020 15:28:34 +0000 Subject: [PATCH] TYP: core.arrays.boolean --- pandas/core/arrays/boolean.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/pandas/core/arrays/boolean.py b/pandas/core/arrays/boolean.py index 7b12f3348e7e7..75a0f397e936f 100644 --- a/pandas/core/arrays/boolean.py +++ b/pandas/core/arrays/boolean.py @@ -1,5 +1,5 @@ import numbers -from typing import TYPE_CHECKING, Any, List, Tuple, Type +from typing import TYPE_CHECKING, Any, List, Tuple, Type, Union import warnings import numpy as np @@ -30,7 +30,7 @@ from .masked import BaseMaskedArray if TYPE_CHECKING: - from pandas._typing import Scalar + import pyarrow # noqa: F401 @register_extension_dtype @@ -62,7 +62,7 @@ class BooleanDtype(ExtensionDtype): name = "boolean" @property - def na_value(self) -> "Scalar": + def na_value(self) -> libmissing.NAType: """ BooleanDtype uses :attr:`pandas.NA` as the missing NA value. @@ -73,7 +73,7 @@ def na_value(self) -> "Scalar": return libmissing.NA @property - def type(self) -> Type: + def type(self) -> Type[np.bool_]: return np.bool_ @property @@ -81,7 +81,14 @@ def kind(self) -> str: return "b" @classmethod - def construct_array_type(cls) -> "Type[BooleanArray]": + def construct_array_type(cls) -> Type["BooleanArray"]: + """ + Return the array type associated with this dtype. + + Returns + ------- + type + """ return BooleanArray def __repr__(self) -> str: @@ -91,9 +98,13 @@ def __repr__(self) -> str: def _is_boolean(self) -> bool: return True - def __from_arrow__(self, array): - """Construct BooleanArray from passed pyarrow Array/ChunkedArray""" - import pyarrow + def __from_arrow__( + self, array: Union["pyarrow.Array", "pyarrow.ChunkedArray"] + ) -> "BooleanArray": + """ + Construct BooleanArray from pyarrow Array/ChunkedArray. + """ + import pyarrow # noqa: F811 if isinstance(array, pyarrow.Array): chunks = [array] @@ -110,7 +121,9 @@ def __from_arrow__(self, array): return BooleanArray._concat_same_type(results) -def coerce_to_array(values, mask=None, copy: bool = False): +def coerce_to_array( + values, mask=None, copy: bool = False +) -> Tuple[np.ndarray, np.ndarray]: """ Coerce the input values array to numpy arrays with a mask.