28
28
from pandas ._typing import Dtype
29
29
30
30
from pandas .core .dtypes .common import (
31
- is_datetime64_dtype ,
32
- is_datetime64tz_dtype ,
33
31
is_float_dtype ,
34
32
is_integer_dtype ,
35
- is_period_dtype ,
36
33
is_sequence ,
37
- is_timedelta64_dtype ,
38
34
is_unsigned_integer_dtype ,
39
35
pandas_dtype ,
40
36
)
41
- from pandas .core .dtypes .dtypes import IntervalDtype
42
37
43
38
import pandas as pd
44
39
from pandas import (
112
107
)
113
108
from pandas .core .arrays import (
114
109
BaseMaskedArray ,
115
- DatetimeArray ,
116
110
ExtensionArray ,
117
111
PandasArray ,
118
- PeriodArray ,
119
- TimedeltaArray ,
120
- period_array ,
121
112
)
122
113
from pandas .core .arrays ._mixins import NDArrayBackedExtensionArray
114
+ from pandas .core .construction import extract_array
123
115
124
116
if TYPE_CHECKING :
125
117
from pandas import (
@@ -268,13 +260,6 @@ def box_expected(expected, box_cls, transpose=True):
268
260
# single-row special cases in datetime arithmetic
269
261
expected = expected .T
270
262
expected = pd .concat ([expected ] * 2 , ignore_index = True )
271
- elif box_cls is PeriodArray :
272
- # the PeriodArray constructor is not as flexible as period_array
273
- expected = period_array (expected )
274
- elif box_cls is DatetimeArray :
275
- expected = DatetimeArray (expected )
276
- elif box_cls is TimedeltaArray :
277
- expected = TimedeltaArray (expected )
278
263
elif box_cls is np .ndarray or box_cls is np .array :
279
264
expected = np .array (expected )
280
265
elif box_cls is to_array :
@@ -285,21 +270,16 @@ def box_expected(expected, box_cls, transpose=True):
285
270
286
271
287
272
def to_array (obj ):
273
+ """
274
+ Similar to pd.array, but does not cast numpy dtypes to nullable dtypes.
275
+ """
288
276
# temporary implementation until we get pd.array in place
289
277
dtype = getattr (obj , "dtype" , None )
290
278
291
- if is_period_dtype (dtype ):
292
- return period_array (obj )
293
- elif is_datetime64_dtype (dtype ) or is_datetime64tz_dtype (dtype ):
294
- return DatetimeArray ._from_sequence (obj )
295
- elif is_timedelta64_dtype (dtype ):
296
- return TimedeltaArray ._from_sequence (obj )
297
- elif isinstance (obj , pd .core .arrays .BooleanArray ):
298
- return obj
299
- elif isinstance (dtype , IntervalDtype ):
300
- return pd .core .arrays .IntervalArray (obj )
301
- else :
302
- return np .array (obj )
279
+ if dtype is None :
280
+ return np .asarray (obj )
281
+
282
+ return extract_array (obj , extract_numpy = True )
303
283
304
284
305
285
# -----------------------------------------------------------------------------
0 commit comments