Skip to content

TYP: core.arrays.boolean #31346

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

Merged
merged 2 commits into from
Jan 31, 2020
Merged
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
31 changes: 22 additions & 9 deletions pandas/core/arrays/boolean.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -30,7 +30,7 @@
from .masked import BaseMaskedArray

if TYPE_CHECKING:
from pandas._typing import Scalar
import pyarrow # noqa: F401


@register_extension_dtype
Expand Down Expand Up @@ -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.

Expand All @@ -73,15 +73,22 @@ def na_value(self) -> "Scalar":
return libmissing.NA

@property
def type(self) -> Type:
def type(self) -> Type[np.bool_]:
return np.bool_

@property
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:
Expand All @@ -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]
Expand All @@ -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.

Expand Down