Skip to content

Commit 63a6a87

Browse files
committed
interval array
1 parent f319951 commit 63a6a87

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

pandas-stubs/core/construction.pyi

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ from pandas._typing import (
4949
StrDtypeArg,
5050
TimedeltaDtypeArg,
5151
TimestampDtypeArg,
52+
UIntDtypeArg,
5253
np_ndarray,
5354
np_ndarray_anyint,
5455
np_ndarray_bool,
@@ -85,7 +86,7 @@ def array( # type: ignore[overload-overlap]
8586
@overload
8687
def array( # type: ignore[overload-overlap]
8788
data: Sequence[int | np.integer | NAType | None] | np_ndarray_anyint | IntegerArray,
88-
dtype: IntDtypeArg | None = None,
89+
dtype: IntDtypeArg | UIntDtypeArg | None = None,
8990
copy: bool = True,
9091
) -> IntegerArray: ...
9192
@overload
@@ -137,12 +138,8 @@ def array( # type: ignore[overload-overlap]
137138
) -> PeriodArray: ...
138139
@overload
139140
def array( # type: ignore[overload-overlap]
140-
data: (
141-
Sequence[IntervalT | NAType | None]
142-
| IntervalIndex
143-
| Series[Interval]
144-
| IntervalArray
145-
),
141+
# float("nan") also works, but I don't know how to put it in
142+
data: Sequence[IntervalT | None] | IntervalArray | IntervalIndex | Series[Interval],
146143
dtype: IntervalDtype | None = None,
147144
copy: bool = True,
148145
) -> IntervalArray: ...
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pandas as pd
2+
from pandas.core.arrays.interval import IntervalArray
3+
from typing_extensions import assert_type
4+
5+
from tests import check
6+
7+
8+
def test_constructor() -> None:
9+
itv = pd.Interval(0, 1)
10+
check(
11+
assert_type( # type: ignore[assert-type] # I do not understand
12+
pd.array([itv]), IntervalArray
13+
),
14+
IntervalArray,
15+
)
16+
check(
17+
assert_type( # type: ignore[assert-type] # I do not understand
18+
pd.array([itv, None]), IntervalArray
19+
),
20+
IntervalArray,
21+
)
22+
23+
check(
24+
assert_type( # type: ignore[assert-type] # I do not understand
25+
pd.array(pd.array([itv])), IntervalArray
26+
),
27+
IntervalArray,
28+
)
29+
30+
check(assert_type(pd.array(pd.Index([itv])), IntervalArray), IntervalArray)
31+
32+
check(assert_type(pd.array(pd.Series([itv])), IntervalArray), IntervalArray)

0 commit comments

Comments
 (0)