Skip to content

Commit 555d7ac

Browse files
simplify _array_from_proxy
1 parent 272d674 commit 555d7ac

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

pandas/core/dtypes/concat.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@
55

66
import numpy as np
77

8-
from pandas._libs import NaT, lib
8+
from pandas._libs import lib
99
from pandas._typing import ArrayLike, DtypeObj
1010

1111
from pandas.core.dtypes.cast import find_common_type
1212
from pandas.core.dtypes.common import (
1313
is_bool_dtype,
1414
is_categorical_dtype,
15-
is_datetime64_ns_dtype,
1615
is_dtype_equal,
1716
is_extension_array_dtype,
1817
is_integer_dtype,
1918
is_sparse,
20-
is_timedelta64_ns_dtype,
2119
)
2220
from pandas.core.dtypes.generic import ABCCategoricalIndex, ABCSeries
21+
from pandas.core.dtypes.missing import na_value_for_dtype
2322

2423
from pandas.core.arrays import ExtensionArray
2524
from pandas.core.arrays.sparse import SparseArray
@@ -67,27 +66,18 @@ def _array_from_proxy(arr, dtype: DtypeObj, fill_value=lib.no_default):
6766
return dtype.construct_array_type()._from_sequence(
6867
[dtype.na_value] * arr.n, dtype=dtype
6968
)
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)
7869
else:
7970
if is_integer_dtype(dtype):
80-
dtype = "float64"
81-
fill_value = np.nan
71+
dtype = np.dtype("float64")
8272
elif is_bool_dtype(dtype):
83-
dtype = object
73+
dtype = np.dtype(object)
8474

8575
if fill_value is lib.no_default:
86-
fill_value = np.nan
76+
fill_value = na_value_for_dtype(dtype)
8777

8878
arr = np.empty(arr.n, dtype=dtype)
8979
arr.fill(fill_value)
90-
return arr
80+
return ensure_wrapped_if_datetimelike(arr)
9181

9282

9383
def _cast_to_common_type(arr: ArrayLike, dtype: DtypeObj) -> ArrayLike:

0 commit comments

Comments
 (0)