Skip to content

Commit b3c5b8c

Browse files
TomAugspurgerPingviinituutti
authored andcommitted
BUG: Fixed merging on tz-aware (pandas-dev#25033)
1 parent 69f9a22 commit b3c5b8c

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

doc/source/whatsnew/v0.24.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Fixed Regressions
2323
- Bug in :meth:`DataFrame.itertuples` with ``records`` orient raising an ``AttributeError`` when the ``DataFrame`` contained more than 255 columns (:issue:`24939`)
2424
- Bug in :meth:`DataFrame.itertuples` orient converting integer column names to strings prepended with an underscore (:issue:`24940`)
2525
- Fixed regression in :class:`Index.intersection` incorrectly sorting the values by default (:issue:`24959`).
26+
- Fixed regression in :func:`merge` when merging an empty ``DataFrame`` with multiple timezone-aware columns on one of the timezone-aware columns (:issue:`25014`).
2627

2728
.. _whatsnew_0241.enhancements:
2829

pandas/core/internals/concat.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def get_reindexed_values(self, empty_dtype, upcasted_na):
183183
is_datetime64tz_dtype(empty_dtype)):
184184
if self.block is None:
185185
array = empty_dtype.construct_array_type()
186-
return array(np.full(self.shape[1], fill_value),
186+
return array(np.full(self.shape[1], fill_value.value),
187187
dtype=empty_dtype)
188188
pass
189189
elif getattr(self.block, 'is_categorical', False):
@@ -335,8 +335,10 @@ def get_empty_dtype_and_na(join_units):
335335
elif 'category' in upcast_classes:
336336
return np.dtype(np.object_), np.nan
337337
elif 'datetimetz' in upcast_classes:
338+
# GH-25014. We use NaT instead of iNaT, since this eventually
339+
# ends up in DatetimeArray.take, which does not allow iNaT.
338340
dtype = upcast_classes['datetimetz']
339-
return dtype[0], tslibs.iNaT
341+
return dtype[0], tslibs.NaT
340342
elif 'datetime' in upcast_classes:
341343
return np.dtype('M8[ns]'), tslibs.iNaT
342344
elif 'timedelta' in upcast_classes:

pandas/tests/reshape/merge/test_merge.py

+18
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,24 @@ def test_merge_on_datetime64tz(self):
616616
assert result['value_x'].dtype == 'datetime64[ns, US/Eastern]'
617617
assert result['value_y'].dtype == 'datetime64[ns, US/Eastern]'
618618

619+
def test_merge_on_datetime64tz_empty(self):
620+
# https://github.com/pandas-dev/pandas/issues/25014
621+
dtz = pd.DatetimeTZDtype(tz='UTC')
622+
right = pd.DataFrame({'date': [pd.Timestamp('2018', tz=dtz.tz)],
623+
'value': [4.0],
624+
'date2': [pd.Timestamp('2019', tz=dtz.tz)]},
625+
columns=['date', 'value', 'date2'])
626+
left = right[:0]
627+
result = left.merge(right, on='date')
628+
expected = pd.DataFrame({
629+
'value_x': pd.Series(dtype=float),
630+
'date2_x': pd.Series(dtype=dtz),
631+
'date': pd.Series(dtype=dtz),
632+
'value_y': pd.Series(dtype=float),
633+
'date2_y': pd.Series(dtype=dtz),
634+
}, columns=['value_x', 'date2_x', 'date', 'value_y', 'date2_y'])
635+
tm.assert_frame_equal(result, expected)
636+
619637
def test_merge_datetime64tz_with_dst_transition(self):
620638
# GH 18885
621639
df1 = pd.DataFrame(pd.date_range(

0 commit comments

Comments
 (0)