From 02943255c738f921e036ccf5c25514075cd9205a Mon Sep 17 00:00:00 2001 From: Liang Yan Date: Mon, 6 Mar 2023 12:42:05 +0800 Subject: [PATCH] add concat function dtype test Signed-off-by: Liang Yan --- pandas/tests/reshape/concat/test_datetimes.py | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/pandas/tests/reshape/concat/test_datetimes.py b/pandas/tests/reshape/concat/test_datetimes.py index f16358813488e..43c6bb03b6a9a 100644 --- a/pandas/tests/reshape/concat/test_datetimes.py +++ b/pandas/tests/reshape/concat/test_datetimes.py @@ -538,3 +538,40 @@ def test_concat_multiindex_datetime_nat(): {"a": [1.0, np.nan], "b": 2}, MultiIndex.from_tuples([(1, pd.NaT), (2, pd.NaT)]) ) tm.assert_frame_equal(result, expected) + + +def test_concat_float_datetime64(using_array_manager): + # GH#32934 + df_time = DataFrame({"A": pd.array(["2000"], dtype="datetime64[ns]")}) + df_float = DataFrame({"A": pd.array([1.0], dtype="float64")}) + + expected = DataFrame( + { + "A": [ + pd.array(["2000"], dtype="datetime64[ns]")[0], + pd.array([1.0], dtype="float64")[0], + ] + }, + index=[0, 0], + ) + result = concat([df_time, df_float]) + tm.assert_frame_equal(result, expected) + + expected = DataFrame({"A": pd.array([], dtype="object")}) + result = concat([df_time.iloc[:0], df_float.iloc[:0]]) + tm.assert_frame_equal(result, expected) + + expected = DataFrame({"A": pd.array([1.0], dtype="object")}) + result = concat([df_time.iloc[:0], df_float]) + tm.assert_frame_equal(result, expected) + + if not using_array_manager: + expected = DataFrame({"A": pd.array(["2000"], dtype="datetime64[ns]")}) + result = concat([df_time, df_float.iloc[:0]]) + tm.assert_frame_equal(result, expected) + else: + expected = DataFrame({"A": pd.array(["2000"], dtype="datetime64[ns]")}).astype( + {"A": "object"} + ) + result = concat([df_time, df_float.iloc[:0]]) + tm.assert_frame_equal(result, expected)