@@ -21,6 +21,7 @@ from pandas.core.arrays.numpy_ import NumpyExtensionArray
2121from pandas .core .arrays .period import PeriodArray
2222from pandas .core .arrays .sparse .array import SparseArray
2323from pandas .core .arrays .string_ import StringArray
24+ from pandas .core .arrays .string_arrow import ArrowStringArray
2425from pandas .core .arrays .timedeltas import TimedeltaArray
2526from pandas .core .indexes .base import Index
2627from pandas .core .indexes .category import CategoricalIndex
@@ -39,16 +40,22 @@ from pandas._libs.tslibs.period import Period
3940from pandas ._libs .tslibs .timedeltas import Timedelta
4041from pandas ._libs .tslibs .timestamps import Timestamp
4142from pandas ._typing import (
42- BooleanDtypeArg ,
43+ BuiltinBooleanDtypeArg ,
44+ BuiltinFloatDtypeArg ,
45+ BuiltinIntDtypeArg ,
46+ BuiltinStrDtypeArg ,
4347 CategoryDtypeArg ,
44- FloatDtypeArg ,
45- IntDtypeArg ,
4648 IntervalT ,
49+ NumpyDtypeArg ,
50+ PandasBooleanDtypeArg ,
51+ PandasFloatDtypeArg ,
52+ PandasIntDtypeArg ,
53+ PandasStrDtypeArg ,
54+ PandasTimestampDtypeArg ,
55+ PandasUIntDtypeArg ,
56+ PyArrowNotStrDtypeArg ,
57+ PyArrowStrDtypeArg ,
4758 SequenceNotStr ,
48- StrDtypeArg ,
49- TimedeltaDtypeArg ,
50- TimestampDtypeArg ,
51- UIntDtypeArg ,
5259 np_ndarray ,
5360 np_ndarray_anyint ,
5461 np_ndarray_bool ,
@@ -64,36 +71,64 @@ from pandas.core.dtypes.dtypes import (
6471 PeriodDtype ,
6572)
6673
74+ # @overload
75+ # def array(
76+ # data: SequenceNotStr[NAType | None],
77+ # dtype: None = None,
78+ # copy: bool = True
79+ # ) -> NumpyExtensionArray: ...
6780@overload
6881def array ( # type: ignore[overload-overlap]
6982 data : SequenceNotStr [Any ] | np_ndarray | ExtensionArray | Index | Series ,
7083 dtype : CategoryDtypeArg ,
7184 copy : bool = True ,
7285) -> Categorical : ...
7386@overload
87+ def array (
88+ # TODO: Categorical Series pandas-dev/pandas-stubs#1415
89+ data : Categorical | CategoricalIndex ,
90+ dtype : CategoryDtypeArg | None = None ,
91+ copy : bool = True ,
92+ ) -> Categorical : ...
93+ @overload
7494def array ( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
75- data : Sequence [NAType | None ],
76- dtype : str | np .dtype | ExtensionDtype | None = None ,
95+ data : (
96+ Sequence [Period | NaTType | None ] | PeriodArray | PeriodIndex | Series [Period ]
97+ ),
98+ dtype : PeriodDtype | None = None ,
7799 copy : bool = True ,
78- ) -> NumpyExtensionArray : ...
100+ ) -> PeriodArray : ...
79101@overload
80102def array ( # type: ignore[overload-overlap]
103+ # float("nan") also works, but I don't know how to put it in
104+ data : Sequence [IntervalT | None ] | IntervalArray | IntervalIndex | Series [Interval ],
105+ dtype : IntervalDtype | None = None ,
106+ copy : bool = True ,
107+ ) -> IntervalArray : ...
108+ @overload
109+ def array (
110+ data : SparseArray | SparseIndex ,
111+ dtype : str | np .dtype | ExtensionDtype | None = None ,
112+ copy : bool = True ,
113+ ) -> SparseArray : ...
114+ @overload
115+ def array ( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
81116 data : Sequence [bool | np .bool | NAType | None ] | np_ndarray_bool | BooleanArray ,
82- dtype : BooleanDtypeArg | None = None ,
117+ dtype : BuiltinBooleanDtypeArg | PandasBooleanDtypeArg | None = None ,
83118 copy : bool = True ,
84119) -> BooleanArray : ...
85120@overload
86121def array ( # type: ignore[overload-overlap]
87122 data : Sequence [int | np .integer | NAType | None ] | np_ndarray_anyint | IntegerArray ,
88- dtype : IntDtypeArg | UIntDtypeArg | None = None ,
123+ dtype : BuiltinIntDtypeArg | PandasIntDtypeArg | PandasUIntDtypeArg | None = None ,
89124 copy : bool = True ,
90125) -> IntegerArray : ...
91126@overload
92127def array ( # type: ignore[overload-overlap]
93128 data : (
94129 Sequence [float | np .floating | NAType | None ] | np_ndarray_float | FloatingArray
95130 ),
96- dtype : FloatDtypeArg | None = None ,
131+ dtype : BuiltinFloatDtypeArg | PandasFloatDtypeArg | None = None ,
97132 copy : bool = True ,
98133) -> FloatingArray : ...
99134@overload
@@ -106,75 +141,54 @@ def array( # type: ignore[overload-overlap]
106141 | DatetimeIndex
107142 | Series [Timestamp ]
108143 ),
109- dtype : TimestampDtypeArg | None = None ,
144+ dtype : PandasTimestampDtypeArg | None = None ,
110145 copy : bool = True ,
111146) -> DatetimeArray : ...
112147@overload
113- def array ( # type: ignore[overload-overlap]
148+ def array (
114149 data : (
115150 Sequence [timedelta | np .timedelta64 | NaTType | None ]
116151 | np_ndarray_td
117152 | TimedeltaArray
118153 | TimedeltaIndex
119154 | Series [Timedelta ]
120155 ),
121- dtype : TimedeltaDtypeArg | None = None ,
156+ dtype : None = None ,
122157 copy : bool = True ,
123158) -> TimedeltaArray : ...
124159@overload
125- def array (
160+ def array ( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
126161 data : SequenceNotStr [str | np .str_ | NAType | None ] | np_ndarray_str | StringArray ,
127- dtype : StrDtypeArg | None = None ,
162+ dtype : BuiltinStrDtypeArg | PandasStrDtypeArg | None = None ,
128163 copy : bool = True ,
129164) -> StringArray : ...
130165@overload
131166def array ( # type: ignore[overload-overlap]
132167 data : (
133- Sequence [Period | NaTType | None ] | PeriodArray | PeriodIndex | Series [Period ]
168+ SequenceNotStr [str | np .str_ | NAType | None ]
169+ | np_ndarray_str
170+ | StringArray
171+ | ArrowStringArray
134172 ),
135- dtype : PeriodDtype | None = None ,
136- copy : bool = True ,
137- ) -> PeriodArray : ...
138- @overload
139- def array (
140- # float("nan") also works, but I don't know how to put it in
141- data : Sequence [IntervalT | None ] | IntervalArray | IntervalIndex | Series [Interval ],
142- dtype : IntervalDtype | None = None ,
173+ dtype : PyArrowStrDtypeArg | None = None ,
143174 copy : bool = True ,
144- ) -> IntervalArray : ...
145- @overload
146- def array (
147- # TODO: Categorical Series pandas-dev/pandas-stubs#1415
148- data : Categorical | CategoricalIndex ,
149- dtype : CategoryDtypeArg | None = None ,
150- copy : bool = True ,
151- ) -> Categorical : ...
175+ ) -> ArrowStringArray : ...
152176@overload
153177def array (
154- data : (
155- SequenceNotStr [object ]
156- | np .typing .NDArray [np .object_ ]
157- | NumpyExtensionArray
158- | RangeIndex
159- ),
160- dtype : str | np .dtype | ExtensionDtype | None = None ,
178+ data : SequenceNotStr [object ] | np_ndarray | NumpyExtensionArray | RangeIndex ,
179+ dtype : NumpyDtypeArg | None = None ,
161180 copy : bool = True ,
162181) -> NumpyExtensionArray : ...
163182@overload
164- def array (
165- data : SparseArray | SparseIndex ,
166- dtype : str | np .dtype | ExtensionDtype | None = None ,
167- copy : bool = True ,
168- ) -> SparseArray : ...
169- @overload
170183def array (
171184 data : ArrowExtensionArray ,
172- dtype : str | np . dtype | ExtensionDtype | None = None ,
185+ dtype : PyArrowNotStrDtypeArg | None = None ,
173186 copy : bool = True ,
174187) -> ArrowExtensionArray : ...
175- @overload
176- def array (
177- data : SequenceNotStr [Any ] | np_ndarray | ExtensionArray | Index | Series ,
178- dtype : str | np .dtype | ExtensionDtype | None = None ,
179- copy : bool = True ,
180- ) -> ExtensionArray : ...
188+
189+ # @overload
190+ # def array(
191+ # data: SequenceNotStr[Any] | np_ndarray | ExtensionArray | Index | Series,
192+ # dtype: str | np.dtype | ExtensionDtype | None = None,
193+ # copy: bool = True,
194+ # ) -> ExtensionArray: ...
0 commit comments