Skip to content

Commit 7ba2ec8

Browse files
mroeschkejreback
authored andcommitted
BUG: DataFrame.join on tz aware index and column (#26362)
1 parent 612c244 commit 7ba2ec8

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

doc/source/whatsnew/v0.25.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ Timezones
298298
- Bug in :func:`DataFrame.update` when updating with timezone aware data would return timezone naive data (:issue:`25807`)
299299
- Bug in :func:`to_datetime` where an uninformative ``RuntimeError`` was raised when passing a naive :class:`Timestamp` with datetime strings with mixed UTC offsets (:issue:`25978`)
300300
- Bug in :func:`to_datetime` with ``unit='ns'`` would drop timezone information from the parsed argument (:issue:`26168`)
301+
- Bug in :func:`DataFrame.join` where joining a timezone aware index with a timezone aware column would result in a column of ``NaN`` (:issue:`26335`)
301302

302303
Numeric
303304
^^^^^^^

pandas/core/reshape/merge.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1674,8 +1674,8 @@ def _right_outer_join(x, y, max_groups):
16741674
def _factorize_keys(lk, rk, sort=True):
16751675
# Some pre-processing for non-ndarray lk / rk
16761676
if is_datetime64tz_dtype(lk) and is_datetime64tz_dtype(rk):
1677-
lk = lk._data
1678-
rk = rk._data
1677+
lk = getattr(lk, '_values', lk)._data
1678+
rk = getattr(rk, '_values', rk)._data
16791679

16801680
elif (is_categorical_dtype(lk) and
16811681
is_categorical_dtype(rk) and

pandas/tests/reshape/merge/test_join.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ def test_join_multi_to_multi(self, join_type):
679679
right.join(left, on=['abc', 'xy'], how=join_type)
680680

681681
def test_join_on_tz_aware_datetimeindex(self):
682-
# GH 23931
682+
# GH 23931, 26335
683683
df1 = pd.DataFrame(
684684
{
685685
'date': pd.date_range(start='2018-01-01', periods=5,
@@ -697,7 +697,8 @@ def test_join_on_tz_aware_datetimeindex(self):
697697
)
698698
result = df1.join(df2.set_index('date'), on='date')
699699
expected = df1.copy()
700-
expected['vals_2'] = pd.Series([np.nan] * len(expected), dtype=object)
700+
expected['vals_2'] = pd.Series([np.nan] * 2 + list('tuv'),
701+
dtype=object)
701702
assert_frame_equal(result, expected)
702703

703704

0 commit comments

Comments
 (0)