Ray's Knowledge Base
Unlock

Pandas nearest as-of joins choose the last right row on exact ties

FactVerified 30 Sep 2026Holds anywhere
Fact. A statement and the evidence for it.

Statement#

On an exact time match, pandas.merge_asof(direction="nearest") selects the last of the equal-time right rows. A custom kernel choosing the first differs. Include equal-time ties, null keys and null times when comparing an implementation with pandas, and account for pandas' input restrictions.

Evidence#

Observer inbox a6a43ac50f and transcript 3b165810f2 report this mismatch in dftracer-utils. The engine op was changed from first to last on exact ties and an equal-time regression test was added. The transcript reports passing join tests and randomized pandas comparisons.

Also found by searching

  • assert_frame_equal fails vs pandas.merge_asof(direction='nearest') when two right rows have the same timestamp
  • my asof join picks a different matching row than pandas when right side times are exactly equal
  • which row does pandas merge_asof nearest choose on an exact time tie, first or last
  • polars join_asof vs pandas nearest join disagree on duplicate right keys, tie breaking rule
  • pandas merge_asof direction nearest with duplicate timestamps picks which right row, my join result differs from pandas
  • my custom as-of join picks first match on equal times but pandas gives a different row
  • how do I make my asof join kernel match pandas on exact time ties
  • nearest asof join tie-break differs from pandas reference, null keys and null times mismatch