11from collections .abc import Sequence
2+ from datetime import (
3+ datetime ,
4+ timedelta ,
5+ )
6+ import sys
27from typing import (
38 Any ,
49 TypeAlias ,
510 overload ,
611)
712
813import numpy as np
14+ from pandas .core .arrays .base import ExtensionArray
915from pandas .core .arrays .boolean import BooleanArray
16+ from pandas .core .arrays .categorical import Categorical
17+ from pandas .core .arrays .datetimes import DatetimeArray
1018from pandas .core .arrays .floating import FloatingArray
1119from pandas .core .arrays .integer import IntegerArray
20+ from pandas .core .arrays .interval import IntervalArray
1221from pandas .core .arrays .numpy_ import NumpyExtensionArray
22+ from pandas .core .arrays .period import PeriodArray
23+ from pandas .core .arrays .sparse .array import SparseArray
1324from pandas .core .arrays .string_ import (
1425 BaseStringArray ,
1526 StringArray ,
1627 StringDtype ,
1728)
1829from pandas .core .arrays .string_arrow import ArrowStringArray
30+ from pandas .core .arrays .timedeltas import TimedeltaArray
31+ from pandas .core .indexes .base import Index
32+ from pandas .core .indexes .category import CategoricalIndex
33+ from pandas .core .indexes .datetimes import DatetimeIndex
34+ from pandas .core .indexes .interval import IntervalIndex
35+ from pandas .core .indexes .period import PeriodIndex
1936from pandas .core .indexes .range import RangeIndex
37+ from pandas .core .indexes .timedeltas import TimedeltaIndex
38+ from pandas .core .series import Series
2039from typing_extensions import Never
2140
41+ from pandas ._libs .interval import Interval
2242from pandas ._libs .missing import NAType
43+ from pandas ._libs .sparse import SparseIndex
2344from pandas ._libs .tslibs .nattype import NaTType
45+ from pandas ._libs .tslibs .period import Period
46+ from pandas ._libs .tslibs .timedeltas import Timedelta
47+ from pandas ._libs .tslibs .timestamps import Timestamp
2448from pandas ._typing import (
2549 BuiltinDtypeArg ,
50+ CategoryDtypeArg ,
51+ IntervalT ,
2652 Just ,
2753 NumpyNotTimeDtypeArg ,
54+ NumpyTimedeltaDtypeArg ,
55+ NumpyTimestampDtypeArg ,
2856 PandasBaseStrDtypeArg ,
2957 PandasBooleanDtypeArg ,
3058 PandasFloatDtypeArg ,
3159 PandasIntDtypeArg ,
3260 PandasStrDtypeArg ,
61+ PandasTimestampDtypeArg ,
3362 PandasUIntDtypeArg ,
3463 PyArrowStrDtypeArg ,
3564 SequenceNotStr ,
3665 np_ndarray ,
3766 np_ndarray_anyint ,
3867 np_ndarray_bool ,
68+ np_ndarray_dt ,
3969 np_ndarray_float ,
4070 np_ndarray_str ,
71+ np_ndarray_td ,
72+ )
73+
74+ from pandas .core .dtypes .base import ExtensionDtype
75+ from pandas .core .dtypes .dtypes import (
76+ IntervalDtype ,
77+ PeriodDtype ,
4178)
4279
4380_NaNNullableStrData : TypeAlias = (
@@ -62,6 +99,51 @@ def array( # type: ignore[overload-overlap] # pyright: ignore[reportOverlapping
6299 dtype : BuiltinDtypeArg | NumpyNotTimeDtypeArg | None = None ,
63100 copy : bool = True ,
64101) -> NumpyExtensionArray : ...
102+ @overload
103+ def array ( # type: ignore[overload-overlap]
104+ data : SequenceNotStr [Any ] | np_ndarray | ExtensionArray | Index | Series ,
105+ dtype : CategoryDtypeArg ,
106+ copy : bool = True ,
107+ ) -> Categorical : ...
108+ @overload
109+ def array (
110+ # TODO: Categorical Series pandas-dev/pandas-stubs#1415
111+ data : Categorical | CategoricalIndex ,
112+ dtype : CategoryDtypeArg | None = None ,
113+ copy : bool = True ,
114+ ) -> Categorical : ...
115+ @overload
116+ def array ( # type: ignore[overload-overlap]
117+ data : (
118+ Sequence [Period | NaTType | None ] | PeriodArray | PeriodIndex | Series [Period ]
119+ ),
120+ dtype : PeriodDtype | None = None ,
121+ copy : bool = True ,
122+ ) -> PeriodArray : ...
123+ @overload
124+ def array ( # type: ignore[overload-overlap]
125+ # float("nan") also works, but I don't know how to put it in
126+ data : Sequence [IntervalT | None ] | IntervalArray | IntervalIndex | Series [Interval ],
127+ dtype : IntervalDtype | None = None ,
128+ copy : bool = True ,
129+ ) -> IntervalArray : ...
130+
131+ if sys .version_info >= (3 , 11 ):
132+ @overload
133+ def array (
134+ data : SparseArray | SparseIndex ,
135+ dtype : str | np .dtype | ExtensionDtype | None = None ,
136+ copy : bool = True ,
137+ ) -> SparseArray : ...
138+
139+ else :
140+ @overload
141+ def array (
142+ data : SparseArray | SparseIndex ,
143+ dtype : str | np .dtype [Any ] | ExtensionDtype | None = None ,
144+ copy : bool = True ,
145+ ) -> SparseArray : ...
146+
65147@overload
66148def array (
67149 data : Sequence [bool | np .bool | Just [float ] | NAType | None ],
@@ -99,14 +181,39 @@ def array(
99181 copy : bool = True ,
100182) -> IntegerArray : ...
101183@overload
102- def array (
184+ def array ( # type: ignore[overload-overlap]
103185 data : (
104186 Sequence [float | np .floating | NAType | None ] | np_ndarray_float | FloatingArray
105187 ),
106188 dtype : PandasFloatDtypeArg | None = None ,
107189 copy : bool = True ,
108190) -> FloatingArray : ...
109191@overload
192+ def array ( # type: ignore[overload-overlap]
193+ data : ( # TODO: merge the two Sequence's after 3.0 pandas-dev/pandas#57064
194+ Sequence [datetime | NaTType | None ]
195+ | Sequence [np .datetime64 | NaTType | None ]
196+ | np_ndarray_dt
197+ | DatetimeArray
198+ | DatetimeIndex
199+ | Series [Timestamp ]
200+ ),
201+ dtype : PandasTimestampDtypeArg | NumpyTimestampDtypeArg | None = None ,
202+ copy : bool = True ,
203+ ) -> DatetimeArray : ...
204+ @overload
205+ def array (
206+ data : (
207+ Sequence [timedelta | np .timedelta64 | NaTType | None ]
208+ | np_ndarray_td
209+ | TimedeltaArray
210+ | TimedeltaIndex
211+ | Series [Timedelta ]
212+ ),
213+ dtype : NumpyTimedeltaDtypeArg | None = None ,
214+ copy : bool = True ,
215+ ) -> TimedeltaArray : ...
216+ @overload
110217def array ( # type: ignore[overload-overlap]
111218 data : _NaNNullableStrData , dtype : StringDtype [Never ], copy : bool = True
112219) -> BaseStringArray : ...
0 commit comments