|
5 | 5 |
|
6 | 6 | import numpy as np
|
7 | 7 |
|
8 |
| -from pandas._libs import NaT, lib |
| 8 | +from pandas._libs import lib |
9 | 9 | from pandas._typing import ArrayLike, DtypeObj
|
10 | 10 |
|
11 | 11 | from pandas.core.dtypes.cast import find_common_type
|
12 | 12 | from pandas.core.dtypes.common import (
|
13 | 13 | is_bool_dtype,
|
14 | 14 | is_categorical_dtype,
|
15 |
| - is_datetime64_ns_dtype, |
16 | 15 | is_dtype_equal,
|
17 | 16 | is_extension_array_dtype,
|
18 | 17 | is_integer_dtype,
|
19 | 18 | is_sparse,
|
20 |
| - is_timedelta64_ns_dtype, |
21 | 19 | )
|
22 | 20 | from pandas.core.dtypes.generic import ABCCategoricalIndex, ABCSeries
|
| 21 | +from pandas.core.dtypes.missing import na_value_for_dtype |
23 | 22 |
|
24 | 23 | from pandas.core.arrays import ExtensionArray
|
25 | 24 | from pandas.core.arrays.sparse import SparseArray
|
@@ -67,27 +66,18 @@ def _array_from_proxy(arr, dtype: DtypeObj, fill_value=lib.no_default):
|
67 | 66 | return dtype.construct_array_type()._from_sequence(
|
68 | 67 | [dtype.na_value] * arr.n, dtype=dtype
|
69 | 68 | )
|
70 |
| - elif is_datetime64_ns_dtype(dtype): |
71 |
| - from pandas.core.arrays import DatetimeArray |
72 |
| - |
73 |
| - return DatetimeArray._from_sequence([NaT] * arr.n, dtype=dtype) |
74 |
| - elif is_timedelta64_ns_dtype(dtype): |
75 |
| - from pandas.core.arrays import TimedeltaArray |
76 |
| - |
77 |
| - return TimedeltaArray._from_sequence([NaT] * arr.n, dtype=dtype) |
78 | 69 | else:
|
79 | 70 | if is_integer_dtype(dtype):
|
80 |
| - dtype = "float64" |
81 |
| - fill_value = np.nan |
| 71 | + dtype = np.dtype("float64") |
82 | 72 | elif is_bool_dtype(dtype):
|
83 |
| - dtype = object |
| 73 | + dtype = np.dtype(object) |
84 | 74 |
|
85 | 75 | if fill_value is lib.no_default:
|
86 |
| - fill_value = np.nan |
| 76 | + fill_value = na_value_for_dtype(dtype) |
87 | 77 |
|
88 | 78 | arr = np.empty(arr.n, dtype=dtype)
|
89 | 79 | arr.fill(fill_value)
|
90 |
| - return arr |
| 80 | + return ensure_wrapped_if_datetimelike(arr) |
91 | 81 |
|
92 | 82 |
|
93 | 83 | def _cast_to_common_type(arr: ArrayLike, dtype: DtypeObj) -> ArrayLike:
|
|
0 commit comments