diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index b30dbe32eec4b..1bc3c9647bfde 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -1829,7 +1829,16 @@ def construct_1d_ndarray_preserving_na( else: if dtype is not None: _disallow_mismatched_datetimelike(values, dtype) - subarr = np.array(values, dtype=dtype, copy=copy) + + if ( + dtype == object + and isinstance(values, np.ndarray) + and values.dtype.kind in ["m", "M"] + ): + # TODO(numpy#12550): special-case can be removed + subarr = construct_1d_object_array_from_listlike(list(values)) + else: + subarr = np.array(values, dtype=dtype, copy=copy) return subarr diff --git a/pandas/tests/dtypes/cast/test_construct_ndarray.py b/pandas/tests/dtypes/cast/test_construct_ndarray.py index fe271392122a2..72da93a5c4de3 100644 --- a/pandas/tests/dtypes/cast/test_construct_ndarray.py +++ b/pandas/tests/dtypes/cast/test_construct_ndarray.py @@ -19,3 +19,13 @@ def test_construct_1d_ndarray_preserving_na(values, dtype, expected): result = construct_1d_ndarray_preserving_na(values, dtype=dtype) tm.assert_numpy_array_equal(result, expected) + + +@pytest.mark.parametrize("dtype", ["m8[ns]", "M8[ns]"]) +def test_construct_1d_ndarray_preserving_na_datetimelike(dtype): + arr = np.arange(5, dtype=np.int64).view(dtype) + expected = np.array(list(arr), dtype=object) + assert all(isinstance(x, type(arr[0])) for x in expected) + + result = construct_1d_ndarray_preserving_na(arr, np.dtype(object)) + tm.assert_numpy_array_equal(result, expected)