From 1cd66a11c11e88776798eedcb3ee7ad58b279e92 Mon Sep 17 00:00:00 2001 From: u7397058 Date: Mon, 20 Oct 2025 00:26:37 +1100 Subject: [PATCH 1/5] Additional "merge_asof" docs explaination --- pandas/core/reshape/merge.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index 604181214ad44..98084ae4d96cd 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -676,8 +676,11 @@ def merge_asof( """ Perform a merge by key distance. - 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. + This is similar to a left-join except that we match on nearest + key rather than equal keys. Both DataFrames must be first sorted by + the merge key in ascending order before calling this function. + Sorting by any additional 'by' grouping columns is not required. + For each row in the left DataFrame: @@ -700,19 +703,22 @@ def merge_asof( Second pandas object to merge. on : label Field name to join on. Must be found in both DataFrames. - The data MUST be ordered. Furthermore this must be a numeric column, - such as datetimelike, integer, or float. On or left_on/right_on - must be given. + The data MUST be in ascending order. Furthermore this must be + a numeric column, such as datetimelike, integer, or float. 'on' + or 'left_on' / 'right_on' must be given. left_on : label - Field name to join on in left DataFrame. + Field name to join on in left DataFrame. If specified, sort the left + DataFrame by this column in ascending order before merging. right_on : label - Field name to join on in right DataFrame. + Field name to join on in right DataFrame. If specified, sort the right + DataFrame by this column in ascending order before merging. left_index : bool Use the index of the left DataFrame as the join key. right_index : bool Use the index of the right DataFrame as the join key. by : column name or list of column names - Match on these columns before performing merge operation. + Match on these columns before performing merge operation. It is not required + to sort by these columns. left_by : column name Field names to match on in the left DataFrame. right_by : column name @@ -736,7 +742,9 @@ def merge_asof( Returns ------- DataFrame - A DataFrame of the two merged objects. + A DataFrame of the two merged objects, containing all rows from the + left DataFrame and the nearest matches from the right DataFrame. + See Also -------- From c9663dcceb7133f2eba5e44a8b9895b304fe6c10 Mon Sep 17 00:00:00 2001 From: u7397058 Date: Mon, 20 Oct 2025 00:49:22 +1100 Subject: [PATCH 2/5] Remove whitespace --- pandas/core/reshape/merge.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index 98084ae4d96cd..0ad17c3adc396 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -676,9 +676,9 @@ def merge_asof( """ Perform a merge by key distance. - This is similar to a left-join except that we match on nearest - key rather than equal keys. Both DataFrames must be first sorted by - the merge key in ascending order before calling this function. + This is similar to a left-join except that we match on nearest + key rather than equal keys. Both DataFrames must be first sorted by + the merge key in ascending order before calling this function. Sorting by any additional 'by' grouping columns is not required. @@ -703,14 +703,14 @@ def merge_asof( Second pandas object to merge. on : label Field name to join on. Must be found in both DataFrames. - The data MUST be in ascending order. Furthermore this must be - a numeric column, such as datetimelike, integer, or float. 'on' + The data MUST be in ascending order. Furthermore this must be + a numeric column, such as datetimelike, integer, or float. 'on' or 'left_on' / 'right_on' must be given. left_on : label - Field name to join on in left DataFrame. If specified, sort the left + Field name to join on in left DataFrame. If specified, sort the left DataFrame by this column in ascending order before merging. right_on : label - Field name to join on in right DataFrame. If specified, sort the right + Field name to join on in right DataFrame. If specified, sort the right DataFrame by this column in ascending order before merging. left_index : bool Use the index of the left DataFrame as the join key. @@ -742,7 +742,7 @@ def merge_asof( Returns ------- DataFrame - A DataFrame of the two merged objects, containing all rows from the + A DataFrame of the two merged objects, containing all rows from the left DataFrame and the nearest matches from the right DataFrame. From 904346fbdd4e52b4ab8df0e73260e9326a948e19 Mon Sep 17 00:00:00 2001 From: u7397058 Date: Mon, 20 Oct 2025 00:51:00 +1100 Subject: [PATCH 3/5] remove additional whitespaces --- pandas/core/reshape/merge.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index 0ad17c3adc396..71f75914a0672 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -717,7 +717,7 @@ def merge_asof( right_index : bool Use the index of the right DataFrame as the join key. by : column name or list of column names - Match on these columns before performing merge operation. It is not required + Match on these columns before performing merge operation. It is not required to sort by these columns. left_by : column name Field names to match on in the left DataFrame. @@ -745,7 +745,6 @@ def merge_asof( A DataFrame of the two merged objects, containing all rows from the left DataFrame and the nearest matches from the right DataFrame. - See Also -------- merge : Merge with a database-style join. From d4831b669f522a2aa94441e67bb60fd7c9ef95b7 Mon Sep 17 00:00:00 2001 From: u7397058 Date: Mon, 20 Oct 2025 10:08:54 +1100 Subject: [PATCH 4/5] remove double spaces --- pandas/core/reshape/merge.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index 71f75914a0672..a02d0bcb299de 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -681,7 +681,6 @@ def merge_asof( the merge key in ascending order before calling this function. Sorting by any additional 'by' grouping columns is not required. - For each row in the left DataFrame: - A "backward" search selects the last row in the right DataFrame whose From 002848b7a3ede8337037fb9e8cbbf8aef55b59f0 Mon Sep 17 00:00:00 2001 From: Zephy <74450862+zephyrieal@users.noreply.github.com> Date: Mon, 27 Oct 2025 14:35:39 +1100 Subject: [PATCH 5/5] Change single quotes to code quotes Co-authored-by: Richard Shadrach <45562402+rhshadrach@users.noreply.github.com> --- pandas/core/reshape/merge.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index a02d0bcb299de..399ce1ae26a96 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -703,8 +703,8 @@ def merge_asof( on : label Field name to join on. Must be found in both DataFrames. The data MUST be in ascending order. Furthermore this must be - a numeric column, such as datetimelike, integer, or float. 'on' - or 'left_on' / 'right_on' must be given. + a numeric column, such as datetimelike, integer, or float. ``on`` + or ``left_on`` / ``right_on`` must be given. left_on : label Field name to join on in left DataFrame. If specified, sort the left DataFrame by this column in ascending order before merging.