From d75762d94296b459d1d80c5f05812001114db76f Mon Sep 17 00:00:00 2001 From: srkds Date: Wed, 3 May 2023 00:25:55 +0530 Subject: [PATCH 1/4] BUG: NaT instead of error for timestamp --- pandas/core/internals/managers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 36dd0cece0f20..723f75d707541 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -26,6 +26,7 @@ BlockPlacement, BlockValuesRefs, ) +from pandas._libs.tslibs import NaT from pandas.errors import PerformanceWarning from pandas.util._decorators import cache_readonly from pandas.util._exceptions import find_stack_level @@ -2358,7 +2359,7 @@ def _preprocess_slice_or_indexer( def make_na_array(dtype: DtypeObj, shape: Shape, fill_value) -> ArrayLike: if isinstance(dtype, DatetimeTZDtype): # NB: exclude e.g. pyarrow[dt64tz] dtypes - i8values = np.full(shape, fill_value._value) + i8values = np.full(shape, NaT.value) return DatetimeArray(i8values, dtype=dtype) elif is_1d_only_ea_dtype(dtype): From c1c56754595c590204a407f9567b42380ef265dd Mon Sep 17 00:00:00 2001 From: srkds Date: Mon, 8 May 2023 23:37:21 +0530 Subject: [PATCH 2/4] Timestamp --- pandas/core/internals/managers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index cdaa3ef39821f..acea84a0ff7ef 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -26,7 +26,7 @@ BlockPlacement, BlockValuesRefs, ) -from pandas._libs.tslibs import NaT +from pandas._libs.tslibs import Timestamp from pandas.errors import PerformanceWarning from pandas.util._decorators import cache_readonly from pandas.util._exceptions import find_stack_level @@ -2406,7 +2406,7 @@ def _preprocess_slice_or_indexer( def make_na_array(dtype: DtypeObj, shape: Shape, fill_value) -> ArrayLike: if isinstance(dtype, DatetimeTZDtype): # NB: exclude e.g. pyarrow[dt64tz] dtypes - i8values = np.full(shape, NaT.value) + i8values = np.full(shape, Timestamp(fill_value)._value) return DatetimeArray(i8values, dtype=dtype) elif is_1d_only_ea_dtype(dtype): From 4171a7c0f5aa9f15f283d4c24df3cdf57d6445a5 Mon Sep 17 00:00:00 2001 From: srkds Date: Tue, 9 May 2023 23:40:58 +0530 Subject: [PATCH 3/4] whatsnew entry --- doc/source/whatsnew/v2.1.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index 62d56f684a11d..1a63cdc6050ca 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -309,6 +309,7 @@ Categorical Datetimelike ^^^^^^^^^^^^ - :meth:`DatetimeIndex.map` with ``na_action="ignore"`` now works as expected. (:issue:`51644`) +- Bug in :func:`concat` raises ``AttributeError`` when concate ``None`` dtype DataFrame with ``timestamp`` dtype DataFrame. (:issue:`52093`) - Bug in :func:`date_range` when ``freq`` was a :class:`DateOffset` with ``nanoseconds`` (:issue:`46877`) - Bug in :meth:`Timestamp.round` with values close to the implementation bounds returning incorrect results instead of raising ``OutOfBoundsDatetime`` (:issue:`51494`) - Bug in :meth:`arrays.DatetimeArray.map` and :meth:`DatetimeIndex.map`, where the supplied callable operated array-wise instead of element-wise (:issue:`51977`) From 416f4a8b99cc3622aa94bfaebb8781bf9efd3260 Mon Sep 17 00:00:00 2001 From: srkds Date: Mon, 26 Jun 2023 18:58:16 +0530 Subject: [PATCH 4/4] added actual bug test case --- pandas/tests/reshape/concat/test_concat.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pandas/tests/reshape/concat/test_concat.py b/pandas/tests/reshape/concat/test_concat.py index dc14e6e74302e..28f3995d1102e 100644 --- a/pandas/tests/reshape/concat/test_concat.py +++ b/pandas/tests/reshape/concat/test_concat.py @@ -826,3 +826,14 @@ def test_concat_mismatched_keys_length(): concat((x for x in sers), keys=(y for y in keys), axis=1) with tm.assert_produces_warning(FutureWarning, match=msg): concat((x for x in sers), keys=(y for y in keys), axis=0) + + +def test_concat_none_with_datetime(): + # GH 52093 + df1 = DataFrame([{"A": None}], dtype="datetime64[ns, UTC]") + df2 = DataFrame([{"A": pd.to_datetime("1990-12-20 00:00:00+00:00")}]) + result = concat([df1, df2]) + expected = DataFrame( + [{"A": None}, {"A": pd.to_datetime("1990-12-20 00:00:00+00:00")}], index=[0, 0] + ) + tm.assert_frame_equal(result, expected)