Skip to content

Commit 8b7fd0d

Browse files
yuanx749srkds
andauthored
BUG: fix AttributeError raised with pd.concat between a None and timezone-aware Timestamp (pandas-dev#54428)
* BUG: NaT instead of error for timestamp * Timestamp * whatsnew entry * added actual bug test case * Update test * Update whatsnew * Add unit * Update * Move whatsnew --------- Co-authored-by: srkds <[email protected]>
1 parent 0de3bcb commit 8b7fd0d

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

doc/source/whatsnew/v2.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ Categorical
301301

302302
Datetimelike
303303
^^^^^^^^^^^^
304+
- Bug in :func:`concat` raising ``AttributeError`` when concatenating all-NA DataFrame with :class:`DatetimeTZDtype` dtype DataFrame. (:issue:`52093`)
304305
- Bug in :meth:`DatetimeIndex.union` returning object dtype for tz-aware indexes with the same timezone but different units (:issue:`55238`)
305306
- Bug in :meth:`Tick.delta` with very large ticks raising ``OverflowError`` instead of ``OutOfBoundsTimedelta`` (:issue:`55503`)
306307
- 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`)

pandas/core/internals/managers.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
BlockPlacement,
2727
BlockValuesRefs,
2828
)
29+
from pandas._libs.tslibs import Timestamp
2930
from pandas.errors import PerformanceWarning
3031
from pandas.util._decorators import cache_readonly
3132
from pandas.util._exceptions import find_stack_level
@@ -2304,7 +2305,8 @@ def _preprocess_slice_or_indexer(
23042305
def make_na_array(dtype: DtypeObj, shape: Shape, fill_value) -> ArrayLike:
23052306
if isinstance(dtype, DatetimeTZDtype):
23062307
# NB: exclude e.g. pyarrow[dt64tz] dtypes
2307-
i8values = np.full(shape, fill_value._value)
2308+
ts = Timestamp(fill_value).as_unit(dtype.unit)
2309+
i8values = np.full(shape, ts._value)
23082310
return DatetimeArray(i8values, dtype=dtype)
23092311

23102312
elif is_1d_only_ea_dtype(dtype):

pandas/tests/reshape/concat/test_concat.py

+11
Original file line numberDiff line numberDiff line change
@@ -867,3 +867,14 @@ def test_concat_ea_upcast():
867867
result = concat([df1, df2])
868868
expected = DataFrame(["a", 1], index=[0, 0])
869869
tm.assert_frame_equal(result, expected)
870+
871+
872+
def test_concat_none_with_timezone_timestamp():
873+
# GH#52093
874+
df1 = DataFrame([{"A": None}])
875+
df2 = DataFrame([{"A": pd.Timestamp("1990-12-20 00:00:00+00:00")}])
876+
msg = "The behavior of DataFrame concatenation with empty or all-NA entries"
877+
with tm.assert_produces_warning(FutureWarning, match=msg):
878+
result = concat([df1, df2], ignore_index=True)
879+
expected = DataFrame({"A": [None, pd.Timestamp("1990-12-20 00:00:00+00:00")]})
880+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)