Skip to content

feat: add DataFrame.join_asof and join_asof_using - #1869

Open
slachiewicz wants to merge 1 commit into
apache:mainfrom
slachiewicz:dataframe-join-asof
Open

slachiewicz wants to merge 1 commit into
apache:mainfrom
slachiewicz:dataframe-join-asof

Conversation

@slachiewicz

@slachiewicz slachiewicz commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

Which issue does this PR close?

Closes #1866.

Rationale for this change

An ASOF join pairs each row with the closest eligible row of another table, for example the latest price at or before each trade. DataFusion 56 added DataFrame::join_asof and DataFrame::join_asof_using, but the Python DataFrame did not expose them.

What changes are included in this PR?

Adds two DataFrame methods:

from datafusion import col

# For each trade, the latest price at or before its timestamp, per symbol
trades.join_asof(
    prices,
    col("trades.ts") >= col("prices.ts"),
    on=col("trades.symbol") == col("prices.symbol"),
)

# The same, naming the shared key column
trades.join_asof_using(prices, "symbol", col("trades.ts") >= col("prices.ts"))

How they behave:

  • Every left row is kept. A row with no eligible match gets nulls for the right columns.
  • match_condition is a single <, <=, > or >= comparison, with the left table on its left side.
  • on is optional. Without it, every right row is a candidate.
  • join_asof_using takes one column name or a list. It keeps the key columns of both sides in the result, the same as upstream.

The PR also adds docstring examples, tests, an "ASOF Join" section in the joins user guide, and an entry in the user-facing skill.

Open questions for review

  • Key columns after join_asof_using. DataFrame.join(on=...) coalesces same-named keys by default, but this method returns both sides' key columns, as upstream does. Should it coalesce to match join?
  • Two methods or one. I kept upstream's two methods. A single join_asof(..., on=None, using=None) would also work.
  • Shape of on. It is a single keyword-only Expr, with predicates combined by &. join_on takes *on_exprs instead; say if you prefer that form here.
  • Claims taken from the upstream docs, not tested here. "Rows with a null key never match" and the required operand order of match_condition have no test in this PR.
  • Docs build. I have not run the Sphinx build that executes the new guide cells locally.

Are there any user-facing changes?

Yes, two new methods: DataFrame.join_asof and DataFrame.join_asof_using. Nothing existing changes.

@slachiewicz
slachiewicz marked this pull request as ready for review December 6, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose DataFrame.join_asof and DataFrame.join_asof_using

1 participant