Skip to content

Commit dd44072

Browse files
committed
tests
1 parent edd3215 commit dd44072

File tree

3 files changed

+39
-31
lines changed

3 files changed

+39
-31
lines changed

pandas-stubs/core/construction.pyi

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections.abc import Sequence
22
from typing import (
33
Any,
4+
Never,
45
overload,
56
)
67

@@ -23,6 +24,11 @@ from pandas._libs.tslibs.nattype import NaTType
2324
from pandas._libs.tslibs.timedeltas import Timedelta
2425
from pandas._libs.tslibs.timestamps import Timestamp
2526
from pandas._typing import (
27+
BooleanDtypeArg,
28+
FloatDtypeArg,
29+
IntDtypeArg,
30+
TimedeltaDtypeArg,
31+
TimestampDtypeArg,
2632
np_ndarray,
2733
np_ndarray_anyint,
2834
np_ndarray_bool,
@@ -35,51 +41,34 @@ from pandas.core.dtypes.dtypes import ExtensionDtype
3541

3642
@overload
3743
def array( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
38-
data: Sequence[bool | np.bool | NAType | None] | np_ndarray_bool | BooleanArray,
39-
dtype: PandasBooleanDtypeArg | None = None,
44+
data: Sequence[Never] | Index[Never] | Series[Never],
45+
dtype: str | np.dtype | ExtensionDtype | None = None,
4046
copy: bool = True,
41-
) -> BooleanArray: ...
47+
) -> ExtensionArray: ...
4248
@overload
43-
def array( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
49+
def array( # type: ignore[overload-overlap]
4450
data: Sequence[NAType | None],
4551
dtype: str | np.dtype | ExtensionDtype | None = None,
4652
copy: bool = True,
4753
) -> NumpyExtensionArray: ...
4854
@overload
49-
def array( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
50-
data: (
51-
Sequence[bool | np.bool | NAType | None]
52-
| np_ndarray_bool
53-
| BooleanArray
54-
| Index[bool]
55-
| Series[int]
56-
),
57-
dtype: str | np.dtype | ExtensionDtype | None = None,
55+
def array( # type: ignore[overload-overlap]
56+
data: Sequence[bool | np.bool | NAType | None] | np_ndarray_bool | BooleanArray,
57+
dtype: BooleanDtypeArg | None = None,
5858
copy: bool = True,
5959
) -> BooleanArray: ...
6060
@overload
6161
def array( # type: ignore[overload-overlap]
62-
data: (
63-
Sequence[int | np.integer | NAType | None]
64-
| np_ndarray_anyint
65-
| IntegerArray
66-
| Index[int]
67-
| RangeIndex
68-
| Series[int]
69-
),
70-
dtype: str | np.dtype | ExtensionDtype | None = None,
62+
data: Sequence[int | np.integer | NAType | None] | np_ndarray_anyint | IntegerArray,
63+
dtype: IntDtypeArg | None = None,
7164
copy: bool = True,
7265
) -> IntegerArray: ...
7366
@overload
7467
def array( # type: ignore[overload-overlap]
7568
data: (
76-
Sequence[float | np.floating | NAType | None]
77-
| np_ndarray_float
78-
| FloatingArray
79-
| Index[float]
80-
| Series[float]
69+
Sequence[float | np.floating | NAType | None] | np_ndarray_float | FloatingArray
8170
),
82-
dtype: str | np.dtype | ExtensionDtype | None = None,
71+
dtype: FloatDtypeArg | None = None,
8372
copy: bool = True,
8473
) -> FloatingArray: ...
8574
@overload
@@ -91,7 +80,7 @@ def array( # type: ignore[overload-overlap]
9180
| DatetimeIndex
9281
| Series[Timestamp]
9382
),
94-
dtype: str | np.dtype | ExtensionDtype | None = None,
83+
dtype: TimestampDtypeArg | None = None,
9584
copy: bool = True,
9685
) -> DatetimeArray: ...
9786
@overload
@@ -103,12 +92,18 @@ def array( # type: ignore[overload-overlap]
10392
| TimedeltaIndex
10493
| Series[Timedelta]
10594
),
106-
dtype: str | np.dtype | ExtensionDtype | None = None,
95+
dtype: TimedeltaDtypeArg | None = None,
10796
copy: bool = True,
10897
) -> TimedeltaArray: ...
10998
@overload
11099
def array(
111-
data: Sequence[Any] | np_ndarray | ExtensionArray | Index | Series,
100+
data: Sequence[object] | np.typing.NDArray[np.object_] | RangeIndex,
112101
dtype: str | np.dtype | ExtensionDtype | None = None,
113102
copy: bool = True,
114103
) -> NumpyExtensionArray: ...
104+
@overload
105+
def array(
106+
data: Sequence[Any] | np_ndarray | ExtensionArray | Index[Any] | Series[Any],
107+
dtype: str | np.dtype | ExtensionDtype | None = None,
108+
copy: bool = True,
109+
) -> ExtensionArray: ...

tests/arrays/test_boolean_arrays.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ def test_construction() -> None:
1111
check(assert_type(pd.array([True, np.bool(True)]), BooleanArray), BooleanArray)
1212
check(assert_type(pd.array([True, None]), BooleanArray), BooleanArray)
1313
check(assert_type(pd.array([True, pd.NA]), BooleanArray), BooleanArray)
14+
15+
check(assert_type(pd.array(np.array([1], np.bool_)), BooleanArray), BooleanArray)
16+
17+
check(assert_type(pd.array(pd.array([True])), BooleanArray), BooleanArray)

tests/arrays/test_integer_arrays.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ def test_construction() -> None:
1111
check(assert_type(pd.array([1, np.int64(1)]), IntegerArray), IntegerArray)
1212
check(assert_type(pd.array([1, None]), IntegerArray), IntegerArray)
1313
check(assert_type(pd.array([1, pd.NA, None]), IntegerArray), IntegerArray)
14+
15+
check(
16+
assert_type( # type: ignore[assert-type] # I do not understand
17+
pd.array(np.array([1], np.int64)), IntegerArray
18+
),
19+
IntegerArray,
20+
)
21+
22+
check(assert_type(pd.array(pd.array([1])), IntegerArray), IntegerArray)

0 commit comments

Comments
 (0)