From eeb27fefc2e66af42e1f1e2fd3279f584ae5b65e Mon Sep 17 00:00:00 2001 From: Gustavo Gobetti Bertocco Date: Thu, 16 Dec 2021 13:54:48 -0300 Subject: [PATCH 1/3] added dtype test concat --- pandas/tests/dtypes/test_concat.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pandas/tests/dtypes/test_concat.py b/pandas/tests/dtypes/test_concat.py index f624c56b54001..c4ba658d18fa6 100644 --- a/pandas/tests/dtypes/test_concat.py +++ b/pandas/tests/dtypes/test_concat.py @@ -44,3 +44,21 @@ def test_concat_periodarray_2d(): with pytest.raises(ValueError, match=msg): _concat.concat_compat([arr[:2], arr[2:]], axis=1) + +def test_concat_float_datetime(): + # Mock dataframes + df_time = pd.DataFrame({"A": pd.array(["2000"], dtype="datetime64[ns]")}) + df_float = pd.DataFrame({"A": pd.array([1.0], dtype="float64")}) + + msg = "dtype of concat should be a object type" + with pytest.raises(ValueError, match=msg): + isinstance(pd.concat([df_time.iloc[:0], df_float.iloc[:0]])["A"].dtype, object) + + with pytest.raises(ValueError, match=msg): + isinstance(pd.concat([df_time.iloc[:0], df_float.iloc[:0]])["A"].dtype, object) + + with pytest.raises(ValueError, match=msg): + isinstance(pd.concat([df_time.iloc[:0], df_float])["A"].dtype, object) + + with pytest.raises(ValueError, match=msg): + isinstance(pd.concat([df_time, df_float.iloc[:0]])["A"].dtype, object) From 665a69dac5ad124961faa518b11dec27a323cf9a Mon Sep 17 00:00:00 2001 From: Gustavo Gobetti Bertocco Date: Thu, 16 Dec 2021 15:35:28 -0300 Subject: [PATCH 2/3] removed pytest context manager --- pandas/tests/dtypes/test_concat.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/pandas/tests/dtypes/test_concat.py b/pandas/tests/dtypes/test_concat.py index c4ba658d18fa6..9d47c8d8f7c9e 100644 --- a/pandas/tests/dtypes/test_concat.py +++ b/pandas/tests/dtypes/test_concat.py @@ -45,20 +45,16 @@ def test_concat_periodarray_2d(): with pytest.raises(ValueError, match=msg): _concat.concat_compat([arr[:2], arr[2:]], axis=1) + def test_concat_float_datetime(): - # Mock dataframes + df_time = pd.DataFrame({"A": pd.array(["2000"], dtype="datetime64[ns]")}) df_float = pd.DataFrame({"A": pd.array([1.0], dtype="float64")}) - msg = "dtype of concat should be a object type" - with pytest.raises(ValueError, match=msg): - isinstance(pd.concat([df_time.iloc[:0], df_float.iloc[:0]])["A"].dtype, object) + assert pd.concat([df_time.iloc[:0], df_float.iloc[:0]])["A"].dtype == object - with pytest.raises(ValueError, match=msg): - isinstance(pd.concat([df_time.iloc[:0], df_float.iloc[:0]])["A"].dtype, object) + assert pd.concat([df_time.iloc[:0], df_float.iloc[:0]])["A"].dtype == object - with pytest.raises(ValueError, match=msg): - isinstance(pd.concat([df_time.iloc[:0], df_float])["A"].dtype, object) + assert pd.concat([df_time.iloc[:0], df_float])["A"].dtype == object - with pytest.raises(ValueError, match=msg): - isinstance(pd.concat([df_time, df_float.iloc[:0]])["A"].dtype, object) + assert pd.concat([df_time, df_float.iloc[:0]])["A"].dtype == object From 31620ef3c8289d464f57d9839e9e29c31a0389cf Mon Sep 17 00:00:00 2001 From: Gustavo Gobetti Bertocco Date: Thu, 16 Dec 2021 16:37:47 -0300 Subject: [PATCH 3/3] moved test to test_datetime64 --- pandas/tests/arithmetic/test_datetime64.py | 12 ++++++++++++ pandas/tests/dtypes/test_concat.py | 14 -------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/pandas/tests/arithmetic/test_datetime64.py b/pandas/tests/arithmetic/test_datetime64.py index 49585f3d37924..4ab3fe894a456 100644 --- a/pandas/tests/arithmetic/test_datetime64.py +++ b/pandas/tests/arithmetic/test_datetime64.py @@ -2494,3 +2494,15 @@ def test_dt64arr_addsub_object_dtype_2d(): assert result2.shape == (4, 1) assert result2.freq is None assert (result2.asi8 == 0).all() + + +def test_concat_float_datetime64(): + # GH Issue number #32934 + df_time = pd.DataFrame({"A": pd.array(["2000"], dtype="datetime64[ns]")}) + df_float = pd.DataFrame({"A": pd.array([1.0], dtype="float64")}) + + assert pd.concat([df_time, df_float])["A"].dtype == object + assert pd.concat([df_time.iloc[:0], df_float.iloc[:0]])["A"].dtype == object + assert pd.concat([df_time.iloc[:0], df_float.iloc[:0]])["A"].dtype == object + assert pd.concat([df_time.iloc[:0], df_float])["A"].dtype == object + assert pd.concat([df_time, df_float.iloc[:0]])["A"].dtype == object diff --git a/pandas/tests/dtypes/test_concat.py b/pandas/tests/dtypes/test_concat.py index 9d47c8d8f7c9e..f624c56b54001 100644 --- a/pandas/tests/dtypes/test_concat.py +++ b/pandas/tests/dtypes/test_concat.py @@ -44,17 +44,3 @@ def test_concat_periodarray_2d(): with pytest.raises(ValueError, match=msg): _concat.concat_compat([arr[:2], arr[2:]], axis=1) - - -def test_concat_float_datetime(): - - df_time = pd.DataFrame({"A": pd.array(["2000"], dtype="datetime64[ns]")}) - df_float = pd.DataFrame({"A": pd.array([1.0], dtype="float64")}) - - assert pd.concat([df_time.iloc[:0], df_float.iloc[:0]])["A"].dtype == object - - assert pd.concat([df_time.iloc[:0], df_float.iloc[:0]])["A"].dtype == object - - assert pd.concat([df_time.iloc[:0], df_float])["A"].dtype == object - - assert pd.concat([df_time, df_float.iloc[:0]])["A"].dtype == object