Skip to content

Commit e3659c8

Browse files
committed
numpy_extension_array
1 parent d0c0017 commit e3659c8

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

pandas-stubs/core/construction.pyi

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,12 @@ def array(
157157
) -> Categorical: ...
158158
@overload
159159
def array(
160-
data: SequenceNotStr[object] | np.typing.NDArray[np.object_] | RangeIndex,
160+
data: (
161+
SequenceNotStr[object]
162+
| np.typing.NDArray[np.object_]
163+
| NumpyExtensionArray
164+
| RangeIndex
165+
),
161166
dtype: str | np.dtype | ExtensionDtype | None = None,
162167
copy: bool = True,
163168
) -> NumpyExtensionArray: ...
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import numpy as np
2+
import pandas as pd
3+
from pandas.core.arrays.numpy_ import NumpyExtensionArray
4+
from typing_extensions import assert_type
5+
6+
from tests import check
7+
8+
9+
def test_constructor() -> None:
10+
check(
11+
assert_type(pd.array([pd.NA, None]), NumpyExtensionArray), NumpyExtensionArray
12+
)
13+
14+
check(
15+
assert_type( # type: ignore[assert-type] # I do not understand
16+
pd.array([1, "🐼"]), NumpyExtensionArray
17+
),
18+
NumpyExtensionArray,
19+
)
20+
check(
21+
assert_type( # type: ignore[assert-type] # I do not understand, mypy must have problem with two Generic Variables somehow
22+
pd.array(np.array([1, "🐼"], np.object_)), NumpyExtensionArray
23+
),
24+
NumpyExtensionArray,
25+
)
26+
check(
27+
assert_type(pd.array(pd.array([pd.NA, None])), NumpyExtensionArray),
28+
NumpyExtensionArray,
29+
)
30+
check(
31+
assert_type(pd.array(pd.RangeIndex(0, 1)), NumpyExtensionArray),
32+
NumpyExtensionArray,
33+
)

0 commit comments

Comments
 (0)