Skip to content

Feature request: asofjoin #2738

@natemcintosh

Description

@natemcintosh

This is a request for an asof join type, as seen in pandas, kdb+, QuestDB, and probably a few others.

This is a rather niche join, but extremely useful for time series work. I think the pandas' description sums it up pretty well:

This is similar to a left-join except that we match on nearest key rather than equal keys. Both DataFrames must be sorted by the key.
For each row in the left DataFrame:

  • A “backward” search selects the last row in the right DataFrame whose ‘on’ key is less than or equal to the left’s key.
  • A “forward” search selects the first row in the right DataFrame whose ‘on’ key is greater than or equal to the left’s key.
  • A “nearest” search selects the row in the right DataFrame whose ‘on’ key is closest in absolute distance to the left’s key.

The default is “backward” and is compatible in versions below 0.20.0. The direction parameter was added in version 0.20.0 and introduces “forward” and “nearest”.
Optionally match on equivalent keys with ‘by’ before searching with ‘on’.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions