Skip to content
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

BUG: Fixed merging on tz-aware #25033

Merged
merged 3 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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/v0.24.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Fixed Regressions
- Bug in :meth:`DataFrame.itertuples` with ``records`` orient raising an ``AttributeError`` when the ``DataFrame`` contained more than 255 columns (:issue:`24939`)
- Bug in :meth:`DataFrame.itertuples` orient converting integer column names to strings prepended with an underscore (:issue:`24940`)
- Fixed regression in :class:`Index.intersection` incorrectly sorting the values by default (:issue:`24959`).
- Fixed regression in :func:`merge` when merging an empty ``DataFrame`` with multiple timezone-aware columns on one of the timezone-aware columns (:issue:`25014`).

.. _whatsnew_0241.enhancements:

Expand Down
5 changes: 5 additions & 0 deletions pandas/core/internals/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ def get_reindexed_values(self, empty_dtype, upcasted_na):

else:
for ax, indexer in self.indexers.items():
# GH-25014: get_upcasted_na returns iNaT, but
# DatetimeArray.take expects NaT.
# TODO: update get_empty_dtype_and_na to use EAs earlier?
if is_datetime64tz_dtype(values) and fill_value == tslibs.iNaT:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isnull(fill_value)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually this should be in take_nd I think (instead)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was (hopefully) able to fix it at the root, in get_empty_dtype_and_na.

fill_value = tslibs.NaT
values = algos.take_nd(values, indexer, axis=ax,
fill_value=fill_value)

Expand Down
18 changes: 18 additions & 0 deletions pandas/tests/reshape/merge/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,24 @@ def test_merge_on_datetime64tz(self):
assert result['value_x'].dtype == 'datetime64[ns, US/Eastern]'
assert result['value_y'].dtype == 'datetime64[ns, US/Eastern]'

def test_merge_on_datetime64tz_empty(self):
# https://github.com/pandas-dev/pandas/issues/25014
dtz = pd.DatetimeTZDtype(tz='UTC')
right = pd.DataFrame({'date': [pd.Timestamp('2018', tz=dtz.tz)],
'value': [4.0],
'date2': [pd.Timestamp('2019', tz=dtz.tz)]},
columns=['date', 'value', 'date2'])
left = right[:0]
result = left.merge(right, on='date')
expected = pd.DataFrame({
'value_x': pd.Series(dtype=float),
'date2_x': pd.Series(dtype=dtz),
'date': pd.Series(dtype=dtz),
'value_y': pd.Series(dtype=float),
'date2_y': pd.Series(dtype=dtz),
}, columns=['value_x', 'date2_x', 'date', 'value_y', 'date2_y'])
tm.assert_frame_equal(result, expected)

def test_merge_datetime64tz_with_dst_transition(self):
# GH 18885
df1 = pd.DataFrame(pd.date_range(
Expand Down