diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index 9eb5bbc8f07d5..e3d17977ad26c 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -301,6 +301,7 @@ Categorical Datetimelike ^^^^^^^^^^^^ +- Bug in :func:`concat` raising ``AttributeError`` when concatenating all-NA DataFrame with :class:`DatetimeTZDtype` dtype DataFrame. (:issue:`52093`) - Bug in :meth:`DatetimeIndex.union` returning object dtype for tz-aware indexes with the same timezone but different units (:issue:`55238`) - Bug in :meth:`Tick.delta` with very large ticks raising ``OverflowError`` instead of ``OutOfBoundsTimedelta`` (:issue:`55503`) - Bug in adding or subtracting a :class:`Week` offset to a ``datetime64`` :class:`Series`, :class:`Index`, or :class:`DataFrame` column with non-nanosecond resolution returning incorrect results (:issue:`55583`) diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 86cef032ec6e4..c26e3a88951a8 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -26,6 +26,7 @@ BlockPlacement, BlockValuesRefs, ) +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 @@ -2304,7 +2305,8 @@ 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) + ts = Timestamp(fill_value).as_unit(dtype.unit) + i8values = np.full(shape, ts._value) return DatetimeArray(i8values, dtype=dtype) elif is_1d_only_ea_dtype(dtype): diff --git a/pandas/tests/reshape/concat/test_concat.py b/pandas/tests/reshape/concat/test_concat.py index 74c79d20a3fb3..131058010808e 100644 --- a/pandas/tests/reshape/concat/test_concat.py +++ b/pandas/tests/reshape/concat/test_concat.py @@ -867,3 +867,14 @@ def test_concat_ea_upcast(): result = concat([df1, df2]) expected = DataFrame(["a", 1], index=[0, 0]) tm.assert_frame_equal(result, expected) + + +def test_concat_none_with_timezone_timestamp(): + # GH#52093 + df1 = DataFrame([{"A": None}]) + df2 = DataFrame([{"A": pd.Timestamp("1990-12-20 00:00:00+00:00")}]) + msg = "The behavior of DataFrame concatenation with empty or all-NA entries" + with tm.assert_produces_warning(FutureWarning, match=msg): + result = concat([df1, df2], ignore_index=True) + expected = DataFrame({"A": [None, pd.Timestamp("1990-12-20 00:00:00+00:00")]}) + tm.assert_frame_equal(result, expected)