From 533d40749b2942d7337c087b21dfc04b9f54d225 Mon Sep 17 00:00:00 2001 From: ianzur Date: Mon, 29 Jul 2019 16:29:27 -0500 Subject: [PATCH 01/19] issue #27642 - timedelta merge asof with tolerance --- pandas/core/reshape/merge.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index fc32a8f0dd044..7ab51abd5b740 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -35,6 +35,7 @@ is_number, is_numeric_dtype, is_object_dtype, + is_timedelta64_dtype, needs_i8_conversion, ) from pandas.core.dtypes.missing import isnull, na_value_for_dtype @@ -1635,7 +1636,11 @@ def _get_merge_keys(self): ) ) - if is_datetime64_dtype(lt) or is_datetime64tz_dtype(lt): + if( + is_datetime64_dtype(lt) + or is_datetime64tz_dtype(lt) + or is_timedelta64_dtype(lt) + ): if not isinstance(self.tolerance, Timedelta): raise MergeError(msg) if self.tolerance < Timedelta(0): From 431da66d26d9a12955151159bc2c5c8d9caa801c Mon Sep 17 00:00:00 2001 From: ianzur Date: Mon, 29 Jul 2019 16:36:54 -0500 Subject: [PATCH 02/19] #27642 --- pandas/core/reshape/merge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index 7ab51abd5b740..9be1146c0efb1 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -1637,7 +1637,7 @@ def _get_merge_keys(self): ) if( - is_datetime64_dtype(lt) + is_datetime64_dtype(lt) or is_datetime64tz_dtype(lt) or is_timedelta64_dtype(lt) ): From c9acc0997788c647ee917082d5ce123ba61efc84 Mon Sep 17 00:00:00 2001 From: ianzur Date: Tue, 30 Jul 2019 00:38:18 -0500 Subject: [PATCH 03/19] whatsnew --- doc/source/whatsnew/v0.25.1.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v0.25.1.rst b/doc/source/whatsnew/v0.25.1.rst index fa9ca98f9c8d8..e28a8d394d067 100644 --- a/doc/source/whatsnew/v0.25.1.rst +++ b/doc/source/whatsnew/v0.25.1.rst @@ -42,8 +42,8 @@ Datetimelike Timedelta ^^^^^^^^^ - -- + +- - - @@ -129,7 +129,7 @@ Reshaping ^^^^^^^^^ - A ``KeyError`` is now raised if ``.unstack()`` is called on a :class:`Series` or :class:`DataFrame` with a flat :class:`Index` passing a name which is not the correct one (:issue:`18303`) -- +- Bug in ``merge_asof(tolerance=tolerance)`` could not merge :class:`TimedeltaIndex` objects (:issue:`27642`) - Sparse From 76f6525072e7bc2aac61a2b7980b9f1148cdbf90 Mon Sep 17 00:00:00 2001 From: ianzur Date: Tue, 30 Jul 2019 01:44:33 -0500 Subject: [PATCH 04/19] #27642 added testing stuff --- pandas/tests/reshape/merge/test_merge_asof.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/pandas/tests/reshape/merge/test_merge_asof.py b/pandas/tests/reshape/merge/test_merge_asof.py index 6b66386bafc5e..f7986ab30c24e 100644 --- a/pandas/tests/reshape/merge/test_merge_asof.py +++ b/pandas/tests/reshape/merge/test_merge_asof.py @@ -1246,3 +1246,38 @@ def test_by_mixed_tz_aware(self): ) expected["value_y"] = np.array([np.nan], dtype=object) assert_frame_equal(result, expected) + + def test_timedelta_tolerance_nearest(self): + # GH 27642 + + left = pd.DataFrame( + { + 'time': pd.to_timedelta([0, 5, 10, 15, 20, 25], 'ms'), + 'left': [0, 1, 2, 3, 4, 5] + } + ) + + right = pd.DataFrame( + { + 'time': pd.to_timedelta([0, 3, 9, 12, 15, 18], 'ms'), + 'right': [0, 1, 2, 3, 4, 5] + } + ) + + expected = pd.DataFrame( + { + 'time': pd.to_timedelta([0, 5, 10, 15, 20, 25], 'ms'), + 'left': [0, 1, 2, 3, 4, 5], + 'right': [0, np.nan, 2, 4, np.nan, np.nan] + } + ) + + result = pd.merge_asof( + left, + right, + on='time', + tolerance=pd.Timedelta('1ms'), + direction="nearest" + ) + + assert_frame_equal(result, expected) From fd1dbb25fc8c2843f6be45d2f7c00eb8bfe43e59 Mon Sep 17 00:00:00 2001 From: ianzur Date: Tue, 30 Jul 2019 01:59:15 -0500 Subject: [PATCH 05/19] mroeschke: this test is for you :rocket: --- pandas/tests/reshape/merge/test_merge_asof.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pandas/tests/reshape/merge/test_merge_asof.py b/pandas/tests/reshape/merge/test_merge_asof.py index f7986ab30c24e..e9bf721a1b8c8 100644 --- a/pandas/tests/reshape/merge/test_merge_asof.py +++ b/pandas/tests/reshape/merge/test_merge_asof.py @@ -1,4 +1,5 @@ import numpy as np +import datetime import pytest import pytz @@ -599,6 +600,18 @@ def test_tolerance(self): expected = self.tolerance assert_frame_equal(result, expected) + def test_datetime_timedelta_tolerance(self): + + trades = self.trades + quotes = self.quotes + + result = merge_asof( + trades, quotes, on="time", by="ticker", tolerance=datetime.timedelta(days=1) + ) + expected = self.tolerance + + assert_frame_equal(result, expected) + def test_tolerance_forward(self): # GH14887 From 63b7a2b3ec96867919431d1f81f897a815f08641 Mon Sep 17 00:00:00 2001 From: ianzur Date: Tue, 30 Jul 2019 02:04:06 -0500 Subject: [PATCH 06/19] some words --- doc/source/whatsnew/v0.25.1.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.1.rst b/doc/source/whatsnew/v0.25.1.rst index e28a8d394d067..374c604fc4e3f 100644 --- a/doc/source/whatsnew/v0.25.1.rst +++ b/doc/source/whatsnew/v0.25.1.rst @@ -129,7 +129,7 @@ Reshaping ^^^^^^^^^ - A ``KeyError`` is now raised if ``.unstack()`` is called on a :class:`Series` or :class:`DataFrame` with a flat :class:`Index` passing a name which is not the correct one (:issue:`18303`) -- Bug in ``merge_asof(tolerance=tolerance)`` could not merge :class:`TimedeltaIndex` objects (:issue:`27642`) +- Bug in ``merge_asof(tolerance=tolerance)`` could not merge :class:`Timedelta` objects (:issue:`27642`) - Sparse From 84759ac90abd9214ddd739c08c853496452e5092 Mon Sep 17 00:00:00 2001 From: ianzur Date: Tue, 30 Jul 2019 03:07:23 -0500 Subject: [PATCH 07/19] remove some whitespace --- doc/source/whatsnew/v0.25.1.rst | 6 +++--- pandas/core/reshape/merge.py | 2 +- pandas/tests/reshape/merge/test_merge_asof.py | 20 ++++++++----------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/doc/source/whatsnew/v0.25.1.rst b/doc/source/whatsnew/v0.25.1.rst index 374c604fc4e3f..d800894d0375e 100644 --- a/doc/source/whatsnew/v0.25.1.rst +++ b/doc/source/whatsnew/v0.25.1.rst @@ -42,8 +42,8 @@ Datetimelike Timedelta ^^^^^^^^^ - -- + +- - - @@ -129,7 +129,7 @@ Reshaping ^^^^^^^^^ - A ``KeyError`` is now raised if ``.unstack()`` is called on a :class:`Series` or :class:`DataFrame` with a flat :class:`Index` passing a name which is not the correct one (:issue:`18303`) -- Bug in ``merge_asof(tolerance=tolerance)`` could not merge :class:`Timedelta` objects (:issue:`27642`) +- Bug in ``.merge_asof(tolerance=tolerance)`` could not merge :class:`Timedelta` objects (:issue:`27642`) - Sparse diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index 9be1146c0efb1..1a7ec0b5a7875 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -1636,7 +1636,7 @@ def _get_merge_keys(self): ) ) - if( + if ( is_datetime64_dtype(lt) or is_datetime64tz_dtype(lt) or is_timedelta64_dtype(lt) diff --git a/pandas/tests/reshape/merge/test_merge_asof.py b/pandas/tests/reshape/merge/test_merge_asof.py index e9bf721a1b8c8..451353703c513 100644 --- a/pandas/tests/reshape/merge/test_merge_asof.py +++ b/pandas/tests/reshape/merge/test_merge_asof.py @@ -1265,32 +1265,28 @@ def test_timedelta_tolerance_nearest(self): left = pd.DataFrame( { - 'time': pd.to_timedelta([0, 5, 10, 15, 20, 25], 'ms'), - 'left': [0, 1, 2, 3, 4, 5] + "time": pd.to_timedelta([0, 5, 10, 15, 20, 25], "ms"), + "left": [0, 1, 2, 3, 4, 5], } ) right = pd.DataFrame( { - 'time': pd.to_timedelta([0, 3, 9, 12, 15, 18], 'ms'), - 'right': [0, 1, 2, 3, 4, 5] + "time": pd.to_timedelta([0, 3, 9, 12, 15, 18], "ms"), + "right": [0, 1, 2, 3, 4, 5], } ) expected = pd.DataFrame( { - 'time': pd.to_timedelta([0, 5, 10, 15, 20, 25], 'ms'), - 'left': [0, 1, 2, 3, 4, 5], - 'right': [0, np.nan, 2, 4, np.nan, np.nan] + "time": pd.to_timedelta([0, 5, 10, 15, 20, 25], "ms"), + "left": [0, 1, 2, 3, 4, 5], + "right": [0, np.nan, 2, 4, np.nan, np.nan], } ) result = pd.merge_asof( - left, - right, - on='time', - tolerance=pd.Timedelta('1ms'), - direction="nearest" + left, right, on="time", tolerance=pd.Timedelta("1ms"), direction="nearest" ) assert_frame_equal(result, expected) From 04c18e9f15358ac2b91631abfaf0f4151cf289cf Mon Sep 17 00:00:00 2001 From: ianzur Date: Tue, 30 Jul 2019 09:04:22 -0500 Subject: [PATCH 08/19] a comment --- pandas/tests/reshape/merge/test_merge_asof.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/reshape/merge/test_merge_asof.py b/pandas/tests/reshape/merge/test_merge_asof.py index 451353703c513..903f6156d5cac 100644 --- a/pandas/tests/reshape/merge/test_merge_asof.py +++ b/pandas/tests/reshape/merge/test_merge_asof.py @@ -601,6 +601,7 @@ def test_tolerance(self): assert_frame_equal(result, expected) def test_datetime_timedelta_tolerance(self): + # this will fail trades = self.trades quotes = self.quotes From ac7691861c2fee9f7a2d1c4849a0404bba76f2bd Mon Sep 17 00:00:00 2001 From: ianzur Date: Wed, 31 Jul 2019 13:14:49 -0500 Subject: [PATCH 09/19] docs change --- doc/source/whatsnew/v0.25.1.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.1.rst b/doc/source/whatsnew/v0.25.1.rst index d800894d0375e..0d27f7de35d72 100644 --- a/doc/source/whatsnew/v0.25.1.rst +++ b/doc/source/whatsnew/v0.25.1.rst @@ -129,7 +129,7 @@ Reshaping ^^^^^^^^^ - A ``KeyError`` is now raised if ``.unstack()`` is called on a :class:`Series` or :class:`DataFrame` with a flat :class:`Index` passing a name which is not the correct one (:issue:`18303`) -- Bug in ``.merge_asof(tolerance=tolerance)`` could not merge :class:`Timedelta` objects (:issue:`27642`) +- Bug :meth:`merge_asof` could not merge :class:`Timedelta` objects when passing `tolerance` kwarg (:issue:`27642`) - Sparse From a26bb717dfa4946887689367f77ba532b08138a1 Mon Sep 17 00:00:00 2001 From: ianzur Date: Wed, 31 Jul 2019 14:15:43 -0500 Subject: [PATCH 10/19] callbacks are :fireworks: --- pandas/tests/reshape/merge/test_merge_asof.py | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/pandas/tests/reshape/merge/test_merge_asof.py b/pandas/tests/reshape/merge/test_merge_asof.py index 903f6156d5cac..89c150496ac4c 100644 --- a/pandas/tests/reshape/merge/test_merge_asof.py +++ b/pandas/tests/reshape/merge/test_merge_asof.py @@ -589,28 +589,24 @@ def test_non_sorted(self): # ok, though has dupes merge_asof(trades, self.quotes, on="time", by="ticker") - def test_tolerance(self): - - trades = self.trades - quotes = self.quotes - - result = merge_asof( - trades, quotes, on="time", by="ticker", tolerance=Timedelta("1day") - ) - expected = self.tolerance - assert_frame_equal(result, expected) - - def test_datetime_timedelta_tolerance(self): - # this will fail + @pytest.mark.parametrize( + "tolerance", + [ + Timedelta("1day"), + pytest.param( + datetime.timedelta(days=1), + marks=pytest.mark.xfail(reason="not implemented", strict=True), + ), + ], + ids=["pd.Timedelta", "datetime.timedelta"], + ) + def test_tolerance(self, tolerance): trades = self.trades quotes = self.quotes - result = merge_asof( - trades, quotes, on="time", by="ticker", tolerance=datetime.timedelta(days=1) - ) + result = merge_asof(trades, quotes, on="time", by="ticker", tolerance=tolerance) expected = self.tolerance - assert_frame_equal(result, expected) def test_tolerance_forward(self): From a0ba5d9874a511617f95b6855426a5d6420acc12 Mon Sep 17 00:00:00 2001 From: ianzur Date: Wed, 31 Jul 2019 14:28:29 -0500 Subject: [PATCH 11/19] whitespace --- pandas/core/reshape/merge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index 1a7ec0b5a7875..9be1146c0efb1 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -1636,7 +1636,7 @@ def _get_merge_keys(self): ) ) - if ( + if( is_datetime64_dtype(lt) or is_datetime64tz_dtype(lt) or is_timedelta64_dtype(lt) From e5456ac95919cc6b9a3851cfd53c86ae56ca72d1 Mon Sep 17 00:00:00 2001 From: ianzur Date: Wed, 31 Jul 2019 15:06:10 -0500 Subject: [PATCH 12/19] little stuff --- doc/source/whatsnew/v0.25.1.rst | 2 +- pandas/core/reshape/merge.py | 2 +- pandas/tests/reshape/merge/test_merge_asof.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v0.25.1.rst b/doc/source/whatsnew/v0.25.1.rst index ba02d0eb68c9c..1a1b33818a7f9 100644 --- a/doc/source/whatsnew/v0.25.1.rst +++ b/doc/source/whatsnew/v0.25.1.rst @@ -42,7 +42,7 @@ Datetimelike Timedelta ^^^^^^^^^ - + - - - diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index 9be1146c0efb1..1a7ec0b5a7875 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -1636,7 +1636,7 @@ def _get_merge_keys(self): ) ) - if( + if ( is_datetime64_dtype(lt) or is_datetime64tz_dtype(lt) or is_timedelta64_dtype(lt) diff --git a/pandas/tests/reshape/merge/test_merge_asof.py b/pandas/tests/reshape/merge/test_merge_asof.py index 89c150496ac4c..41b2f84aaa1ce 100644 --- a/pandas/tests/reshape/merge/test_merge_asof.py +++ b/pandas/tests/reshape/merge/test_merge_asof.py @@ -1,5 +1,5 @@ -import numpy as np import datetime +import numpy as np import pytest import pytz @@ -1283,7 +1283,7 @@ def test_timedelta_tolerance_nearest(self): ) result = pd.merge_asof( - left, right, on="time", tolerance=pd.Timedelta("1ms"), direction="nearest" + left, right, on="time", tolerance=Timedelta("1ms"), direction="nearest" ) assert_frame_equal(result, expected) From 4f56dc42f8e06b7ba238b4c956e4f1d8908d4bf1 Mon Sep 17 00:00:00 2001 From: ianzur Date: Thu, 1 Aug 2019 20:42:11 -0500 Subject: [PATCH 13/19] isort --- pandas/tests/reshape/merge/test_merge_asof.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/reshape/merge/test_merge_asof.py b/pandas/tests/reshape/merge/test_merge_asof.py index 41b2f84aaa1ce..d7c2349489184 100644 --- a/pandas/tests/reshape/merge/test_merge_asof.py +++ b/pandas/tests/reshape/merge/test_merge_asof.py @@ -1,4 +1,5 @@ import datetime + import numpy as np import pytest import pytz From 52193a48f930b0e77474f78b21872f5ee2dede22 Mon Sep 17 00:00:00 2001 From: ianzur Date: Thu, 1 Aug 2019 21:49:20 -0500 Subject: [PATCH 14/19] I think this'll work --- pandas/tests/reshape/merge/test_merge_asof.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/reshape/merge/test_merge_asof.py b/pandas/tests/reshape/merge/test_merge_asof.py index d7c2349489184..1e5ad17eab42c 100644 --- a/pandas/tests/reshape/merge/test_merge_asof.py +++ b/pandas/tests/reshape/merge/test_merge_asof.py @@ -1287,4 +1287,4 @@ def test_timedelta_tolerance_nearest(self): left, right, on="time", tolerance=Timedelta("1ms"), direction="nearest" ) - assert_frame_equal(result, expected) + assert_frame_equal(result, expected, check_names=False) From 7c004c96ffd4bea5ee0d55b612297b6674084110 Mon Sep 17 00:00:00 2001 From: ianzur Date: Thu, 1 Aug 2019 22:00:04 -0500 Subject: [PATCH 15/19] cleaner --- pandas/core/reshape/merge.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index 1a7ec0b5a7875..6dcb79a29de36 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -35,7 +35,6 @@ is_number, is_numeric_dtype, is_object_dtype, - is_timedelta64_dtype, needs_i8_conversion, ) from pandas.core.dtypes.missing import isnull, na_value_for_dtype @@ -1636,11 +1635,7 @@ def _get_merge_keys(self): ) ) - if ( - is_datetime64_dtype(lt) - or is_datetime64tz_dtype(lt) - or is_timedelta64_dtype(lt) - ): + if is_datetimelike(lt): if not isinstance(self.tolerance, Timedelta): raise MergeError(msg) if self.tolerance < Timedelta(0): From 8f8aeb37df06a33b6791bbd731cbea9233d09237 Mon Sep 17 00:00:00 2001 From: ianzur Date: Fri, 9 Aug 2019 10:41:07 -0500 Subject: [PATCH 16/19] :bug: :wrench: --- pandas/tests/reshape/merge/test_merge_asof.py | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/pandas/tests/reshape/merge/test_merge_asof.py b/pandas/tests/reshape/merge/test_merge_asof.py index 1e5ad17eab42c..4e4cb0da15fdc 100644 --- a/pandas/tests/reshape/merge/test_merge_asof.py +++ b/pandas/tests/reshape/merge/test_merge_asof.py @@ -1262,29 +1262,32 @@ def test_timedelta_tolerance_nearest(self): # GH 27642 left = pd.DataFrame( - { - "time": pd.to_timedelta([0, 5, 10, 15, 20, 25], "ms"), - "left": [0, 1, 2, 3, 4, 5], - } + list(zip([0, 5, 10, 15, 20, 25], + [0, 1, 2, 3, 4, 5])), + columns=['time', 'left'] ) + left['time'] = pd.to_timedelta(left['time'], "ms") + right = pd.DataFrame( - { - "time": pd.to_timedelta([0, 3, 9, 12, 15, 18], "ms"), - "right": [0, 1, 2, 3, 4, 5], - } + list(zip([0, 3, 9, 12, 15, 18], + [0, 1, 2, 3, 4, 5])), + columns=['time', 'right'] ) + right['time'] = pd.to_timedelta(right['time'], "ms") + expected = pd.DataFrame( - { - "time": pd.to_timedelta([0, 5, 10, 15, 20, 25], "ms"), - "left": [0, 1, 2, 3, 4, 5], - "right": [0, np.nan, 2, 4, np.nan, np.nan], - } + list(zip([0, 5, 10, 15, 20, 25], + [0, 1, 2, 3, 4, 5], + [0, np.nan, 2, 4, np.nan, np.nan])), + columns=['time', 'left', 'right'] ) + expected['time'] = pd.to_timedelta(expected['time'], "ms") + result = pd.merge_asof( left, right, on="time", tolerance=Timedelta("1ms"), direction="nearest" ) - assert_frame_equal(result, expected, check_names=False) + assert_frame_equal(result, expected) From f66fce48215c4207fa6a73fcc116bbd223972a3a Mon Sep 17 00:00:00 2001 From: ianzur Date: Fri, 9 Aug 2019 11:57:43 -0500 Subject: [PATCH 17/19] blacked --- pandas/tests/reshape/merge/test_merge_asof.py | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/pandas/tests/reshape/merge/test_merge_asof.py b/pandas/tests/reshape/merge/test_merge_asof.py index 4e4cb0da15fdc..7412b1de643a1 100644 --- a/pandas/tests/reshape/merge/test_merge_asof.py +++ b/pandas/tests/reshape/merge/test_merge_asof.py @@ -1262,29 +1262,31 @@ def test_timedelta_tolerance_nearest(self): # GH 27642 left = pd.DataFrame( - list(zip([0, 5, 10, 15, 20, 25], - [0, 1, 2, 3, 4, 5])), - columns=['time', 'left'] + list(zip([0, 5, 10, 15, 20, 25], [0, 1, 2, 3, 4, 5])), + columns=["time", "left"], ) - left['time'] = pd.to_timedelta(left['time'], "ms") + left["time"] = pd.to_timedelta(left["time"], "ms") right = pd.DataFrame( - list(zip([0, 3, 9, 12, 15, 18], - [0, 1, 2, 3, 4, 5])), - columns=['time', 'right'] + list(zip([0, 3, 9, 12, 15, 18], [0, 1, 2, 3, 4, 5])), + columns=["time", "right"], ) - right['time'] = pd.to_timedelta(right['time'], "ms") + right["time"] = pd.to_timedelta(right["time"], "ms") expected = pd.DataFrame( - list(zip([0, 5, 10, 15, 20, 25], - [0, 1, 2, 3, 4, 5], - [0, np.nan, 2, 4, np.nan, np.nan])), - columns=['time', 'left', 'right'] + list( + zip( + [0, 5, 10, 15, 20, 25], + [0, 1, 2, 3, 4, 5], + [0, np.nan, 2, 4, np.nan, np.nan], + ) + ), + columns=["time", "left", "right"], ) - expected['time'] = pd.to_timedelta(expected['time'], "ms") + expected["time"] = pd.to_timedelta(expected["time"], "ms") result = pd.merge_asof( left, right, on="time", tolerance=Timedelta("1ms"), direction="nearest" From 0eb173f664143c3983499d9245d07d9ec7835925 Mon Sep 17 00:00:00 2001 From: ianzur Date: Fri, 9 Aug 2019 11:58:08 -0500 Subject: [PATCH 18/19] unused import --- pandas/core/reshape/merge.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index af29a69036e3a..225de3f11cf7d 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -22,7 +22,6 @@ is_bool, is_bool_dtype, is_categorical_dtype, - is_datetime64_dtype, is_datetime64tz_dtype, is_datetimelike, is_dtype_equal, From 6f7151da7a0107bccdc92606fa10dbddffedcce3 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Thu, 22 Aug 2019 06:36:49 -0500 Subject: [PATCH 19/19] Removed duplicate --- doc/source/whatsnew/v0.25.1.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.1.rst b/doc/source/whatsnew/v0.25.1.rst index b833f4a3705a4..33296045fa05c 100644 --- a/doc/source/whatsnew/v0.25.1.rst +++ b/doc/source/whatsnew/v0.25.1.rst @@ -96,7 +96,6 @@ Reshaping - A ``KeyError`` is now raised if ``.unstack()`` is called on a :class:`Series` or :class:`DataFrame` with a flat :class:`Index` passing a name which is not the correct one (:issue:`18303`) - Bug :meth:`merge_asof` could not merge :class:`Timedelta` objects when passing `tolerance` kwarg (:issue:`27642`) -- Bug in :meth:`DataFrame.crosstab` when ``margins`` set to ``True`` and ``normalize`` is not ``False``, an error is raised. (:issue:`27500`) - Bug in :meth:`DataFrame.crosstab` when ``margins`` set to ``True`` and ``normalize`` is not ``False``, an error is raised. (:issue:`27500`) - :meth:`DataFrame.join` now suppresses the ``FutureWarning`` when the sort parameter is specified (:issue:`21952`) - Bug in :meth:`DataFrame.join` raising with readonly arrays (:issue:`27943`)