Skip to content

BUG: fix AttributeError raised with pd.concat between a None and timezone-aware Timestamp #54428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d75762d
BUG: NaT instead of error for timestamp
srkds May 2, 2023
e17bd97
Merge remote-tracking branch 'upstream/main' into bug/52093/concat_no…
srkds May 3, 2023
8804de4
Merge remote-tracking branch 'upstream/main' into bug/52093/concat_no…
srkds May 8, 2023
c1c5675
Timestamp
srkds May 8, 2023
634e522
Merge remote-tracking branch 'upstream/main' into bug/52093/concat_no…
srkds May 9, 2023
4171a7c
whatsnew entry
srkds May 9, 2023
11db8f1
Resolved merge conflict: accepted both changes
srkds Jun 26, 2023
416f4a8
added actual bug test case
srkds Jun 26, 2023
8363a47
Merge remote-tracking branch 'upstream/main' into concat-none-dt
yuanx749 Aug 5, 2023
71788fd
Update test
yuanx749 Aug 5, 2023
b902ade
Update whatsnew
yuanx749 Aug 6, 2023
f3ddec2
Add unit
yuanx749 Aug 10, 2023
2c9e3f5
Merge remote-tracking branch 'upstream/main' into concat-none-dt
yuanx749 Aug 10, 2023
57dfdc5
Merge remote-tracking branch 'upstream/main' into concat-none-dt
yuanx749 Aug 16, 2023
dc073e9
Update
yuanx749 Aug 21, 2023
d13d27c
Merge remote-tracking branch 'upstream/main' into concat-none-dt
yuanx749 Aug 21, 2023
7f3d494
Merge remote-tracking branch 'upstream/main' into concat-none-dt
yuanx749 Aug 28, 2023
287bee1
Merge remote-tracking branch 'upstream/main' into concat-none-dt
yuanx749 Sep 10, 2023
4b5e247
Merge remote-tracking branch 'upstream/main' into concat-none-dt
yuanx749 Oct 11, 2023
b9e4c8b
Merge remote-tracking branch 'upstream/main' into concat-none-dt
yuanx749 Oct 23, 2023
4e76bbb
Merge remote-tracking branch 'upstream/main' into concat-none-dt
yuanx749 Oct 23, 2023
e5ae627
Move whatsnew
yuanx749 Oct 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)