Skip to content

Commit 9766fa3

Browse files
committed
more tests
1 parent 5370fc4 commit 9766fa3

File tree

5 files changed

+66
-5
lines changed

5 files changed

+66
-5
lines changed

pandas-stubs/core/construction.pyi

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from collections.abc import Sequence
2+
from datetime import (
3+
datetime,
4+
timedelta,
5+
)
26
from typing import (
37
Any,
4-
Never,
58
overload,
69
)
710

@@ -27,6 +30,7 @@ from pandas.core.indexes.period import PeriodIndex
2730
from pandas.core.indexes.range import RangeIndex
2831
from pandas.core.indexes.timedeltas import TimedeltaIndex
2932
from pandas.core.series import Series
33+
from typing_extensions import Never
3034

3135
from pandas._libs.interval import Interval
3236
from pandas._libs.missing import NAType
@@ -95,7 +99,8 @@ def array( # type: ignore[overload-overlap]
9599
@overload
96100
def array( # type: ignore[overload-overlap]
97101
data: (
98-
Sequence[Timestamp | np.datetime64 | NaTType | None]
102+
Sequence[datetime | NaTType | None]
103+
| Sequence[np.datetime64 | NaTType | None]
99104
| np_ndarray_dt
100105
| DatetimeArray
101106
| DatetimeIndex
@@ -107,7 +112,7 @@ def array( # type: ignore[overload-overlap]
107112
@overload
108113
def array( # type: ignore[overload-overlap]
109114
data: (
110-
Sequence[Timedelta | np.timedelta64 | NaTType | None]
115+
Sequence[timedelta | np.timedelta64 | NaTType | None]
111116
| np_ndarray_td
112117
| TimedeltaArray
113118
| TimedeltaIndex

tests/arrays/test_boolean_arrays.py renamed to tests/arrays/test_boolean_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from tests import check
77

88

9-
def test_construction() -> None:
9+
def test_constructor() -> None:
1010
check(assert_type(pd.array([True]), BooleanArray), BooleanArray)
1111
check(assert_type(pd.array([True, np.bool(True)]), BooleanArray), BooleanArray)
1212
check(assert_type(pd.array([True, None]), BooleanArray), BooleanArray)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from datetime import datetime
2+
3+
import numpy as np
4+
import pandas as pd
5+
from pandas.core.arrays.datetimes import DatetimeArray
6+
from typing_extensions import assert_type
7+
8+
from tests import check
9+
10+
11+
def test_constructor() -> None:
12+
dt = datetime(2025, 11, 10)
13+
check(assert_type(pd.array([dt]), DatetimeArray), DatetimeArray)
14+
check(assert_type(pd.array([dt, pd.Timestamp(dt)]), DatetimeArray), DatetimeArray)
15+
check(assert_type(pd.array([dt, None]), DatetimeArray), DatetimeArray)
16+
check(assert_type(pd.array([dt, pd.NaT, None]), DatetimeArray), DatetimeArray)
17+
18+
np_dt = np.datetime64(dt)
19+
check(assert_type(pd.array([np_dt]), DatetimeArray), DatetimeArray)
20+
check(assert_type(pd.array([np_dt, None]), DatetimeArray), DatetimeArray)
21+
check(assert_type(pd.array([np_dt, pd.NaT]), DatetimeArray), DatetimeArray)
22+
23+
check(
24+
assert_type( # type: ignore[assert-type] # I do not understand
25+
pd.array(np.array([dt], np.datetime64)), DatetimeArray
26+
),
27+
DatetimeArray,
28+
)
29+
30+
check(assert_type(pd.array(pd.array([dt])), DatetimeArray), DatetimeArray)
31+
32+
check(assert_type(pd.array(pd.Index([dt])), DatetimeArray), DatetimeArray)
33+
34+
check(assert_type(pd.array(pd.Series([dt])), DatetimeArray), DatetimeArray)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import numpy as np
2+
import pandas as pd
3+
from pandas.core.arrays.floating import FloatingArray
4+
from typing_extensions import assert_type
5+
6+
from tests import check
7+
8+
9+
def test_constructor() -> None:
10+
check(assert_type(pd.array([1.0]), FloatingArray), FloatingArray)
11+
check(assert_type(pd.array([1.0, np.float64(1)]), FloatingArray), FloatingArray)
12+
check(assert_type(pd.array([1.0, None]), FloatingArray), FloatingArray)
13+
check(assert_type(pd.array([1.0, pd.NA, None]), FloatingArray), FloatingArray)
14+
15+
check(
16+
assert_type( # type: ignore[assert-type] # I do not understand
17+
pd.array(np.array([1.0], np.float64)), FloatingArray
18+
),
19+
FloatingArray,
20+
)
21+
22+
check(assert_type(pd.array(pd.array([1.0])), FloatingArray), FloatingArray)

tests/arrays/test_integer_arrays.py renamed to tests/arrays/test_integer_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from tests import check
77

88

9-
def test_construction() -> None:
9+
def test_constructor() -> None:
1010
check(assert_type(pd.array([1]), IntegerArray), IntegerArray)
1111
check(assert_type(pd.array([1, np.int64(1)]), IntegerArray), IntegerArray)
1212
check(assert_type(pd.array([1, None]), IntegerArray), IntegerArray)

0 commit comments

Comments
 (0)