File tree 3 files changed +6
-9
lines changed
3 files changed +6
-9
lines changed Original file line number Diff line number Diff line change @@ -279,6 +279,7 @@ Reshaping
279
279
280
280
- Bug in :meth: `DataFrame.apply ` that caused incorrect output with empty :class: `DataFrame ` (:issue: `28202 `, :issue: `21959 `)
281
281
- Bug in :meth: `DataFrame.stack ` not handling non-unique indexes correctly when creating MultiIndex (:issue: `28301 `)
282
+ - Bug :func: `merge_asof ` could not use :class: `datetime.timedelta ` for ``tolerance `` kwarg (:issue: `28098 `)
282
283
283
284
Sparse
284
285
^^^^^^
Original file line number Diff line number Diff line change 3
3
"""
4
4
5
5
import copy
6
+ import datetime
6
7
from functools import partial
7
8
import string
8
9
import warnings
@@ -1619,7 +1620,7 @@ def _get_merge_keys(self):
1619
1620
)
1620
1621
raise MergeError (msg )
1621
1622
1622
- # validate tolerance; must be a Timedelta if we have a DTI
1623
+ # validate tolerance; datetime.timedelta or Timedelta if we have a DTI
1623
1624
if self .tolerance is not None :
1624
1625
1625
1626
if self .left_index :
@@ -1635,7 +1636,7 @@ def _get_merge_keys(self):
1635
1636
)
1636
1637
1637
1638
if is_datetimelike (lt ):
1638
- if not isinstance (self .tolerance , Timedelta ):
1639
+ if not isinstance (self .tolerance , datetime . timedelta ):
1639
1640
raise MergeError (msg )
1640
1641
if self .tolerance < Timedelta (0 ):
1641
1642
raise MergeError ("tolerance must be positive" )
@@ -1705,6 +1706,7 @@ def flip(xs):
1705
1706
left_values = left_values .view ("i8" )
1706
1707
right_values = right_values .view ("i8" )
1707
1708
if tolerance is not None :
1709
+ tolerance = Timedelta (tolerance )
1708
1710
tolerance = tolerance .value
1709
1711
1710
1712
# a "by" parameter requires special handling
Original file line number Diff line number Diff line change @@ -592,13 +592,7 @@ def test_non_sorted(self):
592
592
593
593
@pytest .mark .parametrize (
594
594
"tolerance" ,
595
- [
596
- Timedelta ("1day" ),
597
- pytest .param (
598
- datetime .timedelta (days = 1 ),
599
- marks = pytest .mark .xfail (reason = "not implemented" , strict = True ),
600
- ),
601
- ],
595
+ [Timedelta ("1day" ), datetime .timedelta (days = 1 )],
602
596
ids = ["pd.Timedelta" , "datetime.timedelta" ],
603
597
)
604
598
def test_tolerance (self , tolerance ):
You can’t perform that action at this time.
0 commit comments