Skip to content

Commit c4fa6a5

Browse files
mroeschkejreback
authored andcommitted
BUG: merge_asof with tz_aware left index and right column (#29940)
1 parent 9333e3d commit c4fa6a5

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

doc/source/whatsnew/v1.0.0.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,8 @@ Reshaping
668668
- Bug where :meth:`DataFrame.equals` returned True incorrectly in some cases when two DataFrames had the same columns in different orders (:issue:`28839`)
669669
- Bug in :meth:`DataFrame.replace` that caused non-numeric replacer's dtype not respected (:issue:`26632`)
670670
- Bug in :func:`melt` where supplying mixed strings and numeric values for ``id_vars`` or ``value_vars`` would incorrectly raise a ``ValueError`` (:issue:`29718`)
671-
671+
- Bug in :func:`merge_asof` merging on a tz-aware ``left_index`` and ``right_on`` a tz-aware column (:issue:`29864`)
672+
-
672673

673674
Sparse
674675
^^^^^^

pandas/core/reshape/merge.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ def _get_merge_keys(self):
10271027
)
10281028
]
10291029
else:
1030-
left_keys = [self.left.index.values]
1030+
left_keys = [self.left.index._values]
10311031

10321032
if left_drop:
10331033
self.left = self.left._drop_labels_or_levels(left_drop)

pandas/tests/reshape/merge/test_merge_asof.py

+31
Original file line numberDiff line numberDiff line change
@@ -1303,3 +1303,34 @@ def test_int_type_tolerance(self, any_int_dtype):
13031303

13041304
result = pd.merge_asof(left, right, on="a", tolerance=10)
13051305
tm.assert_frame_equal(result, expected)
1306+
1307+
def test_merge_index_column_tz(self):
1308+
# GH 29864
1309+
index = pd.date_range("2019-10-01", freq="30min", periods=5, tz="UTC")
1310+
left = pd.DataFrame([0.9, 0.8, 0.7, 0.6], columns=["xyz"], index=index[1:])
1311+
right = pd.DataFrame({"from_date": index, "abc": [2.46] * 4 + [2.19]})
1312+
result = pd.merge_asof(
1313+
left=left, right=right, left_index=True, right_on=["from_date"]
1314+
)
1315+
expected = pd.DataFrame(
1316+
{
1317+
"xyz": [0.9, 0.8, 0.7, 0.6],
1318+
"from_date": index[1:],
1319+
"abc": [2.46] * 3 + [2.19],
1320+
},
1321+
index=pd.Index([1, 2, 3, 4]),
1322+
)
1323+
tm.assert_frame_equal(result, expected)
1324+
1325+
result = pd.merge_asof(
1326+
left=right, right=left, right_index=True, left_on=["from_date"]
1327+
)
1328+
expected = pd.DataFrame(
1329+
{
1330+
"from_date": index,
1331+
"abc": [2.46] * 4 + [2.19],
1332+
"xyz": [np.nan, 0.9, 0.8, 0.7, 0.6],
1333+
},
1334+
index=pd.Index([0, 1, 2, 3, 4]),
1335+
)
1336+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)