Skip to content

DOC: Incorrect explanation of merge_asof with direction="backward" #53279

Open
@mosew

Description

@mosew

Pandas version checks

  • I have checked that the issue still exists on the latest versions of the docs on main here

Location of the documentation

https://pandas.pydata.org/docs/reference/api/pandas.merge_asof.html

Documentation problem

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.

This is incorrect, as evidenced here:

left = pd.DataFrame(
    {
        "id": ["a"],
        "date": pd.to_datetime(
            ["20080102"]
        ),
    },
)

right = pd.DataFrame(
    {
        "id": ["a"],
        "date": pd.to_datetime([
            "20080101",
        ])
    },
)

pd.merge_asof(left=left, right=right, by="id", on="date")
  id date
  a 2008-01-02

Suggested fix for documentation

For each row in the left DataFrame:
        A “backward” search selects the last row in the **left** DataFrame whose ‘on’ key is less than or equal to the left’s key.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocsReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions