Skip to content

DOC: Incorrect example result in 'merge_asof' docstring #19489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ZhuBaohe opened this issue Feb 1, 2018 · 1 comment · Fixed by #19737
Closed

DOC: Incorrect example result in 'merge_asof' docstring #19489

ZhuBaohe opened this issue Feb 1, 2018 · 1 comment · Fixed by #19737
Labels
Milestone

Comments

@ZhuBaohe
Copy link
Contributor

ZhuBaohe commented Feb 1, 2018

Last example result is incorrect for 'merge_asof' functon in document.

>>> trades = 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]},
...                 columns=['time', 'ticker', 'price', 'quantity'])
>>> quotes = pd.DataFrame({
...                 'time': pd.to_datetime(['20160525 13:30:00.023',
...                                                      '20160525 13:30:00.023',
...                                                      '20160525 13:30:00.030',
...                                                      '20160525 13:30:00.041',
...                                                      '20160525 13:30:00.048',
...                                                      '20160525 13:30:00.049',
...                                                      '20160525 13:30:00.072',
...                                                     '20160525 13:30:00.075']),
...                   'ticker': ['GOOG', 'MSFT', 'MSFT', 'MSFT', 'GOOG', 'AAPL', 'GOOG', 'MSFT'],
...                   'bid': [720.50, 51.95, 51.97, 51.99, 720.50, 97.99, 720.50, 52.01],
...                   'ask': [720.93, 51.96, 51.98, 52.00, 720.93, 98.01, 720.88, 52.03]},
...                   columns=['time', 'ticker', 'bid', 'ask'])

The following changes should be made.

>>> pd.merge_asof(trades, quotes,
...                       on='time',
...                       by='ticker',
...                       tolerance=pd.Timedelta('10ms'),
...                       allow_exact_matches=False)
                     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    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
@jorisvandenbossche jorisvandenbossche changed the title Doc: Incorrect exmaple rusult for 'merge_asof' functon DOC: Incorrect example result in 'merge_asof' docstring Feb 2, 2018
@jorisvandenbossche
Copy link
Member

@ZhuBaohe Thanks for the report! I can confirm that this is wrong in the docs.

PR welcome to update the docstring. Although we should also figure out if the explanation before the example is then still correct?

We only asof within 10ms between the quote time and the trade time and we exclude exact matches on time. However prior data will propagate forward

@jreback jreback added this to the 0.23.0 milestone Feb 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants