Skip to content

Commit

Permalink
BUG: fix AttributeError raised with pd.concat between a None and time…
Browse files Browse the repository at this point in the history
…zone-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 <im.nirav86@gmail.com>
  • Loading branch information
yuanx749 and srkds authored Oct 23, 2023
1 parent 0de3bcb commit 8b7fd0d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/reshape/concat/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 8b7fd0d

Please sign in to comment.