Skip to content

Commit fcf8cdc

Browse files
committed
numpy_extension_array
1 parent 267f9b7 commit fcf8cdc

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
@@ -151,7 +151,12 @@ def array(
151151
) -> Categorical: ...
152152
@overload
153153
def array(
154-
data: SequenceNotStr[object] | np.typing.NDArray[np.object_] | RangeIndex,
154+
data: (
155+
SequenceNotStr[object]
156+
| np.typing.NDArray[np.object_]
157+
| NumpyExtensionArray
158+
| RangeIndex
159+
),
155160
dtype: str | np.dtype | ExtensionDtype | None = None,
156161
copy: bool = True,
157162
) -> 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)