From 4c5fc38cf57630ae9aac4f3972ac3868ea9e5e92 Mon Sep 17 00:00:00 2001 From: Luke Manley Date: Fri, 27 Dec 2024 02:20:14 -0500 Subject: [PATCH] fix: Fix `align_frames` with single row panicking (#20466) --- crates/polars-ops/src/frame/join/dispatch_left_right.rs | 6 ++---- py-polars/tests/unit/functions/test_functions.py | 8 ++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/polars-ops/src/frame/join/dispatch_left_right.rs b/crates/polars-ops/src/frame/join/dispatch_left_right.rs index 452c51154a64..4267c8743bc6 100644 --- a/crates/polars-ops/src/frame/join/dispatch_left_right.rs +++ b/crates/polars-ops/src/frame/join/dispatch_left_right.rs @@ -170,8 +170,7 @@ fn maintain_order_idx( let join_tuples_left = df .column("a") .unwrap() - .as_series() - .unwrap() + .as_materialized_series() .idx() .unwrap() .cont_slice() @@ -180,8 +179,7 @@ fn maintain_order_idx( let join_tuples_right = df .column("b") .unwrap() - .as_series() - .unwrap() + .as_materialized_series() .idx() .unwrap() .cont_slice() diff --git a/py-polars/tests/unit/functions/test_functions.py b/py-polars/tests/unit/functions/test_functions.py index 05bd11976fd8..37fb0e8eae73 100644 --- a/py-polars/tests/unit/functions/test_functions.py +++ b/py-polars/tests/unit/functions/test_functions.py @@ -374,6 +374,14 @@ def test_align_frames_duplicate_key() -> None: ] +def test_align_frames_single_row_20445() -> None: + left = pl.DataFrame({"a": [1], "b": [2]}) + right = pl.DataFrame({"a": [1], "c": [3]}) + result = pl.align_frames(left, right, how="left", on="a") + assert_frame_equal(result[0], left) + assert_frame_equal(result[1], right) + + def test_coalesce() -> None: df = pl.DataFrame( {