From 140b0692667689a00a2273797d5b0e2d4f8df610 Mon Sep 17 00:00:00 2001 From: ZhuBaohe Date: Sat, 17 Feb 2018 10:01:57 +0800 Subject: [PATCH 1/4] DOC: correct merge_asof example --- pandas/core/reshape/merge.py | 4 ++-- pandas/tests/reshape/merge/test_merge_asof.py | 22 ++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index 4b99b0407cfcc..7b1a0875bba59 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -457,8 +457,8 @@ def merge_asof(left, right, on=None, time ticker price quantity bid ask 0 2016-05-25 13:30:00.023 MSFT 51.95 75 NaN NaN 1 2016-05-25 13:30:00.038 MSFT 51.95 155 51.97 51.98 - 2 2016-05-25 13:30:00.048 GOOG 720.77 100 720.50 720.93 - 3 2016-05-25 13:30:00.048 GOOG 720.92 100 720.50 720.93 + 2 2016-05-25 13:30:00.048 GOOG 720.77 100 NaN NaN + 3 2016-05-25 13:30:00.048 GOOG 720.92 100 NaN NaN 4 2016-05-25 13:30:00.048 AAPL 98.00 100 NaN NaN See also diff --git a/pandas/tests/reshape/merge/test_merge_asof.py b/pandas/tests/reshape/merge/test_merge_asof.py index 2f48aef1894a9..6cb29c19671ee 100644 --- a/pandas/tests/reshape/merge/test_merge_asof.py +++ b/pandas/tests/reshape/merge/test_merge_asof.py @@ -92,11 +92,31 @@ def test_examples2(self): by='ticker', tolerance=pd.Timedelta('2ms')) - pd.merge_asof(trades, quotes, + expected = pd.DataFrame({ + 'time': pd.to_datetime(['20160525 13:30:00.023', + '20160525 13:30:00.038', + '20160525 13:30:00.048', + '20160525 13:30:00.048', + '20160525 13:30:00.048']), + 'ticker': ['MSFT', 'MSFT','GOOG', + 'GOOG', 'AAPL'], + 'price': [51.95, 51.95, + 720.77, 720.92, 98.00], + 'quantity': [75, 155, + 100, 100, 100], + 'bid': [np.nan, 51.97, np.nan, + np.nan, np.nan], + 'ask': [np.nan, 51.98, np.nan, + np.nan, np.nan]}, + columns=['time', 'ticker', 'price', 'quantity', + 'bid', 'ask']) + + result = pd.merge_asof(trades, quotes, on='time', by='ticker', tolerance=pd.Timedelta('10ms'), allow_exact_matches=False) + assert_frame_equal(result, expected) def test_examples3(self): """ doc-string examples """ From f981e019a49189c2d57cfece1b641e0cf51f6452 Mon Sep 17 00:00:00 2001 From: ZhuBaohe Date: Sat, 17 Feb 2018 10:31:03 +0800 Subject: [PATCH 2/4] fix for PEP8 --- 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 6cb29c19671ee..312673b4f5d9e 100644 --- a/pandas/tests/reshape/merge/test_merge_asof.py +++ b/pandas/tests/reshape/merge/test_merge_asof.py @@ -98,7 +98,7 @@ def test_examples2(self): '20160525 13:30:00.048', '20160525 13:30:00.048', '20160525 13:30:00.048']), - 'ticker': ['MSFT', 'MSFT','GOOG', + 'ticker': ['MSFT', 'MSFT','GOOG', 'GOOG', 'AAPL'], 'price': [51.95, 51.95, 720.77, 720.92, 98.00], From b21b53f3aba74fef55eff5f69c7f914bfe741fad Mon Sep 17 00:00:00 2001 From: ZhuBaohe Date: Sun, 18 Feb 2018 16:08:42 +0800 Subject: [PATCH 3/4] fix space --- pandas/tests/reshape/merge/test_merge_asof.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/tests/reshape/merge/test_merge_asof.py b/pandas/tests/reshape/merge/test_merge_asof.py index 312673b4f5d9e..3dc39fe79d484 100644 --- a/pandas/tests/reshape/merge/test_merge_asof.py +++ b/pandas/tests/reshape/merge/test_merge_asof.py @@ -98,8 +98,7 @@ def test_examples2(self): '20160525 13:30:00.048', '20160525 13:30:00.048', '20160525 13:30:00.048']), - 'ticker': ['MSFT', 'MSFT','GOOG', - 'GOOG', 'AAPL'], + 'ticker': ['MSFT', 'MSFT', 'GOOG', 'GOOG', 'AAPL'], 'price': [51.95, 51.95, 720.77, 720.92, 98.00], 'quantity': [75, 155, From 16d4260f365decb0bfe84bb2a16a8283cd5e0069 Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Sun, 18 Feb 2018 12:45:04 -0500 Subject: [PATCH 4/4] lint --- pandas/tests/reshape/merge/test_merge_asof.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/reshape/merge/test_merge_asof.py b/pandas/tests/reshape/merge/test_merge_asof.py index 3dc39fe79d484..cebbcc41c3e17 100644 --- a/pandas/tests/reshape/merge/test_merge_asof.py +++ b/pandas/tests/reshape/merge/test_merge_asof.py @@ -111,10 +111,10 @@ def test_examples2(self): 'bid', 'ask']) result = pd.merge_asof(trades, quotes, - on='time', - by='ticker', - tolerance=pd.Timedelta('10ms'), - allow_exact_matches=False) + on='time', + by='ticker', + tolerance=pd.Timedelta('10ms'), + allow_exact_matches=False) assert_frame_equal(result, expected) def test_examples3(self):