Skip to content

Commit

Permalink
BUG: DataFrame.join on tz-aware DatetimeIndex (pandas-dev#25260)
Browse files Browse the repository at this point in the history
(cherry picked from commit a9a03a2)
  • Loading branch information
mroeschke authored and Matt Roeschke committed Feb 12, 2019
1 parent 4728f0b commit ea4ace9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Bug Fixes
**Reshaping**

-
-
- Bug in :func:`DataFrame.join` when joining on a timezone aware :class:`DatetimeIndex` (:issue:`23931`)
-

**Visualization**
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ def _get_merge_keys(self):
in zip(self.right.index.levels,
self.right.index.codes)]
else:
right_keys = [self.right.index.values]
right_keys = [self.right.index._values]
elif _any(self.right_on):
for k in self.right_on:
if is_rkey(k):
Expand Down
22 changes: 22 additions & 0 deletions pandas/tests/reshape/merge/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,28 @@ def test_join_multi_to_multi(self, join_type):
with pytest.raises(ValueError, match=msg):
right.join(left, on=['abc', 'xy'], how=join_type)

def test_join_on_tz_aware_datetimeindex(self):
# GH 23931
df1 = pd.DataFrame(
{
'date': pd.date_range(start='2018-01-01', periods=5,
tz='America/Chicago'),
'vals': list('abcde')
}
)

df2 = pd.DataFrame(
{
'date': pd.date_range(start='2018-01-03', periods=5,
tz='America/Chicago'),
'vals_2': list('tuvwx')
}
)
result = df1.join(df2.set_index('date'), on='date')
expected = df1.copy()
expected['vals_2'] = pd.Series([np.nan] * len(expected), dtype=object)
assert_frame_equal(result, expected)


def _check_join(left, right, result, join_col, how='left',
lsuffix='_x', rsuffix='_y'):
Expand Down

0 comments on commit ea4ace9

Please sign in to comment.