Skip to content

Commit 16d5540

Browse files
committed
interval array
1 parent 9245ec7 commit 16d5540

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,
@@ -91,7 +92,7 @@ def array( # type: ignore[overload-overlap]
9192
@overload
9293
def array( # type: ignore[overload-overlap]
9394
data: Sequence[int | np.integer | NAType | None] | np_ndarray_anyint | IntegerArray,
94-
dtype: IntDtypeArg | None = None,
95+
dtype: IntDtypeArg | UIntDtypeArg | None = None,
9596
copy: bool = True,
9697
) -> IntegerArray: ...
9798
@overload
@@ -143,12 +144,8 @@ def array( # type: ignore[overload-overlap]
143144
) -> PeriodArray: ...
144145
@overload
145146
def array( # type: ignore[overload-overlap]
146-
data: (
147-
Sequence[IntervalT | NAType | None]
148-
| IntervalIndex
149-
| Series[Interval]
150-
| IntervalArray
151-
),
147+
# float("nan") also works, but I don't know how to put it in
148+
data: Sequence[IntervalT | None] | IntervalArray | IntervalIndex | Series[Interval],
152149
dtype: IntervalDtype | None = None,
153150
copy: bool = True,
154151
) -> 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)