Skip to content

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

Closed
@ZhuBaohe

Description

@ZhuBaohe

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions