Skip to content

Commit bd6902a

Browse files
committed
test dtype
1 parent f9161d7 commit bd6902a

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

pandas-stubs/core/construction.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ from pandas._libs.tslibs.period import Period
4040
from pandas._libs.tslibs.timedeltas import Timedelta
4141
from pandas._libs.tslibs.timestamps import Timestamp
4242
from pandas._typing import (
43-
BuiltinBooleanDtypeArg,
4443
BuiltinFloatDtypeArg,
4544
BuiltinIntDtypeArg,
4645
BuiltinStrDtypeArg,
@@ -114,7 +113,7 @@ def array(
114113
@overload
115114
def array( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
116115
data: Sequence[bool | np.bool | NAType | None] | np_ndarray_bool | BooleanArray,
117-
dtype: BuiltinBooleanDtypeArg | PandasBooleanDtypeArg | None = None,
116+
dtype: PandasBooleanDtypeArg | None = None,
118117
copy: bool = True,
119118
) -> BooleanArray: ...
120119
@overload

tests/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from __future__ import annotations
22

3-
from collections.abc import Callable
3+
from collections.abc import (
4+
Callable,
5+
Generator,
6+
)
47
from contextlib import (
58
AbstractContextManager,
69
nullcontext,
@@ -35,6 +38,7 @@
3538
if TYPE_CHECKING:
3639
from pandas._typing import (
3740
BooleanDtypeArg as BooleanDtypeArg,
41+
BuiltinBooleanDtypeArg as BuiltinBooleanDtypeArg,
3842
BuiltinDtypeArg as BuiltinDtypeArg,
3943
BytesDtypeArg as BytesDtypeArg,
4044
CategoryDtypeArg as CategoryDtypeArg,
@@ -681,3 +685,14 @@ def skip_platform(
681685
with pytest.raises(TypeError):
682686
raise_type_error()
683687
pytest.skip(f"{system} does not support {dtype}")
688+
689+
690+
def get_dtype(dtype: object) -> Generator[type | str, None, None]:
691+
"""Extract types and string literals from a Union or Literal type."""
692+
if isinstance(dtype, str):
693+
yield dtype
694+
elif isinstance(dtype, type):
695+
yield dtype()
696+
else:
697+
for arg in get_args(dtype):
698+
yield from get_dtype(arg)

tests/arrays/test_boolean_array.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import numpy as np
22
import pandas as pd
33
from pandas.core.arrays.boolean import BooleanArray
4+
import pytest
45
from typing_extensions import assert_type
56

6-
from tests import check
7+
from tests import (
8+
PandasBooleanDtypeArg,
9+
check,
10+
get_dtype,
11+
)
712

813

914
def test_constructor() -> None:
@@ -15,3 +20,10 @@ def test_constructor() -> None:
1520
check(assert_type(pd.array(np.array([1], np.bool_)), BooleanArray), BooleanArray)
1621

1722
check(assert_type(pd.array(pd.array([True])), BooleanArray), BooleanArray)
23+
24+
pd.array([True], dtype=pd.BooleanDtype())
25+
26+
27+
@pytest.mark.parametrize("dtype", get_dtype(PandasBooleanDtypeArg))
28+
def test_constructors_dtype(dtype: PandasBooleanDtypeArg):
29+
check(assert_type(pd.array([True], dtype=dtype), BooleanArray), BooleanArray)

0 commit comments

Comments
 (0)